119 lines
3.7 KiB
Plaintext
119 lines
3.7 KiB
Plaintext
# Infrastructure Command Handlers
|
|
# Handles: server, taskserv, cluster, infra commands
|
|
|
|
use ../flags.nu *
|
|
use ../../lib_provisioning *
|
|
|
|
# Helper to run module commands
|
|
def run_module [
|
|
args: string
|
|
module: string
|
|
option?: string
|
|
--exec
|
|
] {
|
|
let use_debug = if ($env.PROVISIONING_DEBUG? | default false) { "-x" } else { "" }
|
|
|
|
# Always add --notitles when dispatching to submodules to prevent double title display
|
|
if $exec {
|
|
exec $"($env.PROVISIONING_NAME)" $use_debug -mod $module ($option | default "") $args --notitles
|
|
} else {
|
|
^$"($env.PROVISIONING_NAME)" $use_debug -mod $module ($option | default "") $args --notitles
|
|
}
|
|
}
|
|
|
|
# Main infrastructure command dispatcher
|
|
export def handle_infrastructure_command [
|
|
command: string
|
|
ops: string
|
|
flags: record
|
|
] {
|
|
set_debug_env $flags
|
|
|
|
match $command {
|
|
"server" => { handle_server $ops $flags }
|
|
"taskserv" | "task" => { handle_taskserv $ops $flags }
|
|
"cluster" => { handle_cluster $ops $flags }
|
|
"infra" | "infras" => { handle_infra $ops $flags }
|
|
_ => {
|
|
print $"❌ Unknown infrastructure command: ($command)"
|
|
print ""
|
|
print "Available infrastructure commands:"
|
|
print " server - Server management (create, delete, list, ssh, price)"
|
|
print " taskserv - Task service management (create, delete, list, generate)"
|
|
print " cluster - Cluster operations (create, delete, list)"
|
|
print " infra - Infrastructure management (list, validate, generate)"
|
|
print ""
|
|
print "Use 'provisioning help infrastructure' for more details"
|
|
exit 1
|
|
}
|
|
}
|
|
}
|
|
|
|
# Server command handler
|
|
def handle_server [ops: string, flags: record] {
|
|
let args = build_module_args $flags $ops
|
|
run_module $args "server" --exec
|
|
}
|
|
|
|
# Task service command handler
|
|
def handle_taskserv [ops: string, flags: record] {
|
|
let args = build_module_args $flags $ops
|
|
run_module $args "taskserv" --exec
|
|
}
|
|
|
|
# Cluster command handler
|
|
def handle_cluster [ops: string, flags: record] {
|
|
let args = build_module_args $flags $ops
|
|
run_module $args "cluster" --exec
|
|
}
|
|
|
|
# Infrastructure command handler
|
|
def handle_infra [ops: string, flags: record] {
|
|
# Handle infra-specific argument building
|
|
let infra_arg = if ($flags.infra | is-not-empty) {
|
|
$"-i ($flags.infra)"
|
|
} else if ($flags.infras | is-not-empty) {
|
|
$"--infras ($flags.infras)"
|
|
} else {
|
|
$"-i (get_infra | path basename)"
|
|
}
|
|
|
|
let use_yes = if $flags.auto_confirm { "--yes" } else { "" }
|
|
let use_check = if $flags.check_mode { "--check" } else { "" }
|
|
let use_onsel = if ($flags.onsel | is-not-empty) {
|
|
$"--onsel ($flags.onsel)"
|
|
} else { "" }
|
|
|
|
let args = $"($ops) ($infra_arg) ($use_check) ($use_onsel) ($use_yes)" | str trim
|
|
run_module $args "infra"
|
|
}
|
|
|
|
# Price/cost command handler
|
|
export def handle_price_command [ops: string, flags: record] {
|
|
let use_check = if $flags.check_mode { "--check " } else { "" }
|
|
let str_infra = if ($flags.infra | is-not-empty) {
|
|
$"--infra ($flags.infra) "
|
|
} else { "" }
|
|
let str_out = if ($flags.outfile | is-not-empty) {
|
|
$"--outfile ($flags.outfile) "
|
|
} else { "" }
|
|
|
|
run_module $"($ops) ($str_infra) ($use_check) ($str_out)" "server" "price" --exec
|
|
}
|
|
|
|
# Create-server-task combined command handler
|
|
export def handle_create_server_task [ops: string, flags: record] {
|
|
# Create servers first
|
|
let server_args = build_module_args $flags $ops
|
|
run_module $server_args "server" "create"
|
|
|
|
# Check if server creation succeeded
|
|
if $env.LAST_EXIT_CODE != 0 {
|
|
_print $"🛑 Errors found in (_ansi yellow_bold)create-server(_ansi reset)"
|
|
exit 1
|
|
}
|
|
|
|
# Create taskservs
|
|
let taskserv_args = build_module_args $flags $"- ($ops)"
|
|
run_module $taskserv_args "taskserv" "create"
|
|
} |