Reattach NIC to vbox VM to workaround connection issue
Add start NAT network for VirtualBox VM.
Add NIC reattach after the VirtualBox VM is started. This
is a workaround for the VM not connecting via NAT network.
Remove VM configuration file automatically if found.
Change-Id: I4e4898785aa20519e4b39332737bfa38711b0f18
Related-PROD: PROD-29130
diff --git a/predefine-vm/define-vm-vbox.sh b/predefine-vm/define-vm-vbox.sh
index 277b940..e2c4cf6 100755
--- a/predefine-vm/define-vm-vbox.sh
+++ b/predefine-vm/define-vm-vbox.sh
@@ -44,6 +44,7 @@
vboxmanage natnetwork modify --netname "${DEPLOY_NET_NAME}" --network "${DEPLOY_NETWORK}" --enable --dhcp off
fi
fi
+ vboxmanage natnetwork start --netname "${DEPLOY_NET_NAME}"
}
update_iso() {
@@ -105,6 +106,10 @@
}
define_vm() {
+ VBOX_CONFIG_FILE="${HOME}/VirtualBox VMs/${VM_NAME}/${VM_NAME}.vbox"
+ if test -f "${VBOX_CONFIG_FILE}"; then
+ rm -v "${VBOX_CONFIG_FILE}"
+ fi
vboxmanage createvm --name "${VM_NAME}" --register
vboxmanage modifyvm "${VM_NAME}" --ostype Ubuntu_64 \
--memory 8188 --cpus 2 --vram 16 \
@@ -130,6 +135,7 @@
vboxmanage storageattach "${VM_NAME}" \
--storagectl "IDE" --port 0 --device 0 \
--type dvddrive --medium "${CONFIG_DRIVE_ISO}"
+
}
[ -f env_overrides ] && source env_overrides
@@ -183,4 +189,8 @@
create_host_net
define_vm
vboxmanage startvm "${VM_NAME}" --type headless
+
+vboxmanage controlvm "${VM_NAME}" nic1 null
+vboxmanage controlvm "${VM_NAME}" nic1 natnetwork "${DEPLOY_NET_NAME}"
+
echo "VM successfully started, check the VM console"