def stop(self): """ stop domU using system callbacks """ # be sure not to stop the dom0 if domU network config not loaded if self.srv_ip == self.dom0.srv_ip: return False # shutdown domU and return status change fapi.sudo(self.srv_ip, "shutdown -h now") return scc.wait_host(self.srv_ip, "DOWN", 10)
def wget_file(self, target, storage, use_sudo = False): """ wget file or directory """ cmd = "wget %s -O %s" % (target, storage) if use_sudo: return __fapi.sudo(self.srv_ip, cmd, nocheck = True) return __fapi.run(self.srv_ip, cmd, nocheck = True)
def check_iface(self, iface): """ check network iface presence """ out = __fapi.sudo(self.srv_ip, "ifconfig %s" % (iface), nocheck = True) if out.return_code != 0: return False return True
def chown_file(self, filename, owner, group, recursive = True): """ chown file with owner and group """ opts = "" if recursive is True: opts = "-R" return __fapi.sudo(self.srv_ip, "chown %s %s:%s %s " % (opts, owner, group, filename))
def tar_extract(self, target, storage, files = list(), compr = True, use_sudo = False): """ extract files from tar archive """ opts = "xf" if compr is True: opts = "xzf" cmd = "tar %s %s -C %s %s" % (opts, target, storage, " ".join(files)) if use_sudo: return __fapi.sudo(self.srv_ip, cmd, nocheck = True) return __fapi.run(self.srv_ip, cmd, nocheck = True)
def check_prerequisites(srv_ip): """ check prerequisites on remote host """ ret = True __LOG.log_d("trying to run command") out = __fapi.run(srv_ip, 'whoami', nocheck=True) if out.failed: __LOG.log_c("unable to execute commands on remote host") ret = False __LOG.log_d("trying to run sudo command") out = __fapi.sudo(srv_ip, 'whoami', nocheck=True) if out.failed: __LOG.log_c("unable to execute commands with sudo on remote host") ret = False return ret
def symlink(self, target, source, use_sudo = False): """ create symlink with 'ln' binary """ if use_sudo: return __fapi.sudo(self.srv_ip, "ln -s %s %s" % (target, source)) return __fapi.run(self.srv_ip, "ln -s %s %s" % (target, source))
def install_skel(self, skelpath, dirtarget): """ install skel in directory """ return __fapi.sudo(self.srv_ip, "rsync -a %s %s" % (skelpath, dirtarget))
def chmod_file(self, filename, mode, use_sudo = False): """ chmod file with mode """ if use_sudo: return __fapi.sudo(self.srv_ip, "chmod %s %s" % (mode, filename)) return __fapi.run(self.srv_ip, "chmod %s %s" % (mode, filename))
def xm_exec(self, xm_opts): """ Wrapper to run xm commands """ return fapi.sudo(self.dom0_instance.srv_ip, "xm %s" % (xm_opts))
def __xmlist_raw(self, xmlist_cmd): """ raw xm list """ xmlist_py = list(self.xmlist_py_template) xmlist_py.insert(-1, "try: %s" % (xmlist_cmd)) cmd = "python -c '%s'" % ("\n".join(xmlist_py)) return fapi.sudo(self.dom0_instance.srv_ip, cmd)
def xminfo_raw(self): """ raw xm info """ cmd_xminfo = "xm info" cmd_xminfo_c = "%s -c" % (cmd_xminfo) cmd = "%s && %s" % (cmd_xminfo, cmd_xminfo_c) return fapi.sudo(self.dom0_instance.srv_ip, cmd)