Example #1
0
def prepare_configuration(ctx, agent_config):
    if is_on_management_worker(ctx):
        # we are starting a worker dedicated for a deployment
        # (not specific node)
        # use the same user we used when bootstrapping
        if 'MANAGEMENT_USER' in os.environ:
            agent_config['user'] = os.environ['MANAGEMENT_USER']
        else:
            raise NonRecoverableError(
                'Cannot determine user for deployment user:'******'MANAGEMENT_USER is not set')
        workflows_worker = agent_config['workflows_worker']\
            if 'workflows_worker' in agent_config else False
        suffix = '_workflows' if workflows_worker else ''
        name = '{0}{1}'.format(ctx.deployment.id, suffix)
        agent_config['name'] = name
    else:
        agent_config['host'] = get_machine_ip(ctx)
        _set_ssh_key(ctx, agent_config)
        _set_user(ctx, agent_config)
        _set_remote_execution_port(ctx, agent_config)
        agent_config['name'] = ctx.instance.id

    _set_wait_started_config(agent_config)

    _set_home_dir(ctx, agent_config)

    home_dir = agent_config['home_dir']
    agent_config['celery_base_dir'] = home_dir

    agent_config['base_dir'] = '{0}/cloudify.{1}'.format(
        home_dir, agent_config['name'])
    agent_config['init_file'] = '/etc/init.d/celeryd-{0}'.format(
        agent_config['name'])
    agent_config['config_file'] = '/etc/default/celeryd-{0}'.format(
        agent_config['name'])
    agent_config['includes_file'] = '{0}/work/celeryd-includes'.format(
        agent_config['base_dir'])

    disable_requiretty = True
    if 'disable_requiretty' in agent_config:
        disable_requiretty_value = str(
            agent_config['disable_requiretty']).lower()
        if disable_requiretty_value.lower() == 'true':
            disable_requiretty = True
        elif disable_requiretty_value.lower() == 'false':
            disable_requiretty = False
        else:
            raise NonRecoverableError(
                'Value for disable_requiretty property should be true/false '
                'but is: {0}'.format(disable_requiretty_value))
    agent_config['disable_requiretty'] = disable_requiretty
    _prepare_and_validate_autoscale_params(ctx, agent_config)
Example #2
0
def create_celery_configuration(ctx, runner, agent_config, resource_loader):
    create_celery_includes_file(ctx, runner, agent_config)
    loader = jinja2.FunctionLoader(resource_loader)
    env = jinja2.Environment(loader=loader)
    config_template = env.get_template(
        CELERY_CONFIG_PATH.format(agent_config['distro']))
    config_template_values = {
        'includes_file_path':
        agent_config['includes_file'],
        'celery_base_dir':
        agent_config['celery_base_dir'],
        'worker_modifier':
        agent_config['name'],
        'management_ip':
        utils.get_manager_ip(),
        'broker_ip':
        '127.0.0.1'
        if is_on_management_worker(ctx) else utils.get_manager_ip(),
        'agent_ip':
        get_agent_ip(ctx, agent_config),
        'celery_user':
        agent_config['user'],
        'celery_group':
        agent_config['user'],
        'worker_autoscale':
        '{0},{1}'.format(agent_config['max_workers'],
                         agent_config['min_workers'])
    }

    ctx.logger.debug(
        'Populating celery config jinja2 template with the following '
        'values: {0}'.format(config_template_values))

    config = config_template.render(config_template_values)
    init_template = env.get_template(
        CELERY_INIT_PATH.format(agent_config['distro']))
    init_template_values = {
        'celery_base_dir': agent_config['celery_base_dir'],
        'worker_modifier': agent_config['name']
    }

    ctx.logger.debug(
        'Populating celery init.d jinja2 template with the following '
        'values: {0}'.format(init_template_values))

    init = init_template.render(init_template_values)

    ctx.logger.debug(
        'Creating celery config and init files [cloudify_agent={0}]'.format(
            agent_config))

    runner.put(agent_config['config_file'], config, use_sudo=True)
    runner.put(agent_config['init_file'], init, use_sudo=True)
Example #3
0
def prepare_configuration(ctx, agent_config):
    if is_on_management_worker(ctx):
        # we are starting a worker dedicated for a deployment
        # (not specific node)
        # use the same user we used when bootstrapping
        if 'MANAGEMENT_USER' in os.environ:
            agent_config['user'] = os.environ['MANAGEMENT_USER']
        else:
            raise NonRecoverableError(
                'Cannot determine user for deployment user:'******'MANAGEMENT_USER is not set')
        workflows_worker = agent_config['workflows_worker']\
            if 'workflows_worker' in agent_config else False
        suffix = '_workflows' if workflows_worker else ''
        name = '{0}{1}'.format(ctx.deployment_id, suffix)
        agent_config['name'] = name
    else:
        agent_config['host'] = get_machine_ip(ctx)
        _set_ssh_key(ctx, agent_config)
        _set_user(ctx, agent_config)
        _set_remote_execution_port(ctx, agent_config)
        agent_config['name'] = ctx.node_id

    _set_wait_started_config(agent_config)

    home_dir = pwd.getpwnam(agent_config['user']).pw_dir

    agent_config['celery_base_dir'] = home_dir

    agent_config['base_dir'] = '{0}/cloudify.{1}'.format(
        home_dir, agent_config['name'])
    agent_config['init_file'] = '/etc/init.d/celeryd-{0}'.format(
        agent_config['name'])
    agent_config['config_file'] = '/etc/default/celeryd-{0}'.format(
        agent_config['name'])
    agent_config['includes_file'] = '{0}/work/celeryd-includes'.format(
        agent_config['base_dir'])

    disable_requiretty = True
    if 'disable_requiretty' in agent_config:
        disable_requiretty_value = str(
            agent_config['disable_requiretty']).lower()
        if disable_requiretty_value.lower() == 'true':
            disable_requiretty = True
        elif disable_requiretty_value.lower() == 'false':
            disable_requiretty = False
        else:
            raise NonRecoverableError(
                'Value for disable_requiretty property should be true/false '
                'but is: {0}'.format(disable_requiretty_value))
    agent_config['disable_requiretty'] = disable_requiretty
    _prepare_and_validate_autoscale_params(ctx, agent_config)
Example #4
0
def create_celery_configuration(ctx, runner, agent_config, resource_loader):
    create_celery_includes_file(ctx, runner, agent_config)
    loader = jinja2.FunctionLoader(resource_loader)
    env = jinja2.Environment(loader=loader)
    config_template_path = get_agent_resource_local_path(
        ctx, agent_config, 'celery_config_path')
    config_template = env.get_template(config_template_path)
    config_template_values = {
        'includes_file_path': agent_config['includes_file'],
        'celery_base_dir': agent_config['celery_base_dir'],
        'worker_modifier': agent_config['name'],
        'management_ip': utils.get_manager_ip(),
        'broker_ip': '127.0.0.1' if is_on_management_worker(ctx)
        else utils.get_manager_ip(),
        'agent_ip': get_agent_ip(ctx, agent_config),
        'celery_user': agent_config['user'],
        'celery_group': agent_config['user'],
        'worker_autoscale': '{0},{1}'.format(agent_config['max_workers'],
                                             agent_config['min_workers'])
    }

    ctx.logger.debug(
        'Populating celery config jinja2 template with the following '
        'values: {0}'.format(config_template_values))

    config = config_template.render(config_template_values)
    init_template_path = get_agent_resource_local_path(
        ctx, agent_config, 'celery_init_path')
    init_template = env.get_template(init_template_path)
    init_template_values = {
        'celery_base_dir': agent_config['celery_base_dir'],
        'worker_modifier': agent_config['name']
    }

    ctx.logger.debug(
        'Populating celery init.d jinja2 template with the following '
        'values: {0}'.format(init_template_values))

    init = init_template.render(init_template_values)

    ctx.logger.debug(
        'Creating celery config and init files [cloudify_agent={0}]'.format(
            agent_config))

    runner.put(agent_config['config_file'], config, use_sudo=True)
    runner.put(agent_config['init_file'], init, use_sudo=True)
Example #5
0
def prepare_connection_configuration(ctx, agent_config):
    if is_on_management_worker(ctx):
        # we are starting a worker dedicated for a deployment
        # (not specific node)
        # use the same user we used when bootstrapping
        if 'MANAGEMENT_USER' in os.environ:
            agent_config['user'] = os.environ['MANAGEMENT_USER']
        else:
            raise NonRecoverableError(
                'Cannot determine user for deployment user:'******'MANAGEMENT_USER is not set')
        workflows_worker = agent_config['workflows_worker'] \
            if 'workflows_worker' in agent_config else False
        suffix = '_workflows' if workflows_worker else ''
        name = '{0}{1}'.format(ctx.deployment.id, suffix)
        agent_config['name'] = name
    else:
        agent_config['host'] = get_machine_ip(ctx)
        _set_auth(ctx, agent_config)
        _set_user(ctx, agent_config)
        _set_remote_execution_port(ctx, agent_config)
        agent_config['name'] = ctx.instance.id
def prepare_connection_configuration(ctx, agent_config):
    if is_on_management_worker(ctx):
        # we are starting a worker dedicated for a deployment
        # (not specific node)
        # use the same user we used when bootstrapping
        if 'MANAGEMENT_USER' in os.environ:
            agent_config['user'] = os.environ['MANAGEMENT_USER']
        else:
            raise NonRecoverableError(
                'Cannot determine user for deployment user:'******'MANAGEMENT_USER is not set')
        workflows_worker = agent_config['workflows_worker'] \
            if 'workflows_worker' in agent_config else False
        suffix = '_workflows' if workflows_worker else ''
        name = '{0}{1}'.format(ctx.deployment.id, suffix)
        agent_config['name'] = name
    else:
        agent_config['host'] = get_machine_ip(ctx)
        _set_auth(ctx, agent_config)
        _set_user(ctx, agent_config)
        _set_remote_execution_port(ctx, agent_config)
        agent_config['name'] = ctx.instance.id
Example #7
0
def get_agent_ip(ctx, agent_config):
    if is_on_management_worker(ctx):
        return utils.get_manager_ip()
    return agent_config['host']
Example #8
0
def get_agent_ip(ctx, agent_config):
    if is_on_management_worker(ctx):
        return utils.get_manager_ip()
    return agent_config['host']