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`_ - `requests`_
- Virtualbox (obviously) - Virtualbox (obviously)
- ``mkisofs`` or ``genisoimage`` command for generating iso image - ``mkisofs`` or ``genisoimage`` command for generating ISO image
- ``wget`` command for fetching images - ``wget`` command for fetching images
- ``sha256sum`` command for checksum check - ``sha256sum`` command for checksum check
- ``qemu-img`` from *qemu-utils* package command for converting between images - ``qemu-img`` from *qemu-utils* package command for converting between images

28
box.py
View File

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