152 lines
5.3 KiB
Plaintext
152 lines
5.3 KiB
Plaintext
![]() |
# Enhanced create command with better validation and logging
|
|||
|
|
|||
|
export def "main create enhanced" [
|
|||
|
target?: string # server (s) | taskserv (t) | cluster (c)
|
|||
|
name?: string # Target name in settings
|
|||
|
...args # Args for create command
|
|||
|
--serverpos (-p): int # Server position in settings
|
|||
|
--check (-c) # Only check mode no servers will be created
|
|||
|
--wait (-w) # Wait servers to be created
|
|||
|
--infra (-i): string # Infra path
|
|||
|
--settings (-s): string # Settings path
|
|||
|
--outfile (-o): string # Output file
|
|||
|
--debug (-x) # Use Debug mode
|
|||
|
--dry-run # Show what would be done without executing
|
|||
|
--verbose (-v) # Verbose output
|
|||
|
]: nothing -> nothing {
|
|||
|
|
|||
|
# Set debug mode
|
|||
|
if $debug {
|
|||
|
$env.PROVISIONING_DEBUG = true
|
|||
|
print $"π Debug mode enabled"
|
|||
|
}
|
|||
|
|
|||
|
# Set output format
|
|||
|
if ($outfile | is-not-empty) {
|
|||
|
$env.PROVISIONING_OUT = $outfile
|
|||
|
$env.PROVISIONING_NO_TERMINAL = true
|
|||
|
}
|
|||
|
|
|||
|
# Validate target parameter
|
|||
|
if ($target | is-empty) {
|
|||
|
print $"π Target parameter is required"
|
|||
|
print "π‘ Valid targets: server(s), taskserv(t), cluster(cl)"
|
|||
|
print "π‘ Example: provisioning create enhanced server my-server"
|
|||
|
exit 1
|
|||
|
}
|
|||
|
|
|||
|
# Validate target value
|
|||
|
let valid_targets = ["server", "servers", "s", "taskserv", "taskservs", "task", "tasks", "t", "clusters", "cl"]
|
|||
|
let is_valid_target = ($valid_targets | where {|t| $t == $target} | length) > 0
|
|||
|
|
|||
|
if not $is_valid_target {
|
|||
|
print $"π Invalid target: ($target)"
|
|||
|
print $"π‘ Valid targets: ($valid_targets | str join ', ')"
|
|||
|
exit 1
|
|||
|
}
|
|||
|
|
|||
|
# Log operation start
|
|||
|
print $""
|
|||
|
print $"π Creating ($target)"
|
|||
|
print $"βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
|
|||
|
print $"βΉοΈ Target: ($target)"
|
|||
|
print $"βΉοΈ Name: ($name | default 'default')"
|
|||
|
|
|||
|
if $dry_run {
|
|||
|
print $"β οΈ DRY RUN MODE - No actual changes will be made"
|
|||
|
}
|
|||
|
|
|||
|
# Validate settings path if provided
|
|||
|
if ($settings | is-not-empty) {
|
|||
|
if not ($settings | path exists) {
|
|||
|
print $"π Settings file not found: ($settings)"
|
|||
|
exit 1
|
|||
|
}
|
|||
|
print $"βΉοΈ Using settings: ($settings)"
|
|||
|
}
|
|||
|
|
|||
|
# Validate infra path if provided
|
|||
|
if ($infra | is-not-empty) {
|
|||
|
if not ($infra | path exists) {
|
|||
|
print $"π Infra path not found: ($infra)"
|
|||
|
exit 1
|
|||
|
}
|
|||
|
print $"βΉοΈ Using infra: ($infra)"
|
|||
|
}
|
|||
|
|
|||
|
# Execute the appropriate creation command
|
|||
|
let use_debug = if $debug { "-x" } else { "" }
|
|||
|
|
|||
|
try {
|
|||
|
match $target {
|
|||
|
"server"| "servers" | "s" => {
|
|||
|
print $" π Creating server"
|
|||
|
if $dry_run {
|
|||
|
print $"βΉοΈ Would execute: server creation command"
|
|||
|
} else {
|
|||
|
^$"($env.PROVISIONING_NAME)" $use_debug -mod "server" ($env.PROVISIONING_ARGS | str replace $target '') --notitles
|
|||
|
}
|
|||
|
},
|
|||
|
"taskserv" | "taskservs" | "task" | "tasks" | "t" => {
|
|||
|
print $" π Creating taskserv"
|
|||
|
let ops = ($env.PROVISIONING_ARGS | split row " ")
|
|||
|
let task = ($ops | get -o 0 | default "")
|
|||
|
if $dry_run {
|
|||
|
print $"βΉοΈ Would execute: taskserv creation for task ($task)"
|
|||
|
} else {
|
|||
|
^$"($env.PROVISIONING_NAME)" $use_debug -mod "taskserv" $task ($env.PROVISIONING_ARGS | str replace $"($task) ($target)" '') --notitles
|
|||
|
}
|
|||
|
},
|
|||
|
"clusters"| "clusters" | "cl" => {
|
|||
|
print $" π Creating cluster"
|
|||
|
if $dry_run {
|
|||
|
print $"βΉοΈ Would execute: cluster creation command"
|
|||
|
} else {
|
|||
|
^$"($env.PROVISIONING_NAME)" $use_debug -mod "cluster" ($env.PROVISIONING_ARGS | str replace $target '') --notitles
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if not $dry_run {
|
|||
|
print $"β
Successfully created ($target)"
|
|||
|
} else {
|
|||
|
print $"β
Dry run completed successfully"
|
|||
|
}
|
|||
|
|
|||
|
} catch {|err|
|
|||
|
print $"π Failed to create ($target)"
|
|||
|
print $" Details: ($err.msg)"
|
|||
|
exit 1
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
# Helper function to validate server configuration
|
|||
|
export def validate-server-config [
|
|||
|
server_config: record
|
|||
|
]: bool {
|
|||
|
let required_fields = ["hostname", "ip", "provider"]
|
|||
|
let missing_fields = ($required_fields | where {|field|
|
|||
|
($server_config | get -o $field | is-empty)
|
|||
|
})
|
|||
|
|
|||
|
if ($missing_fields | length) > 0 {
|
|||
|
print $"π Missing required server configuration fields"
|
|||
|
$missing_fields | each {|field|
|
|||
|
print $" - ($field)"
|
|||
|
}
|
|||
|
return false
|
|||
|
}
|
|||
|
|
|||
|
print $"β
Server configuration is valid"
|
|||
|
true
|
|||
|
}
|
|||
|
|
|||
|
# Helper function to show creation progress
|
|||
|
export def show-creation-progress [
|
|||
|
current: int
|
|||
|
total: int
|
|||
|
operation: string
|
|||
|
] {
|
|||
|
let percent = (($current * 100) / $total)
|
|||
|
print $"π ($operation) ($percent)%"
|
|||
|
}
|