Beispiel #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(config.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'])

    config.set('settings', '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
Beispiel #2
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()

    config.set('settings', 'server', {'url': url})
    crypto = Crypto(config.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
Beispiel #3
0
def set_profile(profile_json):
    profile = json.loads(profile_json)

    try:
        config.set('settings', 'profile', profile)
    except ConfigKeyExistsError:
        config.update('settings', 'profile', profile)
Beispiel #4
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)
Beispiel #5
0
def configure_copytool(id, index, bin_path, archive_number, filesystem,
                       mountpoint, hsm_arguments):
    copytool = Copytool(
        id=id,
        index=index,
        bin_path=bin_path,
        filesystem=filesystem,
        mountpoint=mountpoint,
        hsm_arguments=hsm_arguments,
        archive_number=archive_number,
    )

    try:
        config.set("copytools", copytool.id, copytool.as_dict())
    except ConfigKeyExistsError:
        # This can happen when we've redeployed on a worker that was
        # already configured (force-removed, etc.)
        copytool_log.warn(
            "Copytool %s was already configured -- assuming we need to update"
            % copytool.id)
        update_kwargs = copytool.as_dict()
        del update_kwargs["id"]
        update_copytool(copytool.id, **update_kwargs)

    return copytool.id
Beispiel #6
0
def set_profile(profile_json):
    profile = json.loads(profile_json)

    try:
        config.set('settings', 'profile', profile)
        set_iml_profile(profile.name, profile.bundles, profile.packages)
    except ConfigKeyExistsError:
        config.update('settings', 'profile', profile)
Beispiel #7
0
def set_profile(profile_json):
    profile = json.loads(profile_json)

    try:
        config.set("settings", "profile", profile)
    except ConfigKeyExistsError:
        config.update("settings", "profile", profile)

    set_iml_profile(profile.get("name"), profile.get("bundles"),
                    profile.get("packages"))
Beispiel #8
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)
        config.set('settings', 'server', old_server_conf)
        os.unlink(server_conf_path)

    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)
Beispiel #9
0
def set_server_url(url):
    server_conf = dict(url=url)
    try:
        config.set('settings', 'server', server_conf)
    except ConfigKeyExistsError:
        config.update('settings', 'server', server_conf)