from sh import VBoxManage from collections import OrderedDict from pprint import pprint from cloudmesh.iaas.ComputeBaseType import ComputeBaseType from cloudmesh_base.logger import LOGGER log = LOGGER(__file__) vbox_list = VBoxManage.bake("list", "vms", "-l") vbox_vminfo = VBoxManage.bake("showvminfo") vbox_controlvm = VBoxManage.bake("controlvm") vbox_startvm = VBoxManage.bake("startvm") # # LIST # def filter_attributes(d, filterkeys=["name", "uuid", "state"]): """filters from the given dict just the attributed with the specified keys""" f = {} for name in d: m = d[name] f[m["name"]] = dict(zip(filterkeys, [m[k] for k in filterkeys])) return f def extract_state(attribute, value): if attribute == "state": value = value.split("(")[0]
from sh import VBoxManage from collections import OrderedDict from pprint import pprint vbox_list = VBoxManage.bake("list", "vms", "-l") vbox_vminfo = VBoxManage.bake("showvminfo") # # LIST # def convert_to_dict(lines): m = {} for line in lines: try: attribute, value = line.split(':', 1) if attribute == "State": value = value.split("(")[0] m.update ({attribute : value.strip()}) except: pass return m def filter_attributes(d, filterkeys=["Name", "UUID", "State"]): f = {} for name in d: m = d[name] f[m["Name"]] = dict(zip(filterkeys, [m[k] for k in filterkeys])) return f def get_vms(filter=None):
from __future__ import print_function from sh import VBoxManage from collections import OrderedDict from pprint import pprint vbox_list = VBoxManage.bake("list", "vms", "-l") vbox_vminfo = VBoxManage.bake("showvminfo") # # LIST # def convert_to_dict(lines): m = {} for line in lines: try: attribute, value = line.split(":", 1) if attribute == "State": value = value.split("(")[0] m.update({attribute: value.strip()}) except: pass return m def filter_attributes(d, filterkeys=["Name", "UUID", "State"]): f = {} for name in d: m = d[name] f[m["Name"]] = dict(zip(filterkeys, [m[k] for k in filterkeys]))
from sh import VBoxManage from collections import OrderedDict from pprint import pprint from cloudmesh.iaas.ComputeBaseType import ComputeBaseType from cloudmesh_common.logger import LOGGER log = LOGGER(__file__) vbox_list = VBoxManage.bake("list", "vms", "-l") vbox_vminfo = VBoxManage.bake("showvminfo") vbox_controlvm = VBoxManage.bake("controlvm") vbox_startvm = VBoxManage.bake("startvm") # # LIST # def filter_attributes(d, filterkeys=["name", "uuid", "state"]): """filters from the given dict just the attributed with the specified keys""" f = {} for name in d: m = d[name] f[m["name"]] = dict(zip(filterkeys, [m[k] for k in filterkeys])) return f def extract_state(attribute, value): if attribute == "state": value = value.split("(")[0]