Example #1
0
def register_server(url, ca, secret, address=None):
    if _service_is_running() is True:
        console_log.warning("chroma-agent service was running before registration, stopping.")
        agent_service.stop()

    crypto = Crypto(conf.ENV_PATH)
    # Call delete in case we are over-writing a previous configuration that wasn't removed properly
    crypto.delete()
    crypto.install_authority(ca)

    agent_client = AgentClient(url + "register/%s/" % secret,
                               ActionPluginManager(),
                               DevicePluginManager(),
                               ServerProperties(),
                               crypto)

    registration_result = agent_client.register(address)
    crypto.install_certificate(registration_result['certificate'])

    conf.set_server_url(url)

    console_log.info("Enabling chroma-agent service")
    agent_service.enable()

    console_log.info("Starting chroma-agent service")
    agent_service.start()

    return registration_result
Example #2
0
def _convert_agentstore_config():
    server_conf_path = os.path.join(config.path, "server_conf")
    if os.path.exists(server_conf_path):
        with open(server_conf_path) as f:
            old_server_conf = json.load(f)
        set_server_url(old_server_conf.get("url").replace("/agent/", "/"))
        os.unlink(server_conf_path)
    else:
        try:
            url = config.get("settings",
                             "server").get("url").replace("/agent/", "/")
            set_server_url(url)

            config.delete("settings", "server")
        except (KeyError, TypeError):
            pass

    crypto_files = map(
        lambda x: (os.path.join(config.path, x), os.path.join(ENV_PATH, x)),
        ["authority.crt", "private.pem", "self.crt"],
    )

    map(lambda x: migrate_file(*x), crypto_files)

    uuid_re = re.compile(
        r"[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12}")
    for entry in os.listdir(config.path):
        if uuid_re.match(entry):
            target_conf_path = os.path.join(config.path, entry)
            with open(target_conf_path) as f:
                old_target_conf = json.load(f)
            config.set("targets", entry, old_target_conf)
            os.unlink(target_conf_path)
Example #3
0
def reregister_server(url, address):
    """ Update manager url and register agent address with manager """
    if _service_is_running() is True:
        console_log.warning(
            "chroma-agent service was running before registration, stopping.")
        agent_service.stop()

    conf.set_server_url(url)
    crypto = Crypto(conf.ENV_PATH)
    agent_client = AgentClient(
        url + "reregister/",
        ActionPluginManager(),
        DevicePluginManager(),
        ServerProperties(),
        crypto,
    )
    data = {"address": address, "fqdn": agent_client._fqdn}

    try:
        result = agent_client.post(data)
    except HttpError:
        console_log.error("Reregistration failed to %s with request %s" %
                          (agent_client.url, data))
        raise

    console_log.info("Starting chroma-agent service")
    agent_service.start()

    return result