1
0
mirror of https://github.com/gryf/boxpy.git synced 2025-12-18 21:10:17 +01:00

Pass more than one machine to destroy command.

From now on, there is a possibility to pass more than one machine to be
destroyed.
This commit is contained in:
2021-11-04 08:37:10 +01:00
parent 4581ab0ed0
commit 353d848072
2 changed files with 19 additions and 11 deletions

View File

@@ -22,7 +22,7 @@ Requirements
- `requests`_
- Virtualbox (obviously)
- ``mkisofs`` or ``genisoimage`` command for generating iso image
- ``mkisofs`` or ``genisoimage`` command for generating ISO image
- ``wget`` command for fetching images
- ``sha256sum`` command for checksum check
- ``qemu-img`` from *qemu-utils* package command for converting between images

28
box.py
View File

@@ -18,7 +18,7 @@ import requests
import yaml
__version__ = "1.2"
__version__ = "1.3"
CACHE_DIR = os.environ.get('XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
CLOUD_IMAGE = "ci.iso"
@@ -173,11 +173,16 @@ _boxpy() {
fi
;;
destroy|info)
info)
if [[ ${prev} == ${cmd} ]]; then
_vms_comp vms
fi
;;
destroy)
_vms_comp vms
_get_excluded_items "${COMPREPLY[@]}"
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
;;
list)
items=(--long --running --run-by-boxpy)
_get_excluded_items "${items[@]}"
@@ -1222,13 +1227,16 @@ def vmcreate(args, conf=None):
def vmdestroy(args):
vbox = VBoxManage(args.name)
if not vbox.get_vm_info():
LOG.fatal(f'Cannot remove VM "{args.name}" - it doesn\'t exists.')
return 18
else:
LOG.header('Removing VM: %s', args.name)
return VBoxManage(args.name).destroy()
for name in args.name:
vbox = VBoxManage(name)
if not vbox.get_vm_info():
LOG.fatal(f'Cannot remove VM "{name}" - it doesn\'t exists.')
return 18
LOG.header('Removing VM: %s', name)
res = VBoxManage(name).destroy()
if res:
return res
return 0
def vmlist(args):
@@ -1431,7 +1439,7 @@ def main():
f"Default {DISTROS['ubuntu']['default_version']}")
destroy = subparsers.add_parser('destroy', help='destroy VM')
destroy.add_argument('name', help='name or UUID of the VM')
destroy.add_argument('name', nargs='+', help='name or UUID of the VM')
destroy.set_defaults(func=vmdestroy)
list_vms = subparsers.add_parser('list', help='list VMs')