1
0
mirror of https://github.com/gryf/boxpy.git synced 2026-02-02 22:25:53 +01:00

2 Commits
1.0 ... 1.1

Author SHA1 Message Date
d7544f52f6 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.
2021-08-19 21:09:06 +02:00
3c43263bb9 Fix clashing version from boxpy and subcommands.
Currently, you could pass long version of '--version' option to either
boxpy itself and subcommands create and rebuild. With this patch proper
context is now detected.
2021-08-19 21:08:34 +02:00

20
box.py
View File

@@ -136,7 +136,7 @@ _boxpy() {
;; ;;
create|rebuild) create|rebuild)
items=(--cpus --disable-nested --disk-size --distro --forwarding 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 [[ ${prev} == ${cmd} ]]; then
if [[ ${cmd} = "rebuild" ]]; then if [[ ${cmd} = "rebuild" ]]; then
_vms_comp vms _vms_comp vms
@@ -158,6 +158,10 @@ _boxpy() {
--distro) --distro)
COMPREPLY=( $(compgen -W "ubuntu fedora" -- ${cur}) ) COMPREPLY=( $(compgen -W "ubuntu fedora" -- ${cur}) )
;; ;;
--type)
COMPREPLY=( $(compgen -W "gui headless sdl separate" \
-- ${cur}) )
;;
--*) --*)
COMPREPLY=( ) COMPREPLY=( )
;; ;;
@@ -751,9 +755,9 @@ class VBoxManage:
return False return False
return True return True
def poweron(self): def poweron(self, type_='headless'):
if Run(['vboxmanage', 'startvm', self.name_or_uuid, '--type', 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) LOG.fatal('Failed to start: %s', self.name_or_uuid)
raise BoxVBoxFailure() raise BoxVBoxFailure()
@@ -1109,7 +1113,7 @@ def vmcreate(args, conf=None):
vbox.add_nic(key, val) vbox.add_nic(key, val)
# start the VM and wait for cloud-init to finish # 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 # give VBox some time to actually change the state of the VM before query
time.sleep(3) time.sleep(3)
@@ -1335,6 +1339,9 @@ def main():
help="disable nested virtualization") help="disable nested virtualization")
create.add_argument('-s', '--disk-size', help="disk size to be expanded " create.add_argument('-s', '--disk-size', help="disk size to be expanded "
"to. By default to 10GB") "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 " create.add_argument('-u', '--cpus', type=int, help="amount of CPUs to be "
"configured. Default 1.") "configured. Default 1.")
create.add_argument('-v', '--version', help=f"distribution version. " create.add_argument('-v', '--version', help=f"distribution version. "
@@ -1375,6 +1382,9 @@ def main():
help="disable nested virtualization") help="disable nested virtualization")
rebuild.add_argument('-s', '--disk-size', rebuild.add_argument('-s', '--disk-size',
help='disk size to be expanded to') 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, rebuild.add_argument('-u', '--cpus', type=int,
help='amount of CPUs to be configured') help='amount of CPUs to be configured')
rebuild.add_argument('-v', '--version', help='distribution version') rebuild.add_argument('-v', '--version', help='distribution version')
@@ -1398,7 +1408,7 @@ def main():
LOG.set_verbose(args.verbose, args.quiet) LOG.set_verbose(args.verbose, args.quiet)
if args.version: if not getattr(args, 'func') and args.version:
LOG.info(f'boxpy {__version__}') LOG.info(f'boxpy {__version__}')
parser.exit() parser.exit()