rewrite builder pattern + clean script as template
This commit is contained in:
82
packages/system/virt/tests/rhai/vm_clean_launch.rhai
Normal file
82
packages/system/virt/tests/rhai/vm_clean_launch.rhai
Normal file
@@ -0,0 +1,82 @@
|
||||
// Clean VM Launch Script
|
||||
// Creates a VM using builder pattern with concise output
|
||||
|
||||
let vm_id = "vm-clean-test";
|
||||
|
||||
// Phase 1: Host check
|
||||
print("Checking system requirements...");
|
||||
let hc = host_check();
|
||||
if !(hc.ok == true) {
|
||||
print("❌ System check failed - missing dependencies:");
|
||||
if hc.critical != () && hc.critical.len() > 0 {
|
||||
print("Critical:");
|
||||
for dep in hc.critical {
|
||||
print(" - " + dep);
|
||||
}
|
||||
}
|
||||
if hc.optional != () && hc.optional.len() > 0 {
|
||||
print("Optional:");
|
||||
for dep in hc.optional {
|
||||
print(" - " + dep);
|
||||
}
|
||||
}
|
||||
throw "Host check failed: missing dependencies";
|
||||
}
|
||||
print("✅ System requirements met");
|
||||
|
||||
// Phase 2: Create VM using fluent builder pattern
|
||||
print("Preparing Ubuntu image and configuring VM...");
|
||||
let vm_id_actual = "";
|
||||
try {
|
||||
vm_id_actual = cloudhv_builder(vm_id)
|
||||
.disk_from_flavor("ubuntu")
|
||||
.network_default_nat()
|
||||
.memory_mb(4096)
|
||||
.vcpus(2)
|
||||
.launch();
|
||||
} catch (e) {
|
||||
throw "VM launch failed: " + e.to_string();
|
||||
}
|
||||
|
||||
// Phase 3: Wait for VM to boot and get network configuration
|
||||
print("✅ VM launched successfully");
|
||||
print("⏳ Waiting 10 seconds for VM to boot and configure network...");
|
||||
sleep(10);
|
||||
|
||||
// Phase 4: Discover VM IP addresses
|
||||
print("🔍 Discovering VM network addresses...");
|
||||
let mac_addr = "a2:26:1e:ac:96:3a"; // This should be derived from vm_id_actual
|
||||
let ipv4 = cloudhv_discover_ipv4_from_leases("/var/lib/misc/dnsmasq-hero-br-hero.leases", mac_addr, 30);
|
||||
let ipv6 = cloudhv_discover_ipv6_on_bridge("br-hero", mac_addr);
|
||||
|
||||
// Phase 5: Display connection info
|
||||
print("✅ VM " + vm_id_actual + " is ready!");
|
||||
print("");
|
||||
print("🌐 Network Information:");
|
||||
if ipv4 != () && ipv4 != "" {
|
||||
print(" IPv4: " + ipv4);
|
||||
} else {
|
||||
print(" IPv4: Not assigned yet (VM may still be configuring)");
|
||||
}
|
||||
if ipv6 != () && ipv6 != "" {
|
||||
print(" IPv6: " + ipv6);
|
||||
} else {
|
||||
print(" IPv6: Not available");
|
||||
}
|
||||
print("");
|
||||
print("💡 VM is running in the background. To connect:");
|
||||
print(" SSH: ssh ubuntu@" + (if ipv4 != () && ipv4 != "" { ipv4 } else { "<IPv4>" }));
|
||||
print("");
|
||||
print("🛑 To stop the VM later:");
|
||||
print(" cloudhv_vm_stop(\"" + vm_id_actual + "\", false);");
|
||||
print(" cloudhv_vm_delete(\"" + vm_id_actual + "\", true);");
|
||||
|
||||
/*
|
||||
try {
|
||||
cloudhv_vm_stop(vm_id_actual, false);
|
||||
cloudhv_vm_delete(vm_id_actual, true);
|
||||
print("VM stopped and cleaned up.");
|
||||
} catch (e) {
|
||||
print("Warning: cleanup failed: " + e.to_string());
|
||||
}
|
||||
*/
|
Reference in New Issue
Block a user