refactor: merge action handling blocks in play() functions
Merge the two separate if blocks for handling actions into a single block
since they both use the same logic for getting the name parameter with
get_default('name', 'default').
Changes:
- Combine destroy/install/build and start/stop/restart/lifecycle blocks
- All actions now use consistent name parameter handling
- Reduces code duplication in play() functions
Updated files:
- All 5 horus installer factory files
- Generator template objname_factory_.vtemplate
This commit is contained in:
@@ -169,7 +169,11 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
@if args.cat == .installer
|
||||
mut other_actions := plbook.find(filter: '${args.name}.')!
|
||||
for mut other_action in other_actions {
|
||||
@if args.startupmanager
|
||||
if other_action.name in ["destroy","install","build","start","stop","restart","start_pre","start_post","stop_pre","stop_post"]{
|
||||
@else
|
||||
if other_action.name in ["destroy","install","build"]{
|
||||
@end
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset:=p.get_default_false("reset")
|
||||
@@ -188,13 +192,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug("install action ${args.name}.build")
|
||||
${args.name}_obj.build()!
|
||||
}
|
||||
}
|
||||
@if args.startupmanager
|
||||
if other_action.name in ["start","stop","restart","start_pre","start_post","stop_pre","stop_post"]{
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut ${args.name}_obj:=get(name:name)!
|
||||
console.print_debug("action object:\n??{${args.name}_obj}")
|
||||
if other_action.name == "start"{
|
||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||
${args.name}_obj.start()!
|
||||
@@ -223,8 +221,8 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug("install action ${args.name}.??{other_action.name}")
|
||||
${args.name}_obj.stop_post()!
|
||||
}
|
||||
}
|
||||
@end
|
||||
}
|
||||
other_action.done = true
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -154,7 +154,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'coordinator.')!
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
@@ -173,12 +173,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action coordinator.build')
|
||||
coordinator_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut coordinator_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${coordinator_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action coordinator.${other_action.name}')
|
||||
coordinator_obj.start()!
|
||||
|
||||
@@ -142,7 +142,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'herorunner.')!
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
@@ -161,12 +161,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action herorunner.build')
|
||||
herorunner_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut herorunner_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${herorunner_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action herorunner.${other_action.name}')
|
||||
herorunner_obj.start()!
|
||||
|
||||
@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'osirisrunner.')!
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action osirisrunner.build')
|
||||
osirisrunner_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut osirisrunner_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${osirisrunner_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action osirisrunner.${other_action.name}')
|
||||
osirisrunner_obj.start()!
|
||||
|
||||
@@ -144,7 +144,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'salrunner.')!
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
@@ -163,12 +163,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action salrunner.build')
|
||||
salrunner_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut salrunner_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${salrunner_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action salrunner.${other_action.name}')
|
||||
salrunner_obj.start()!
|
||||
|
||||
@@ -148,7 +148,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
}
|
||||
mut other_actions := plbook.find(filter: 'supervisor.')!
|
||||
for mut other_action in other_actions {
|
||||
if other_action.name in ['destroy', 'install', 'build'] {
|
||||
if other_action.name in ['destroy', 'install', 'build', 'start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get_default('name', 'default')!
|
||||
reset := p.get_default_false('reset')
|
||||
@@ -167,12 +167,6 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
console.print_debug('install action supervisor.build')
|
||||
supervisor_obj.build()!
|
||||
}
|
||||
}
|
||||
if other_action.name in ['start', 'stop', 'restart', 'start_pre', 'start_post', 'stop_pre', 'stop_post'] {
|
||||
mut p := other_action.params
|
||||
name := p.get('name')!
|
||||
mut supervisor_obj := get(name: name)!
|
||||
console.print_debug('action object:\n${supervisor_obj}')
|
||||
if other_action.name == 'start' {
|
||||
console.print_debug('install action supervisor.${other_action.name}')
|
||||
supervisor_obj.start()!
|
||||
@@ -319,7 +313,6 @@ pub fn (mut self Supervisor) running() !bool {
|
||||
return self.running_check()!
|
||||
}
|
||||
|
||||
|
||||
// switch instance to be used for supervisor
|
||||
pub fn switch(name string) {
|
||||
supervisor_default = name
|
||||
|
||||
Reference in New Issue
Block a user