예제 #1
0
def get_stats_type(name):
    _g_lock.acquire()
    try:
        if name not in _g_active_stats:
            raise exceptions.AgentOptionValueNotSetException("name")
        stat_obj = _g_active_stats[name]
        return stat_obj.get_stats_type()
    finally:
        _g_lock.release()
예제 #2
0
def stop_stats(name):
    _g_lock.acquire()
    try:
        if name not in _g_active_stats:
            raise exceptions.AgentOptionValueNotSetException("name")
        stat_obj = _g_active_stats[name]
        stat_obj.stop()
        del _g_active_stats[name]
    finally:
        _g_lock.release()
예제 #3
0
    def configure_server_with_puppet(self):

        if self.args.endpoint is None:
            raise exceptions.AgentOptionValueNotSetException("endpoint")

        # XXX it will only work with the default port.  There is no way for
        # the user to configure anything else in the console
        endpoint = urllib.parse.urlparse(self.args.endpoint).hostname

        puppet_extras_base_path = os.path.join(self.conf.extra_base_path,
                                               "puppetconf")
        puppet_extras_bin = os.path.join(self.conf.extra_base_path,
                                         "bin/puppet")

        try:
            utils.install_extras(self.conf,
                                 package=self.conf.extra_package_name)
        except exceptions.AgentExtrasNotInstalledException as ex:
            _g_logger.exception("An error occurred trying to install puppet.  "
                                "Exception message is %s" % str(ex))
            raise

        template_puppet_conf_path = os.path.join(puppet_extras_base_path,
                                                 "puppet.conf.template")
        if not os.path.exists(template_puppet_conf_path):
            raise exceptions.AgentExtrasNotInstalledException(
                "The puppet.conf template did not install properly.")
        if not os.path.exists(puppet_extras_bin):
            raise exceptions.AgentExtrasNotInstalledException(
                "The puppet binary did not install properly.")

        puppet_conf_path = self.conf.get_temp_file("puppet.conf")
        self._edit_puppet_conf(template_puppet_conf_path, puppet_conf_path,
                               endpoint)
        cert_file_path = self.conf.get_temp_file("cert.pem")
        key_file_path = self.conf.get_temp_file("key.pem")

        try:
            with open(cert_file_path, "w") as fptr:
                fptr.write(self.args.configCert)
            with open(key_file_path, "w") as fptr:
                fptr.write(self.args.configKey)

            exe = self.conf.get_script_location(
                "runConfigurationManagement-PUPPET")
            cmd = [
                exe, endpoint, cert_file_path, key_file_path,
                self.args.configClientName, self.conf.extra_base_path,
                puppet_conf_path
            ]
            return plugin_utils.run_command(self.conf, cmd)
        finally:
            plugin_utils.safe_delete(cert_file_path)
            plugin_utils.safe_delete(key_file_path)
            plugin_utils.safe_delete(puppet_conf_path)
예제 #4
0
파일: config.py 프로젝트: QSFT/unix-agent
def get_connection_object(conf):
    con_type = conf.connection_type
    if not con_type:
        raise exceptions.AgentOptionValueNotSetException("connection_type")

    # XXX should we stevedore load this or __import__ it or go with a
    # hard coded list?  for now hard coded list

    if con_type == "success_tester":
        source_file = conf.connection_source_file
        if not source_file:
            raise exceptions.AgentOptionValueNotSetException(
                "[connection]source_file",
                msg="Using the %s connection type." % con_type)
        fptr = open(source_file, "r")
        if not conf.connection_dest_file:
            raise exceptions.AgentOptionValueNotSetException(
                "[connection]dest_file",
                msg="Using the %s connection type." % con_type)

        outf = open(conf.connection_dest_file, "w")
        con = test_connection.TestConnection(fptr, outf)
    elif con_type == "ws":
        if not conf.connection_agentmanager_url:
            raise exceptions.AgentOptionValueNotSetException(
                "[connection]agentmanager_url")
        con = websocket.WebSocketConnection(
            conf.connection_agentmanager_url,
            backoff_amount=conf.connection_backoff,
            max_backoff=conf.connection_max_backoff,
            heartbeat=conf.connection_heartbeat_frequency,
            allow_unknown_certs=conf.connection_allow_unknown_certs,
            ca_certs=conf.connection_ca_cert)
    else:
        raise exceptions.AgentOptionValueException("[connection]type",
                                                   con_type,
                                                   "ws,success_tester,dummy")
    return con
예제 #5
0
def verify_config_file(opts):
    must_haves = [
        "connection_type", "cloud_type", "platform_name",
        "connection_agentmanager_url"
    ]
    warn_haves = ["cloud_metadata_url"]

    for must in must_haves:
        try:
            getattr(opts, must)
        except:
            raise exceptions.AgentOptionValueNotSetException(
                must, msg="Please check your config file.")

    for warn in warn_haves:
        try:
            getattr(opts, warn)
        except:
            _g_logger.warn("Please check the config file.  The value %s is "
                           "missing and could be needed." % warn)