...
This commit is contained in:
@@ -17,19 +17,18 @@ pub mut:
|
||||
whitelist []int // comma separated list of servers we whitelist to work on
|
||||
user string
|
||||
password string
|
||||
sshkey string
|
||||
nodes []HetznerNode
|
||||
sshkey string
|
||||
nodes []HetznerNode
|
||||
}
|
||||
|
||||
@[heap]
|
||||
pub struct HetznerNode {
|
||||
pub mut:
|
||||
id string
|
||||
id string
|
||||
name string = 'default'
|
||||
description string
|
||||
}
|
||||
|
||||
|
||||
pub fn (mut h HetznerManager) connection() !&httpconnection.HTTPConnection {
|
||||
mut c2 := httpconnection.new(
|
||||
name: 'hetzner_${h.name}'
|
||||
|
||||
@@ -6,8 +6,6 @@ import freeflowuniverse.herolib.core.playbook { PlayBook }
|
||||
// play processes playbook actions for the hetznermanager module.
|
||||
// It allows configuring and managing Hetzner servers through heroscript.
|
||||
pub fn play2(mut plbook PlayBook) ! {
|
||||
|
||||
|
||||
// Handle rescue actions
|
||||
for mut action in plbook.find(filter: 'hetznermanager.server_rescue')! {
|
||||
mut p := action.params
|
||||
@@ -25,12 +23,12 @@ pub fn play2(mut plbook PlayBook) ! {
|
||||
}
|
||||
|
||||
cl.server_rescue(
|
||||
id: id,
|
||||
name: server_name,
|
||||
wait: wait,
|
||||
hero_install: hero_install,
|
||||
reset: reset,
|
||||
retry: retry
|
||||
id: id
|
||||
name: server_name
|
||||
wait: wait
|
||||
hero_install: hero_install
|
||||
reset: reset
|
||||
retry: retry
|
||||
)!
|
||||
|
||||
action.done = true
|
||||
@@ -53,12 +51,12 @@ pub fn play2(mut plbook PlayBook) ! {
|
||||
}
|
||||
|
||||
cl.ubuntu_install(
|
||||
id: id,
|
||||
name: server_name,
|
||||
wait: wait,
|
||||
hero_install: hero_install,
|
||||
hero_install_compile: hero_install_compile,
|
||||
raid: raid
|
||||
id: id
|
||||
name: server_name
|
||||
wait: wait
|
||||
hero_install: hero_install
|
||||
hero_install_compile: hero_install_compile
|
||||
raid: raid
|
||||
)!
|
||||
|
||||
action.done = true
|
||||
@@ -78,10 +76,10 @@ pub fn play2(mut plbook PlayBook) ! {
|
||||
}
|
||||
|
||||
cl.server_reset(
|
||||
id: id,
|
||||
name: server_name,
|
||||
wait: wait,
|
||||
msg: msg
|
||||
id: id
|
||||
name: server_name
|
||||
wait: wait
|
||||
msg: msg
|
||||
)!
|
||||
|
||||
action.done = true
|
||||
@@ -107,8 +105,8 @@ pub fn play2(mut plbook PlayBook) ! {
|
||||
|
||||
key_name := p.get('key_name')!
|
||||
|
||||
cl.key_delete( key_name)!
|
||||
cl.key_delete(key_name)!
|
||||
|
||||
action.done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
module hetznermanager
|
||||
|
||||
|
||||
|
||||
pub fn (mut h HetznerManager) check_whitelist(args_ ServerRescueArgs)! {
|
||||
|
||||
pub fn (mut h HetznerManager) check_whitelist(args_ ServerRescueArgs) ! {
|
||||
if h.whitelist.len == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
mut serverinfo := h.server_info_get(id: args_.id, name: args_.name)!
|
||||
|
||||
if ! h.whitelist.contains(serverinfo.server_number) {
|
||||
if !h.whitelist.contains(serverinfo.server_number) {
|
||||
return error('Server ${serverinfo}\nis not whitelisted')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,9 +69,8 @@ fn (mut h HetznerManager) server_rescue_internal(args_ ServerRescueArgs) !Server
|
||||
if serverinfo.rescue == false || args.reset {
|
||||
console.print_header('server ${serverinfo.server_name} goes into rescue mode')
|
||||
|
||||
|
||||
mykey:=h.key_get(h.sshkey)!
|
||||
mykeyfp:=mykey.fingerprint
|
||||
mykey := h.key_get(h.sshkey)!
|
||||
mykeyfp := mykey.fingerprint
|
||||
|
||||
// println("Using SSH key fingerprint: ${mykey} ${mykeyfp}")
|
||||
|
||||
@@ -117,7 +116,6 @@ fn (mut h HetznerManager) server_rescue_internal(args_ ServerRescueArgs) !Server
|
||||
}
|
||||
|
||||
pub fn (mut h HetznerManager) server_rescue_node(args ServerRescueArgs) !&builder.Node {
|
||||
|
||||
mut serverinfo := h.server_rescue(args)!
|
||||
|
||||
mut b := builder.new()!
|
||||
@@ -137,11 +135,11 @@ pub mut:
|
||||
}
|
||||
|
||||
pub fn (mut h HetznerManager) ubuntu_install(args ServerInstallArgs) !&builder.Node {
|
||||
h.check_whitelist(name:args.name,id:args.id)!
|
||||
h.check_whitelist(name: args.name, id: args.id)!
|
||||
mut serverinfo := h.server_rescue(
|
||||
id: args.id
|
||||
name: args.name
|
||||
wait: true
|
||||
id: args.id
|
||||
name: args.name
|
||||
wait: true
|
||||
)!
|
||||
|
||||
mut b := builder.new()!
|
||||
@@ -153,7 +151,7 @@ pub fn (mut h HetznerManager) ubuntu_install(args ServerInstallArgs) !&builder.N
|
||||
|
||||
mut rstr := '-r no '
|
||||
if args.raid {
|
||||
panic("should not use RAID for now")
|
||||
panic('should not use RAID for now')
|
||||
rstr = '-r yes -l 1 '
|
||||
}
|
||||
|
||||
@@ -189,7 +187,7 @@ pub fn (mut h HetznerManager) ubuntu_install(args ServerInstallArgs) !&builder.N
|
||||
|
||||
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)!
|
||||
|
||||
console.print_debug('server ${serverinfo.server_name} is reacheable over ssh, lets now install hero if asked for.')
|
||||
|
||||
@@ -77,7 +77,7 @@ pub fn (mut h HetznerManager) server_info_get(args_ ServerGetArgs) !ServerInfoDe
|
||||
continue
|
||||
}
|
||||
server_name := texttools.name_fix(item.server_name)
|
||||
//if id specified then we always use that one
|
||||
// if id specified then we always use that one
|
||||
if args.id == 0 && args.name.len > 0 && server_name != args.name {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user