chore: Change the factories

This commit is contained in:
Mahmoud Emad
2025-02-16 11:12:59 +00:00
parent d604d739e3
commit 61a0fd2aa6
17 changed files with 1343 additions and 641 deletions

View File

@@ -1,6 +1,5 @@
module fungistor
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
@@ -14,6 +13,65 @@ __global (
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&FungiStor {
return &FungiStor{}
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut other_actions := plbook.find(filter: 'fungistor.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action fungistor.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action fungistor.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut fungistor_obj := get(name: name)!
console.print_debug('action object:\n${fungistor_obj}')
if other_action.name == 'start' {
console.print_debug('install action fungistor.${other_action.name}')
fungistor_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action fungistor.${other_action.name}')
fungistor_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action fungistor.${other_action.name}')
fungistor_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,8 +106,8 @@ pub fn (mut self FungiStor) start() ! {
console.print_header('fungistor start')
if !installed_()! {
install_()!
if !installed()! {
install()!
}
configure()!
@@ -77,9 +135,9 @@ pub fn (mut self FungiStor) start() ! {
return error('fungistor did not install properly.')
}
pub fn (mut self FungiStor) install_start(model InstallArgs) ! {
pub fn (mut self FungiStor) install_start(args InstallArgs) ! {
switch(self.name)
self.install(model)!
self.install(args)!
self.start()!
}
@@ -119,19 +177,32 @@ pub mut:
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
pub fn (mut self FungiStor) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn destroy() ! {
destroy_()!
pub fn (mut self FungiStor) build() ! {
switch(self.name)
build()!
}
pub fn build() ! {
build_()!
pub fn (mut self FungiStor) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for fungistor
pub fn switch(name string) {
fungistor_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -1,6 +1,5 @@
module grafana
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
@@ -14,6 +13,65 @@ __global (
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Grafana {
return &Grafana{}
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut other_actions := plbook.find(filter: 'grafana.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action grafana.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action grafana.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut grafana_obj := get(name: name)!
console.print_debug('action object:\n${grafana_obj}')
if other_action.name == 'start' {
console.print_debug('install action grafana.${other_action.name}')
grafana_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action grafana.${other_action.name}')
grafana_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action grafana.${other_action.name}')
grafana_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,8 +106,8 @@ pub fn (mut self Grafana) start() ! {
console.print_header('grafana start')
if !installed_()! {
install_()!
if !installed()! {
install()!
}
configure()!
@@ -77,9 +135,9 @@ pub fn (mut self Grafana) start() ! {
return error('grafana did not install properly.')
}
pub fn (mut self Grafana) install_start(model InstallArgs) ! {
pub fn (mut self Grafana) install_start(args InstallArgs) ! {
switch(self.name)
self.install(model)!
self.install(args)!
self.start()!
}
@@ -119,19 +177,32 @@ pub mut:
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
pub fn (mut self Grafana) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn destroy() ! {
destroy_()!
pub fn (mut self Grafana) build() ! {
switch(self.name)
build()!
}
pub fn build() ! {
build_()!
pub fn (mut self Grafana) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for grafana
pub fn switch(name string) {
grafana_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -1,6 +1,5 @@
module prometheus
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
@@ -14,6 +13,65 @@ __global (
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Prometheus {
return &Prometheus{}
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut other_actions := plbook.find(filter: 'prometheus.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action prometheus.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action prometheus.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut prometheus_obj := get(name: name)!
console.print_debug('action object:\n${prometheus_obj}')
if other_action.name == 'start' {
console.print_debug('install action prometheus.${other_action.name}')
prometheus_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action prometheus.${other_action.name}')
prometheus_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action prometheus.${other_action.name}')
prometheus_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,8 +106,8 @@ pub fn (mut self Prometheus) start() ! {
console.print_header('prometheus start')
if !installed_()! {
install_()!
if !installed()! {
install()!
}
configure()!
@@ -77,9 +135,9 @@ pub fn (mut self Prometheus) start() ! {
return error('prometheus did not install properly.')
}
pub fn (mut self Prometheus) install_start(model InstallArgs) ! {
pub fn (mut self Prometheus) install_start(args InstallArgs) ! {
switch(self.name)
self.install(model)!
self.install(args)!
self.start()!
}
@@ -119,19 +177,32 @@ pub mut:
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
pub fn (mut self Prometheus) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn destroy() ! {
destroy_()!
pub fn (mut self Prometheus) build() ! {
switch(self.name)
build()!
}
pub fn build() ! {
build_()!
pub fn (mut self Prometheus) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for prometheus
pub fn switch(name string) {
prometheus_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -1,6 +1,5 @@
module restic
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
@@ -14,6 +13,65 @@ __global (
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&Restic {
return &Restic{}
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut other_actions := plbook.find(filter: 'restic.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action restic.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action restic.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut restic_obj := get(name: name)!
console.print_debug('action object:\n${restic_obj}')
if other_action.name == 'start' {
console.print_debug('install action restic.${other_action.name}')
restic_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action restic.${other_action.name}')
restic_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action restic.${other_action.name}')
restic_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,8 +106,8 @@ pub fn (mut self Restic) start() ! {
console.print_header('restic start')
if !installed_()! {
install_()!
if !installed()! {
install()!
}
configure()!
@@ -77,9 +135,9 @@ pub fn (mut self Restic) start() ! {
return error('restic did not install properly.')
}
pub fn (mut self Restic) install_start(model InstallArgs) ! {
pub fn (mut self Restic) install_start(args InstallArgs) ! {
switch(self.name)
self.install(model)!
self.install(args)!
self.start()!
}
@@ -119,19 +177,32 @@ pub mut:
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
pub fn (mut self Restic) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn destroy() ! {
destroy_()!
pub fn (mut self Restic) build() ! {
switch(self.name)
build()!
}
pub fn build() ! {
build_()!
pub fn (mut self Restic) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for restic
pub fn switch(name string) {
restic_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}

View File

@@ -1,6 +1,5 @@
module s3
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.sysadmin.startupmanager
@@ -14,6 +13,65 @@ __global (
/////////FACTORY
@[params]
pub struct ArgsGet {
pub mut:
name string
}
pub fn get(args_ ArgsGet) !&S3Installer {
return &S3Installer{}
}
@[params]
pub struct PlayArgs {
pub mut:
heroscript string // if filled in then plbook will be made out of it
plbook ?playbook.PlayBook
reset bool
}
pub fn play(args_ PlayArgs) ! {
mut args := args_
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut other_actions := plbook.find(filter: 's3.')!
for other_action in other_actions {
if other_action.name in ['destroy', 'install', 'build'] {
mut p := other_action.params
reset := p.get_default_false('reset')
if other_action.name == 'destroy' || reset {
console.print_debug('install action s3.destroy')
destroy()!
}
if other_action.name == 'install' {
console.print_debug('install action s3.install')
install()!
}
}
if other_action.name in ['start', 'stop', 'restart'] {
mut p := other_action.params
name := p.get('name')!
mut s3_obj := get(name: name)!
console.print_debug('action object:\n${s3_obj}')
if other_action.name == 'start' {
console.print_debug('install action s3.${other_action.name}')
s3_obj.start()!
}
if other_action.name == 'stop' {
console.print_debug('install action s3.${other_action.name}')
s3_obj.stop()!
}
if other_action.name == 'restart' {
console.print_debug('install action s3.${other_action.name}')
s3_obj.restart()!
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////# LIVE CYCLE MANAGEMENT FOR INSTALLERS ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -48,8 +106,8 @@ pub fn (mut self S3Installer) start() ! {
console.print_header('s3 start')
if !installed_()! {
install_()!
if !installed()! {
install()!
}
configure()!
@@ -77,9 +135,9 @@ pub fn (mut self S3Installer) start() ! {
return error('s3 did not install properly.')
}
pub fn (mut self S3Installer) install_start(model InstallArgs) ! {
pub fn (mut self S3Installer) install_start(args InstallArgs) ! {
switch(self.name)
self.install(model)!
self.install(args)!
self.start()!
}
@@ -119,19 +177,32 @@ pub mut:
reset bool
}
pub fn install(args InstallArgs) ! {
if args.reset {
destroy()!
}
if !(installed_()!) {
install_()!
pub fn (mut self S3Installer) install(args InstallArgs) ! {
switch(self.name)
if args.reset || (!installed()!) {
install()!
}
}
pub fn destroy() ! {
destroy_()!
pub fn (mut self S3Installer) build() ! {
switch(self.name)
build()!
}
pub fn build() ! {
build_()!
pub fn (mut self S3Installer) destroy() ! {
switch(self.name)
self.stop() or {}
destroy()!
}
// switch instance to be used for s3
pub fn switch(name string) {
s3_default = name
}
// helpers
@[params]
pub struct DefaultConfigArgs {
instance string = 'default'
}