def vm_list(is_control_domain=VALUE_FALSE, is_snapshot=VALUE_FALSE, other_parameters="", work_dir="/tmp"): """Run xen vm list command.""" resp = fab.run_cmd(cmd=__CMD_VM_LIST.format(**locals())) vm = {} vm_list = {} lines = resp.splitlines() n_lines = len(lines) for index in range(n_lines): line = fab.cleanup_text(lines[index]) # Skip empty lines if re.match(r"^$", line): continue obj = line.split(":") if len(obj) > 1: key = re.search(re.compile(r"^[^ ]*"), obj[0]).group(0) if key in vm: # Start over new VM parameters uuid = vm[VALUE_UUID] del vm[VALUE_UUID] vm_list[uuid] = vm vm = {} if key not in vm: # Parameter belongs to same vm vm[key] = obj[1].strip() if index == n_lines - 1: # Last line reached uuid = vm[VALUE_UUID] del vm[VALUE_UUID] vm_list[uuid] = vm return vm_list
def stat(path=".", options=""): """Run stat command.""" return fab.run_cmd(cmd=__CMD_STAT.format(**locals()))
def ls(path=".", options=""): """Run ls command.""" return fab.run_cmd(cmd=__CMD_RMDIR.format(**locals()))
def rmdir(path): """Run rmdir command.""" return fab.run_cmd(cmd=__CMD_RMDIR.format(**locals()))
def mkdir(path, make_parent=True): """Run mkdir command.""" parent = "-p" if make_parent else "" return fab.run_cmd(cmd=__CMD_MKDIR.format(**locals()))
def unmount(mount_point): """Run unmount command.""" return fab.run_cmd(cmd=__CMD_UNMOUNT.format(**locals()))
def mount(type, remote_target, mount_point): """Run mount command.""" return fab.run_cmd(cmd=__CMD_MOUNT.format(**locals()))
def mountpoint(path="/", quiet=False): """Run mountpoint command.""" options = "-q" if quiet else "" return fab.run_cmd(cmd=__CMD_MOUNTPOINT.format(**locals()))
def du(path=""): """Run du command.""" resp = fab.run_cmd(cmd=__CMD_DU.format(**locals())) resp = resp.strip().split() return resp[0] if len(resp) > 1 else None
def df(path=""): """Run df command.""" return fab.run_cmd(cmd=__CMD_DF.format(**locals()))
def hostname(): """Run hostname command.""" return fab.run_cmd(cmd=__CMD_HOSTNAME)
def vm_uninstall(uuid, force=VALUE_FALSE): """Run xen vm uninstall command.""" return fab.run_cmd(cmd=__CMD_VM_UNINSTALL.format(**locals()))
def vm_export(uuid, filename, compress=VALUE_TRUE): """Run xen vm export command.""" # xe vm-export vm={uuid} filename={filename}" extension = ".xva.gz" if compress else ".xva" filename = filename + extension return fab.run_cmd(cmd=__CMD_VM_EXPORT.format(**locals()))
def template_param_set(uuid, is_a_template=VALUE_FALSE, ha_always_run=VALUE_FALSE): """Run xen template-param-set command.""" return fab.run_cmd(cmd=__CMD_TEMPLATE_PARAM_SET.format(**locals()))
def vm_snapshot(uuid, new_name_label): """Run xen template-param-set command.""" resp = fab.run_cmd(cmd=__CMD_VM_SNAPSHOT.format(**locals())) return resp