コード例 #1
0
    def _run_linux(self, cmd, expect_fail, detach=False):

        ret_value = None

        _cmd = cmd
        if detach:
            _cmd = "nohup {} &> /dev/null &".format(cmd)

        logger.info("[LDROPLET {}]: running: {}".format(self.id, _cmd))

        out = self.conn.run(_cmd, warn=True)
        if not detach:
            ret_value = (out.exited, out.stdout.strip())
        if (not detach and ret_value[0] != 0):
            if not expect_fail:
                logger.error("[LDROPLET {}]: {}".format(self.id, ret_value[1]))
            else:
                logger.info("[LDROPLET {}]: {}".format(self.id, ret_value[1]))

        if not detach:
            logger.debug(
                "[LDROPLET {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}"
                .format(self.id, _cmd, ret_value[0], ret_value[1]))

        return ret_value
コード例 #2
0
    def local(self, cmd):
        ret_value = None
        logger.info("[LOCAL {}]: running: {}".format(self.id, cmd))
        try:
            out = run_cmd(cmd)
            ret_value = (out[0], out[1])
            if (ret_value[0] != 0):
                logger.error("[LOCAL {}]: {}".format(self.id, ret_value[1]))

            logger.debug(
                "[LOCAL {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}"
                .format(self.id, cmd, ret_value[0], ret_value[1]))

            return ret_value
        except Exception as e:
            logger.error("[LOCAL {}]: {}".format(self.id, str(e)))
            return None
コード例 #3
0
    def run(self, cmd, detach=False):
        """
        Runs a command directly on the droplet
        """

        ret_value = None
        if (self.droplet_type == 'docker'):
            out = self.container.exec_run(cmd, detach=detach)
            if not detach:
                ret_value = (out.exit_code, out.output.decode("utf-8"))

        logger.info("[DROPLET {}]: running: {}".format(self.id, cmd))
        if (not detach and ret_value[0] == 1):
            logger.error("[DROPLET {}]: {}".format(self.id, ret_value[1]))

        if not detach:
            logger.debug(
                "[DROPLET {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}".format(self.id, cmd, ret_value[0], ret_value[1]))

        return ret_value
コード例 #4
0
    def _run_docker(self, cmd, expect_fail, detach=False):

        ret_value = None

        out = self.container.exec_run(cmd, detach=detach)
        if not detach:
            ret_value = (out.exit_code, out.output.decode("utf-8"))

        logger.info("[DROPLET {}]: running: {}".format(self.id, cmd))
        if (not detach and ret_value[0] != 0):
            if not expect_fail:
                logger.error("[LDROPLET {}]: {}".format(self.id, ret_value[1]))
            else:
                logger.info("[LDROPLET {}]: {}".format(self.id, ret_value[1]))

        if not detach:
            logger.debug(
                "[DROPLET {}]: running\n    command:\n {}, \n    exit_code: {},\n    output:\n {}"
                .format(self.id, cmd, ret_value[0], ret_value[1]))

        return ret_value
コード例 #5
0
ファイル: droplet.py プロジェクト: yangnany/mizar
 def run_from_root(self, cmd):
     ret_value = run_cmd(cmd)
     logger.debug(
         "[DROPLET {}]: running from root\n    command:\n {}, \n    exit_code: {},\n    output:\n {}"
         .format(self.id, cmd, ret_value[0], ret_value[1]))
     return ret_value