1
0
mirror of https://github.com/gryf/boxpy.git synced 2025-12-19 21:47:59 +01:00

Added destroy class and the corresponding class.

This commit is contained in:
2021-04-08 21:30:02 +02:00
parent 59c8b926d8
commit 4029284815

16
box.py
View File

@@ -286,6 +286,18 @@ class VMCreate:
subprocess.call(['rm', '-fr', self._tmp]) subprocess.call(['rm', '-fr', self._tmp])
class VMDestroy:
def __init__(self, args):
self.vm_name_or_uuid = args.name
def run(self):
subprocess.call(['vboxmanage', 'controlvm', self.vm_name_or_uuid,
'poweroff'], stderr=subprocess.DEVNULL)
if subprocess.call(['vboxmanage', 'unregistervm', self.vm_name_or_uuid,
'--delete']) != 0:
raise AttributeError(f'Removing VM {self.vm_name_or_uuid} failed')
def main(): def main():
parser = argparse.ArgumentParser(description="Automate deployment and " parser = argparse.ArgumentParser(description="Automate deployment and "
"maintenance of Ubuntu VMs using " "maintenance of Ubuntu VMs using "
@@ -312,6 +324,10 @@ def main():
help="SSH key to be add to the config drive. Default " help="SSH key to be add to the config drive. Default "
"~/.ssh/id_rsa") "~/.ssh/id_rsa")
destroy = subparsers.add_parser('destroy', help='destroy VM')
destroy.add_argument('name', help='name or UUID of the VM')
destroy.set_defaults(func=VMDestroy)
args = parser.parse_args() args = parser.parse_args()
try: try: