def run(self): key_file = self.conf.get_temp_file(self.args.userId + ".pub") try: if self.ssh_public_key: with open(key_file, "w") as f: f.write(self.ssh_public_key) self.ordered_param_list.append(key_file) plugin_utils.log_to_dcm_console_job_details( job_name=self.name, details="Attempting to add the user %s." % self.args.userId) rc = super(AddUser, self).run() admin_bool = self.args.administrator.lower() == "true" self._db.add_user( self.conf.agent_id, self.args.userId, self.ssh_public_key, admin_bool) plugin_utils.log_to_dcm_console_job_details( job_name=self.name, details="The user %s was added." % self.args.userId) return rc finally: if os.path.exists(key_file): plugin_utils.secure_delete(self.conf, key_file)
def run(self): key_file = self.conf.get_temp_file(self.args.userId + ".pub") try: if self.ssh_public_key: with open(key_file, "w") as f: f.write(self.ssh_public_key) self.ordered_param_list.append(key_file) plugin_utils.log_to_dcm_console_job_details( job_name=self.name, details="Attempting to add the user %s." % self.args.userId) rc = super(AddUser, self).run() admin_bool = self.args.administrator.lower() == "true" self._db.add_user(self.conf.agent_id, self.args.userId, self.ssh_public_key, admin_bool) plugin_utils.log_to_dcm_console_job_details( job_name=self.name, details="The user %s was added." % self.args.userId) return rc finally: if os.path.exists(key_file): plugin_utils.secure_delete(self.conf, key_file)
def run(self): response = urllib.request.urlopen(self.args.url) data = response.read() script_file = self.conf.get_temp_file("upgradescript") opts_file = self.conf.get_temp_file("upgradeopts") try: with open(script_file, "wb") as f: f.write(data) os.chmod(script_file, 0o755) # write the configuration to a file. We may not be safe assuming # that the default configuration location is correct opts_list = config.build_options_list() opts_dict = {} for opt in opts_list: if opt.section not in opts_dict: opts_dict[opt.section] = {} opts_dict[opt.section][opt.name] = getattr( self.conf, opt.get_option_name()) with open(opts_file, "w") as f: for section_name in opts_dict: f.write("[" + section_name + "]" + os.linesep) section = opts_dict[section_name] for key in section: f.write("%s=%s" % (key, section[key])) f.write(os.linesep) command_list = [ script_file, self.args.newVersion, dcm.agent.g_version, opts_file ] command_list.extend(self.args.args) _g_logger.debug("Plugin running the command %s" % str(command_list)) (stdout, stderr, rc) = plugin_utils.run_command(self.conf, command_list) _g_logger.debug("Command %s: stdout %s. stderr: %s" % (str(command_list), stdout, stderr)) return plugin_base.PluginReply(rc, message=stdout, error_message=stderr, reply_type="void") finally: if os.path.exists(script_file): plugin_utils.secure_delete(self.conf, script_file) if os.path.exists(opts_file): plugin_utils.secure_delete(self.conf, opts_file)
def run(self): response = urllib.request.urlopen(self.args.url) data = response.read() script_file = self.conf.get_temp_file("upgradescript") opts_file = self.conf.get_temp_file("upgradeopts") try: with open(script_file, "wb") as f: f.write(data) os.chmod(script_file, 0o755) # write the configuration to a file. We may not be safe assuming # that the default configuration location is correct opts_list = config.build_options_list() opts_dict = {} for opt in opts_list: if opt.section not in opts_dict: opts_dict[opt.section] = {} opts_dict[opt.section][opt.name] = getattr( self.conf, opt.get_option_name()) with open(opts_file, "w") as f: for section_name in opts_dict: f.write("[" + section_name + "]" + os.linesep) section = opts_dict[section_name] for key in section: f.write("%s=%s" % (key, section[key])) f.write(os.linesep) command_list = [script_file, self.args.newVersion, dcm.agent.g_version, opts_file] command_list.extend(self.args.args) _g_logger.debug("Plugin running the command %s" % str(command_list)) (stdout, stderr, rc) = plugin_utils.run_command( self.conf, command_list) _g_logger.debug("Command %s: stdout %s. stderr: %s" % (str(command_list), stdout, stderr)) return plugin_base.PluginReply( rc, message=stdout, error_message=stderr, reply_type="void") finally: if os.path.exists(script_file): plugin_utils.secure_delete(self.conf, script_file) if os.path.exists(opts_file): plugin_utils.secure_delete(self.conf, opts_file)