From bf93856104a5d39d4c2998da52d7cbd6d55f17d5 Mon Sep 17 00:00:00 2001 From: MJB <mjb@it-innovation.soton.ac.uk> Date: Wed, 11 Apr 2018 00:00:44 +0100 Subject: [PATCH] new delete vm script --- scripts/build/deleteallvms.py | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 scripts/build/deleteallvms.py diff --git a/scripts/build/deleteallvms.py b/scripts/build/deleteallvms.py new file mode 100644 index 0000000..047d947 --- /dev/null +++ b/scripts/build/deleteallvms.py @@ -0,0 +1,47 @@ +#!/bin/python +## © University of Southampton IT Innovation Centre, 2017 +## +## Copyright in this software belongs to University of Southampton +## IT Innovation Centre of Gamma House, Enterprise Road, +## Chilworth Science Park, Southampton, SO16 7NS, UK. +## +## This software may not be used, sold, licensed, transferred, copied +## or reproduced in whole or in part in any manner or form or in or +## on any media by any person other than in accordance with the terms +## of the Licence Agreement supplied with the software, or otherwise +## without the prior written consent of the copyright owners. +## +## This software is distributed WITHOUT ANY WARRANTY, without even the +## implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +## PURPOSE, except where stated in the Licence Agreement supplied with +## the software. +## +## Created By : Michael Boniface +## Created Date : 28-03-2018 +## Created for Project : FLAME +import subprocess +import sys + +proc = subprocess.Popen(['vboxmanage', 'list', 'vms'], stdout=subprocess.PIPE, shell=True) +out, err = proc.communicate() +if proc.returncode != 0: + print("Could list virtualbox vms") + sys.exit() + +vms = out.strip().decode('ascii') +lines = vms.split("\n") +for vm in lines: + vm_id = vm.split()[0].replace('"', '') + print("Removing VM: {0}".format(vm_id)) + + proc = subprocess.Popen(['vboxmanage', 'controlvm', vm_id, 'poweroff'], stdout=subprocess.PIPE, shell=True) + out, err = proc.communicate() + print(out) + if proc.returncode != 0: + print("Could not power off VM: {0}".format(vm_id)) + + proc = subprocess.Popen(['vboxmanage', 'unregistervm', vm_id, '--delete'], stdout=subprocess.PIPE, shell=True) + out, err = proc.communicate() + if proc.returncode != 0: + print("Could not unregister VM: {0}".format(vm_id)) + -- GitLab