// Clean VM Launch Script // Creates a VM using builder pattern with concise output let vm_id = "vm-clean-test"; // Phase 0: Pre-clean any existing VM with the same id (best-effort) // This avoids TAP "Resource busy" when a previous run is still active. try { cloudhv_vm_stop(vm_id, true); } catch (e) { // ignore } // brief wait to let processes exit and TAP release wait_for_vm_boot(1); try { cloudhv_vm_delete(vm_id, true); } catch (e) { // ignore } // Phase 1: Host check let hc = host_check(); if !(hc.ok == true) { throw "Host check failed: missing dependencies"; } // Phase 2: Create VM using fluent builder pattern 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 wait_for_vm_boot(10); // Phase 4: Discover VM IP addresses (robust, no hardcoded MAC/paths) let net = cloudhv_vm_network_info(vm_id_actual, 30); let ipv4 = net["ipv4"]; // Dynamic UNIT if not found yet let ipv6 = net["ipv6"]; // Dynamic UNIT if not found // Optional: you could also inspect net["mac"], net["bridge"], net["lease"] // Phase 5: Display connection info cloudhv_display_network_info(vm_id_actual, ipv4, ipv6); /* 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()); } */