def console(username, cid, cmds=None): """在容器中打入 Console 进程 :param str username: Fuvism user name :param str cid: The container uuid :param list or None cmd: str: Console command(e.g., `ipython`, `python manager.py runserver`) None: Bash console """ urls = {} port = None params = {"AttachStdout": False, "AttachStderr": False, "Tty": True} if cmds: for cmd in cmds: s, m, r = processes.processes(username, cid, cmd) if s == 1: port = r if cmd.startswith("webfront"): params["Cmd"] = [ "bash", "-c", "mkdir -p %s && pushd %s && \ python -m SimpleHTTPServer %s" % (cmd.split(" ")[-1], cmd.split(" ")[-1], port) ] else: params["Cmd"] = [ "/bin/sh", "-c", BASE_CMD % (r, "False", cmd) ] s, m, r = _console_exec(username, cid, params) if s != 0: return (s, m, r) s, m, r = _console_save(username, cid, cmd, port) if s != 0: return (s, m, "") urls[cmd] = r elif s == 0: urls[cmd] = r else: return (s, m, r) return (0, "", urls) else: for i in True, False: port = CONSOLE_PORT_BEG if not i: port = int(CONSOLE_PORT_BEG) + 1 params["Cmd"] = [ "/bin/sh", "-c", BASE_CMD % (port, "%s" % i, "bash") ] s, m, r = _console_exec(username, cid, params) if s != 0: return (s, m, r) s, m, r = _console_save(username, cid) if s != 0: return (s, m, "") return (s, m, r)
def get_running_vms(self): vms = [] procs = processes(self.target, self.options).parse_proc_file() for proc in procs: vm = {} if '/usr/libexec/qemu-kvm' in proc['command']: s = proc['command'] vm['name'] = s[s.find('-name'):-1].split()[1].split( ',')[0].replace('guest=', '') vm.update(proc) vms.append(vm) return vms
def main(): try: opt, arg = getopt.getopt( sys.argv[1:], "", ["processes", "modules", "startup", "services", "schedule-tasks"]) except getopt.GetoptError as err: print(err) sys.exit(-1) if not opt or arg: print("Invalid option") sys.exit(-1) for o, a in opt: if o == "--processes": processes.processes() if o == "--modules": modules.modules() if o == "--startup": startup.startup() if o == "--services": services.services() if o == "--schedule-tasks": scheduletasks.sched()
def btnExecContent(self): if (self.isChanged): self.model = processes(self.dbPath.text(), self.queryPath.text(), self.isFolder) accu = self.model.calc_accuracy(self.processNum) self.lblAccu.setText("{}{:.2%}".format(self.prefixAns, accu))