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
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
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
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
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