Exemple #1
0
    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)
Exemple #2
0
def get_default_conf_dict():
    conf_dict = {}
    option_list = config.build_options_list()

    for c in option_list:
        if c.hidden:
            continue

        s_d = {}
        if c.section in conf_dict:
            s_d = conf_dict[c.section]
        else:
            conf_dict[c.section] = s_d

        s_d[c.name] = (c.get_help(), c.get_default())
    return conf_dict
Exemple #3
0
    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)