From d7544f52f693f992a0ec0dcba327c3c26c9211af Mon Sep 17 00:00:00 2001 From: gryf Date: Thu, 19 Aug 2021 21:09:06 +0200 Subject: [PATCH] Added run type option to create and rebuild subcommand. For now, the only mode VirtualBox VM has launched was headless. For debugging purposes, there were other types allowed using --type switch for command create and rebuild, while headless will remain the default one. --- box.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/box.py b/box.py index a693823..a6b0cb2 100755 --- a/box.py +++ b/box.py @@ -136,7 +136,7 @@ _boxpy() { ;; create|rebuild) items=(--cpus --disable-nested --disk-size --distro --forwarding - --key --memory --hostname --port --config --version) + --key --memory --hostname --port --config --version --type) if [[ ${prev} == ${cmd} ]]; then if [[ ${cmd} = "rebuild" ]]; then _vms_comp vms @@ -158,6 +158,10 @@ _boxpy() { --distro) COMPREPLY=( $(compgen -W "ubuntu fedora" -- ${cur}) ) ;; + --type) + COMPREPLY=( $(compgen -W "gui headless sdl separate" \ + -- ${cur}) ) + ;; --*) COMPREPLY=( ) ;; @@ -751,9 +755,9 @@ class VBoxManage: return False return True - def poweron(self): + def poweron(self, type_='headless'): if Run(['vboxmanage', 'startvm', self.name_or_uuid, '--type', - 'headless']).returncode != 0: + type_]).returncode != 0: LOG.fatal('Failed to start: %s', self.name_or_uuid) raise BoxVBoxFailure() @@ -1109,7 +1113,7 @@ def vmcreate(args, conf=None): vbox.add_nic(key, val) # start the VM and wait for cloud-init to finish - vbox.poweron() + vbox.poweron(args.type) # give VBox some time to actually change the state of the VM before query time.sleep(3) @@ -1335,6 +1339,9 @@ def main(): help="disable nested virtualization") create.add_argument('-s', '--disk-size', help="disk size to be expanded " "to. By default to 10GB") + create.add_argument('-t', '--type', default='headless', + help="run type, headless by default.", + choices=['gui', 'headless', 'sdl', 'separate']) create.add_argument('-u', '--cpus', type=int, help="amount of CPUs to be " "configured. Default 1.") create.add_argument('-v', '--version', help=f"distribution version. " @@ -1375,6 +1382,9 @@ def main(): help="disable nested virtualization") rebuild.add_argument('-s', '--disk-size', help='disk size to be expanded to') + rebuild.add_argument('-t', '--type', default='headless', + help="run type, headless by default.", + choices=['gui', 'headless', 'sdl', 'separate']) rebuild.add_argument('-u', '--cpus', type=int, help='amount of CPUs to be configured') rebuild.add_argument('-v', '--version', help='distribution version')