def _run_command(self, cmd, key): cmd_args = [self.conf.system_sudo, cmd, key] (stdout, stderr, rc) = utils.run_command(self.conf, cmd_args) _g_logger.debug("Joyent metadata %d %s %s" % (rc, stdout, stderr)) if rc != 0: result = None else: result = stdout.strip() _g_logger.debug("Metadata value from cmd %s of %s is %s" % (cmd, key, str(result))) return (rc, result)
def run_scrubber(self, opts): exe = os.path.join(os.path.dirname(sys.executable), "dcm-agent-scrubber") cmd = [self.conf.system_sudo, '-E', exe] if opts: cmd.extend(opts) (stdout, stderr, rc) = utils.run_command(self.conf, cmd) if rc != 0: return plugin_base.PluginReply(rc, message=stdout, error_message=stderr) return plugin_base.PluginReply( 0, message="The image was scrubbed successfully")
def secure_delete(conf, file_name): """ Delete a file in a secure manner :param conf: The DCM agent config object. :param file_name: The name of the file to delete. """ exe_path = conf.get_script_location("secureDelete") (stdout, stderr, rc) = agent_util.run_command(conf, [exe_path, file_name]) _g_logger.debug("Secure delete executed with %d %s %s" % (rc, stdout, stderr)) with open(file_name, "w") as fptr: fptr.write("*" * 100) if os.path.exists(file_name): os.remove(file_name)
def run_command(conf, cmd_line, cwd=None, in_env=None, with_sudo=False): """Run an external executable or script. :param conf: The DCM agent config object. :param cmd_line: A list that is the command to run and all of its options :param cwd: The directory to start in. :param in_env: The environment dictionary to use when running the command. :param with_sudo: A bool that defines whether to run the command under sudo. :return: A 3 tuple (stdout, stderr, return code). """ if with_sudo: cmd_line = cmd_line[:] cmd_line.insert(0, '-E') cmd_line.insert(0, conf.system_sudo) return agent_util.run_command(conf, cmd_line, cwd=cwd, in_env=in_env)
def run_scrubber(self, opts): exe = os.path.join(os.path.dirname(sys.executable), "dcm-agent-scrubber") cmd = [ self.conf.system_sudo, '-E', exe ] if opts: cmd.extend(opts) (stdout, stderr, rc) = utils.run_command(self.conf, cmd) if rc != 0: return plugin_base.PluginReply( rc, message=stdout, error_message=stderr) return plugin_base.PluginReply( 0, message="The image was scrubbed successfully")