def redircmd(self, infd, outfd, errfd, args, wait=True): """ Execute a command on a node with standard input, output, and error redirected according to the given file descriptors. :param infd: stdin file descriptor :param outfd: stdout file descriptor :param errfd: stderr file descriptor :param list[str]|str args: command arguments :param bool wait: wait flag :return: command status :rtype: int """ self._verify_connection() # run command, return process when not waiting args = utils.split_args(args) cmd = self._cmd_args() + args logging.debug("redircmd: %s", cmd) p = Popen(cmd, stdin=infd, stdout=outfd, stderr=errfd) if not wait: return p # wait for and return exit status status = p.wait() if status: logging.warning("cmd exited with status %s: %s", status, args) return status
def icmd(self, args): """ Execute an icmd against a node. :param list[str]|str args: command arguments :return: command result :rtype: int """ args = utils.split_args(args) return os.spawnlp(os.P_WAIT, constants.VCMD_BIN, constants.VCMD_BIN, "-c", self.ctrlchnlname, "--", *args)
def popen(self, args): """ Execute a popen command against the node. :param list[str]|str args: command arguments :return: popen object, stdin, stdout, and stderr :rtype: tuple """ self._verify_connection() args = utils.split_args(args) cmd = self._cmd_args() + args logging.debug("popen: %s", cmd) p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE) return p, p.stdin, p.stdout, p.stderr
def cmd(self, args, wait=True): """ Execute a command on a node and return the status (return code). :param list[str]|str args: command arguments :param bool wait: wait for command to end or not :return: command status :rtype: int """ self._verify_connection() args = utils.split_args(args) # run command, return process when not waiting cmd = self._cmd_args() + args logging.debug("cmd wait(%s): %s", wait, cmd) p = Popen(cmd, stdout=PIPE, stderr=PIPE) if not wait: return 0 # wait for and return exit status return p.wait()