prvng_core/nulib/provisioning-server.nu
Jesús Pérez bea0477b25
refactor(18 files): selective imports — drive to 94.6% elimination (ADR-025 L2/L3)
Final mega-batch of single-star conversions combined in one commit.

=== Orchestrator facades (Layer 3, expanded to explicit symbol lists) ===
  config/accessor.nu            18 symbols (bridges accessor/mod)
  config/accessor_generated.nu  18 symbols (consumer of accessor)
  utils/version.nu              35 symbols (bridges version/mod)
  dependencies/mod.nu            7 symbols from resolver.nu
  oci_registry/mod.nu           12 multi-word "oci-registry X" subcommands
  oci/commands.nu               12 symbols from oci/client.nu
                                + removed redundant `use ./client.nu *` that
                                  was duplicated below the selective import

=== Selective imports (Layer 2) ===
  platform/discovery.nu         target.nu [5 symbols]
  platform/health.nu            target.nu [2 symbols]
  platform/connection.nu        user/config [get-active-workspace]
  vm/preparer.nu                vm/detector [check-vm-capability]
  vm/backend_libvirt.nu         result.nu [7 symbols]
  extensions/tests/test_versions.nu  versions [5 symbols]
  utils/version/loader.nu       nickel_processor [ncl-eval ncl-eval-soft]

=== Dead imports dropped ===
  platform/credentials.nu       user/config
  platform/activation.nu        target
  config/cache/core.nu          cache/metadata
  config/interpolation/core.nu  helpers/environment
  utils/version/loader.nu       version/core (kept nickel_processor)

=== Also included (pre-existing edits from earlier session) ===
  utils/settings.nu             pilot selective imports — reformatted
                                (file was modified externally during session)

Validation: all 18 files match pre-existing baselines (0 errors for clean
ones; 4/18/24/45/50/50 for pre-existing transitive noise).

MILESTONE: 94.6% of star-imports eliminated (370 → 20).

Remaining 20 star-lines in 5 files are intentional:
- lib_provisioning/mod.nu      (13 stars — root facade; empties in ADR-025 Phase 4)
- integrations/mod.nu          (2 stars — re-exports already-selective children)
- cmd/environment.nu           (3 stars — contains ~7 undefined function calls;
                                needs Blocker-1 style cleanup follow-up)
- providers/loader.nu          (1 dynamic `use ($entry_point) *` — runtime dispatch)
- vm/cleanup_scheduler.nu      (1 in string template — not a real import)

Refs: ADR-025
2026-04-17 17:10:47 +01:00

206 lines
9.9 KiB
Text

#!/usr/bin/env nu
# Thin entry for server commands.
# Loads servers/create.nu directly — bypasses full dispatcher + run_module re-invocation.
# Cuts startup from ~46s to ~3-5s (single Nushell process, no exec re-spawn).
export-env {
let lib_dirs_raw = ($env.NU_LIB_DIRS? | default "")
let current_lib_dirs = if ($lib_dirs_raw | type) == "string" {
if ($lib_dirs_raw | is-empty) { [] } else { ($lib_dirs_raw | split row ":") }
} else {
$lib_dirs_raw
}
let dynamic = ($env.PROVISIONING? | default "" | path join "core" "nulib")
$env.NU_LIB_DIRS = ([
"/opt/provisioning/core/nulib"
"/usr/local/provisioning/core/nulib"
] | append $current_lib_dirs | append (if ($dynamic | is-not-empty) { [$dynamic] } else { [] }))
# Strip leading "server"/"s" token so get-provisioning-args returns the sub-command
# e.g. "server create --infra x" → "create --infra x"
let args_raw = ($env.PROVISIONING_ARGS? | default "")
$env.PROVISIONING_ARGS = ($args_raw | str replace --regex '^(server|s)\s+' '')
# Bash exports booleans as strings — normalize before any module code runs
let _coerce = {|raw| $raw == "true" or $raw == "1" }
let raw_no_titles = ($env.PROVISIONING_NO_TITLES? | default "")
if ($raw_no_titles | describe) == "string" and ($raw_no_titles | is-not-empty) {
$env.PROVISIONING_NO_TITLES = (do $_coerce $raw_no_titles)
}
let raw_no_terminal = ($env.PROVISIONING_NO_TERMINAL? | default "")
if ($raw_no_terminal | describe) == "string" and ($raw_no_terminal | is-not-empty) {
$env.PROVISIONING_NO_TERMINAL = (do $_coerce $raw_no_terminal)
}
let raw_titles_shown = ($env.PROVISIONING_TITLES_SHOWN? | default "")
if ($raw_titles_shown | describe) == "string" and ($raw_titles_shown | is-not-empty) {
$env.PROVISIONING_TITLES_SHOWN = (do $_coerce $raw_titles_shown)
}
let raw_debug = ($env.PROVISIONING_DEBUG? | default "")
if ($raw_debug | describe) == "string" and ($raw_debug | is-not-empty) {
$env.PROVISIONING_DEBUG = (do $_coerce $raw_debug)
}
}
use servers/create.nu *
use servers/delete.nu *
use servers/ssh.nu *
use servers/list.nu *
use servers/upgrade.nu *
def main [
...args: string
--infra (-i): string = ""
--settings (-s): string = ""
--outfile (-o): string = ""
--serverpos (-p): int
--check (-c)
--yes (-y)
--del-volume # (delete) also delete attached volumes
--del-fip # (delete) also delete assigned floating IPs
--run (-r)
--wait (-w)
--select: string = ""
--debug (-x)
--xm
--xc
--xr
--xld
--metadata
--notitles
--orchestrated
--orchestrator: string = ""
--out: string = ""
--helpinfo (-h)
]: nothing -> nothing {
if $debug { $env.PROVISIONING_DEBUG = true }
# CMD_ARGS from bash wrapper includes "server"/"s" as arg[0] — strip it.
let first = ($args | get 0? | default "")
let rest = if $first in ["server", "s"] { $args | skip 1 } else { $args }
let subcmd = ($rest | get 0? | default "")
let name = ($rest | get 1? | default "")
match $subcmd {
"list" | "ls" | "lis" | "l" => {
if ($infra | is-not-empty) {
main list --infra $infra --debug=$debug --out=$out
} else {
main list --debug=$debug --out=$out
}
}
"create" | "c" => {
if ($infra | is-not-empty) {
if ($name | is-not-empty) {
main create $name --infra $infra --wait=$wait --check=$check --outfile $outfile
} else {
main create --infra $infra --wait=$wait --check=$check --outfile $outfile
}
} else {
if ($name | is-not-empty) {
main create $name --wait=$wait --check=$check --outfile $outfile
} else {
main create --wait=$wait --check=$check --outfile $outfile
}
}
}
"sync" => {
if ($infra | is-not-empty) {
main sync --infra $infra
} else {
main sync
}
}
"upgrade" | "u" => {
if ($name | is-not-empty) {
main upgrade $name --infra $infra --settings $settings --check=$check --yes=$yes --debug=$debug
} else {
main upgrade --infra $infra --settings $settings --check=$check --yes=$yes --debug=$debug
}
}
"delete" | "d" | "del" => {
if ($name | is-not-empty) {
if $del_volume and $del_fip {
main delete $name --infra $infra --yes=$yes --del-volume --del-fip
} else if $del_volume {
main delete $name --infra $infra --yes=$yes --del-volume
} else if $del_fip {
main delete $name --infra $infra --yes=$yes --del-fip
} else {
main delete $name --infra $infra --yes=$yes
}
} else {
if $del_volume and $del_fip {
main delete --all --infra $infra --yes=$yes --del-volume --del-fip
} else if $del_volume {
main delete --all --infra $infra --yes=$yes --del-volume
} else if $del_fip {
main delete --all --infra $infra --yes=$yes --del-fip
} else {
main delete --all --infra $infra --yes=$yes
}
}
}
"ssh" => {
# Only forward non-default flags to avoid polluting the sub-command signature
let has_infra = ($infra | is-not-empty)
let has_settings = ($settings | is-not-empty)
let has_name = ($name | is-not-empty)
if $run {
match [$has_name, $has_infra, $has_settings, $debug] {
[true, true, true, true ] => { main ssh $name --infra $infra --settings $settings --debug --run }
[true, true, true, false] => { main ssh $name --infra $infra --settings $settings --run }
[true, true, false, true ] => { main ssh $name --infra $infra --debug --run }
[true, true, false, false] => { main ssh $name --infra $infra --run }
[true, false, true, true ] => { main ssh $name --settings $settings --debug --run }
[true, false, true, false] => { main ssh $name --settings $settings --run }
[true, false, false, true ] => { main ssh $name --debug --run }
[true, false, false, false] => { main ssh $name --run }
[false, true, true, true ] => { main ssh --infra $infra --settings $settings --debug --run }
[false, true, true, false] => { main ssh --infra $infra --settings $settings --run }
[false, true, false, true ] => { main ssh --infra $infra --debug --run }
[false, true, false, false] => { main ssh --infra $infra --run }
[false, false, true, true ] => { main ssh --settings $settings --debug --run }
[false, false, true, false] => { main ssh --settings $settings --run }
[false, false, false, true ] => { main ssh --debug --run }
_ => { main ssh --run }
}
} else {
match [$has_name, $has_infra, $has_settings, $debug] {
[true, true, true, true ] => { main ssh $name --infra $infra --settings $settings --debug }
[true, true, true, false] => { main ssh $name --infra $infra --settings $settings }
[true, true, false, true ] => { main ssh $name --infra $infra --debug }
[true, true, false, false] => { main ssh $name --infra $infra }
[true, false, true, true ] => { main ssh $name --settings $settings --debug }
[true, false, true, false] => { main ssh $name --settings $settings }
[true, false, false, true ] => { main ssh $name --debug }
[true, false, false, false] => { main ssh $name }
[false, true, true, true ] => { main ssh --infra $infra --settings $settings --debug }
[false, true, true, false] => { main ssh --infra $infra --settings $settings }
[false, true, false, true ] => { main ssh --infra $infra --debug }
[false, true, false, false] => { main ssh --infra $infra }
[false, false, true, true ] => { main ssh --settings $settings --debug }
[false, false, true, false] => { main ssh --settings $settings }
[false, false, false, true ] => { main ssh --debug }
_ => { main ssh }
}
}
}
"volume" | "vol" => {
use provisioning-volume.nu *
let vol_subcmd = ($rest | get 1? | default "list")
let vol_args = if ($rest | length) > 2 { $rest | skip 2 } else { [] }
match $vol_subcmd {
"list" | "ls" | "lis" | "l" => { main list --infra $infra --out $out }
"create" | "c" => { main create ($vol_args | get 0? | default "") --yes=$yes }
"attach" | "a" => { main attach ($vol_args | get 0? | default "") --server ($vol_args | get 1? | default "") --yes=$yes }
"detach" | "d" => { main detach ($vol_args | get 0? | default "") --yes=$yes }
"delete" | "rm" => { main delete ($vol_args | get 0? | default "") --yes=$yes }
_ => { main list --infra $infra --out $out }
}
}
_ => {
error make { msg: $"Unknown server subcommand '($subcmd)'. Use: create, delete, list, ssh, sync, volume" }
}
}
}