...
This commit is contained in:
@@ -22,14 +22,16 @@ playcmds.run(
|
|||||||
!!hetznermanager.configure
|
!!hetznermanager.configure
|
||||||
name:"main"
|
name:"main"
|
||||||
user:"${user}"
|
user:"${user}"
|
||||||
whitelist:"2111181, 2392178, 2545053"
|
whitelist:"2111181, 2392178, 2545053, 2542166, 2550508, 2550378,2550253"
|
||||||
password:"${passwd}"
|
password:"${passwd}"
|
||||||
|
sshkey:"kristof"
|
||||||
'
|
'
|
||||||
)!
|
)!
|
||||||
|
|
||||||
console.print_header('Hetzner Test.')
|
console.print_header('Hetzner Test.')
|
||||||
|
|
||||||
mut cl := hetznermanager.get(name: 'main')!
|
mut cl := hetznermanager.get(name: 'main')!
|
||||||
|
// println(cl)
|
||||||
|
|
||||||
// for i in 0 .. 5 {
|
// for i in 0 .. 5 {
|
||||||
// println('test cache, first time slow then fast')
|
// println('test cache, first time slow then fast')
|
||||||
@@ -58,5 +60,9 @@ mut cl := hetznermanager.get(name: 'main')!
|
|||||||
|
|
||||||
// n.shell("")!
|
// n.shell("")!
|
||||||
|
|
||||||
// cl.ubuntu_install(name: 'kristof2', wait: true, hero_install: true, sshkey_name: 'kristof')!
|
// cl.ubuntu_install(name: 'kristof2', wait: true, hero_install: true)!
|
||||||
cl.ubuntu_install(name: 'kristof20', wait: true, hero_install: true, sshkey_name: 'kristof')!
|
// cl.ubuntu_install(name: 'kristof20', wait: true, hero_install: true)!
|
||||||
|
// cl.ubuntu_install(id:2550378, name: 'kristof21', wait: true, hero_install: true)!
|
||||||
|
// cl.ubuntu_install(id:2550508, name: 'kristof22', wait: true, hero_install: true)!
|
||||||
|
cl.ubuntu_install(id:2550253, name:'kristof23', wait: true, hero_install: true)!
|
||||||
|
|
||||||
|
|||||||
@@ -54,24 +54,30 @@ fn decode_struct[T](_ T, data string) !T {
|
|||||||
should_skip = true
|
should_skip = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
if attr.contains('skipdecode') {
|
||||||
|
should_skip = true
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !should_skip {
|
if !should_skip {
|
||||||
$if field.is_struct {
|
$if field.is_struct {
|
||||||
$if field.typ !is time.Time {
|
// $if field.typ !is time.Time {
|
||||||
if !field.name[0].is_capital() {
|
// if !field.name[0].is_capital() {
|
||||||
// skip embedded ones
|
// // skip embedded ones
|
||||||
mut data_fmt := data.replace(action_str, '')
|
// mut data_fmt := data.replace(action_str, '')
|
||||||
data_fmt = data.replace('define.${obj_name}', 'define')
|
// data_fmt = data.replace('define.${obj_name}', 'define')
|
||||||
typ.$(field.name) = decode_struct(typ.$(field.name), data_fmt)!
|
// typ.$(field.name) = decode_struct(typ.$(field.name), data_fmt)!
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} $else $if field.is_array {
|
} $else $if field.is_array {
|
||||||
if is_struct_array(typ.$(field.name))! {
|
// arr := decode_array(typ.$(field.name), data_fmt)!
|
||||||
mut data_fmt := data.replace(action_str, '')
|
// typ.$(field.name) = arr
|
||||||
data_fmt = data.replace('define.${obj_name}', 'define')
|
// if is_struct_array(typ.$(field.name))! {
|
||||||
arr := decode_array(typ.$(field.name), data_fmt)!
|
// mut data_fmt := data.replace(action_str, '')
|
||||||
typ.$(field.name) = arr
|
// data_fmt = data.replace('define.${obj_name}', 'define')
|
||||||
}
|
// arr := decode_array(typ.$(field.name), data_fmt)!
|
||||||
|
// typ.$(field.name) = arr
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +99,9 @@ pub fn decode_array[T](_ []T, data string) ![]T {
|
|||||||
// for i in 0 .. val.len {
|
// for i in 0 .. val.len {
|
||||||
value := T{}
|
value := T{}
|
||||||
$if T is $struct {
|
$if T is $struct {
|
||||||
arr << decode_struct(value, data)!
|
//arr << decode_struct(value, data)!
|
||||||
|
}$else{
|
||||||
|
arr << decode[T](data)!
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
return arr
|
return arr
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ module hetznermanager
|
|||||||
|
|
||||||
import freeflowuniverse.herolib.core.httpconnection
|
import freeflowuniverse.herolib.core.httpconnection
|
||||||
import freeflowuniverse.herolib.data.encoderhero
|
import freeflowuniverse.herolib.data.encoderhero
|
||||||
|
import freeflowuniverse.herolib.core.playbook
|
||||||
|
|
||||||
pub const version = '0.0.0'
|
pub const version = '0.0.0'
|
||||||
const singleton = false
|
const singleton = false
|
||||||
@@ -16,8 +17,19 @@ pub mut:
|
|||||||
whitelist []int // comma separated list of servers we whitelist to work on
|
whitelist []int // comma separated list of servers we whitelist to work on
|
||||||
user string
|
user string
|
||||||
password string
|
password string
|
||||||
|
sshkey string
|
||||||
|
nodes []HetznerNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@[heap]
|
||||||
|
pub struct HetznerNode {
|
||||||
|
pub mut:
|
||||||
|
id string
|
||||||
|
name string = 'default'
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn (mut h HetznerManager) connection() !&httpconnection.HTTPConnection {
|
pub fn (mut h HetznerManager) connection() !&httpconnection.HTTPConnection {
|
||||||
mut c2 := httpconnection.new(
|
mut c2 := httpconnection.new(
|
||||||
name: 'hetzner_${h.name}'
|
name: 'hetzner_${h.name}'
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ pub mut:
|
|||||||
name string
|
name string
|
||||||
wait bool = true
|
wait bool = true
|
||||||
hero_install bool
|
hero_install bool
|
||||||
sshkey_name string @[required]
|
|
||||||
reset bool // ask to do reset/rescue even if its already in that state
|
reset bool // ask to do reset/rescue even if its already in that state
|
||||||
retry int = 3
|
retry int = 3
|
||||||
}
|
}
|
||||||
@@ -70,19 +69,12 @@ fn (mut h HetznerManager) server_rescue_internal(args_ ServerRescueArgs) !Server
|
|||||||
if serverinfo.rescue == false || args.reset {
|
if serverinfo.rescue == false || args.reset {
|
||||||
console.print_header('server ${serverinfo.server_name} goes into rescue mode')
|
console.print_header('server ${serverinfo.server_name} goes into rescue mode')
|
||||||
|
|
||||||
mut keyfps := []string{}
|
|
||||||
if args.sshkey_name != '' {
|
|
||||||
keyfps << h.key_get(args.sshkey_name)!.fingerprint
|
|
||||||
} else {
|
|
||||||
keyfps = h.keys_get()!.map(it.fingerprint)
|
|
||||||
}
|
|
||||||
|
|
||||||
mut conn := h.connection()!
|
mut conn := h.connection()!
|
||||||
rescue := conn.post_json_generic[RescueInfo](
|
rescue := conn.post_json_generic[RescueInfo](
|
||||||
prefix: 'boot/${serverinfo.server_number}/rescue'
|
prefix: 'boot/${serverinfo.server_number}/rescue'
|
||||||
params: {
|
params: {
|
||||||
'os': 'linux'
|
'os': 'linux'
|
||||||
'authorized_key': keyfps[0]
|
'authorized_key': h.sshkey
|
||||||
}
|
}
|
||||||
dict_key: 'rescue'
|
dict_key: 'rescue'
|
||||||
dataformat: .urlencoded
|
dataformat: .urlencoded
|
||||||
@@ -135,17 +127,15 @@ pub mut:
|
|||||||
wait bool = true
|
wait bool = true
|
||||||
hero_install bool
|
hero_install bool
|
||||||
hero_install_compile bool
|
hero_install_compile bool
|
||||||
sshkey_name string @[required]
|
|
||||||
raid bool
|
raid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut h HetznerManager) ubuntu_install(args ServerInstallArgs) !&builder.Node {
|
pub fn (mut h HetznerManager) ubuntu_install(args ServerInstallArgs) !&builder.Node {
|
||||||
h.check_whitelist(name:args.name,id:args.id,sshkey_name:args.sshkey_name)!
|
h.check_whitelist(name:args.name,id:args.id)!
|
||||||
mut serverinfo := h.server_rescue(
|
mut serverinfo := h.server_rescue(
|
||||||
id: args.id
|
id: args.id
|
||||||
name: args.name
|
name: args.name
|
||||||
wait: true
|
wait: true
|
||||||
sshkey_name: args.sshkey_name
|
|
||||||
)!
|
)!
|
||||||
|
|
||||||
mut b := builder.new()!
|
mut b := builder.new()!
|
||||||
@@ -191,9 +181,13 @@ pub fn (mut h HetznerManager) ubuntu_install(args ServerInstallArgs) !&builder.N
|
|||||||
timeout_up: 60 * 5
|
timeout_up: 60 * 5
|
||||||
)!
|
)!
|
||||||
|
|
||||||
|
console.print_debug('server ${serverinfo.server_name} is reacheable over ping, lets now try ssh.')
|
||||||
|
|
||||||
//wait 20 sec to make sure ssh is there
|
//wait 20 sec to make sure ssh is there
|
||||||
osal.ssh_wait(address: serverinfo.server_ip, timeout: 20)!
|
osal.ssh_wait(address: serverinfo.server_ip, timeout: 20)!
|
||||||
|
|
||||||
|
console.print_debug('server ${serverinfo.server_name} is reacheable over ssh, lets now install hero if asked for.')
|
||||||
|
|
||||||
if args.hero_install {
|
if args.hero_install {
|
||||||
n.exec_silent('apt update && apt install -y mc redis')!
|
n.exec_silent('apt update && apt install -y mc redis')!
|
||||||
n.hero_install(compile: args.hero_install_compile)!
|
n.hero_install(compile: args.hero_install_compile)!
|
||||||
|
|||||||
@@ -72,11 +72,13 @@ pub fn (mut h HetznerManager) server_info_get(args_ ServerGetArgs) !ServerInfoDe
|
|||||||
mut res := []ServerInfo{}
|
mut res := []ServerInfo{}
|
||||||
|
|
||||||
for item in l {
|
for item in l {
|
||||||
|
// console.print_debug("Checking server: ${item.server_name} ${item.server_number} against args: '${args.name}:${args.id}'")
|
||||||
if args.id > 0 && item.server_number != args.id {
|
if args.id > 0 && item.server_number != args.id {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
server_name := texttools.name_fix(item.server_name)
|
server_name := texttools.name_fix(item.server_name)
|
||||||
if args.name.len > 0 && server_name != args.name {
|
//if id specified then we always use that one
|
||||||
|
if args.id == 0 && args.name.len > 0 && server_name != args.name {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res << item
|
res << item
|
||||||
|
|||||||
Reference in New Issue
Block a user