Пример #1
0
def _master_data(config):

    profiles = config.profile
    providers = _providers_for_config(config)
    config_obj = config.data.copy()
    config_obj['master'] = 'localhost'

    ssh_keys_data = _ssh_keys_for_providers(providers)
    profiles_data = Filesystem.encode(profiles)
    providers_data = Filesystem.encode(providers)

    config_data = Filesystem.encode(config_obj)

    project = config.data['project']
    master_project_path = os.path.join(
        Filesystem.project_path(project),
        'master'
    )

    master_env_path = os.path.join(
        Filesystem.current_env(),
        'master'
    )

    master = Filesystem.encode(config.master_config_data(
        files=[master_project_path, master_env_path]))

    minion = Filesystem.encode(config.minion_config_data({
        'id': 'master',
        'master': 'localhost',
        'grains': {'roles': ['master']}
        }))

    salt_data = {
    'master': master,
    'minion': minion}

    cloudseed_data = {
    'profiles': profiles_data,
    'providers': providers_data,
    'config': config_data,
    'ssh_keys': ssh_keys_data}

    return {
    'salt': salt_data,
    'cloudseed': cloudseed_data
    }
Пример #2
0
def run(config, argv):
    args = docopt(__doc__, argv=argv)

    profile_name = args['--profile-name']
    state = args['--state']

    data = {'salt': {}}

    master = config.master_config_data(files=['/etc/salt/master'])

    instance_name = instances.instance_name_for_state(state, config)
    instance_id = instance_name.rsplit('-')[-1]
    minion_id = '{0}{1}'.format(state, instance_id)

    pem, pub = salt.gen_keys()

    client = LocalClient()
    grains = client.cmd('master', 'grains.item', ['fqdn'])

    try:
        master_fqdn = grains['master']['fqdn']
    except KeyError:
        return

    minion_data = {
    'master': master_fqdn,
    'id': minion_id
    }

    profile = config.profile_for_key(profile_name)
    minion_data.update(profile.get('minion', {}))

    data['salt']['minion_pub'] = pub
    data['salt']['minion_pem'] = pem
    data['salt']['minion'] = Filesystem.encode(
        config.minion_config_data(minion_data))

    salt.accept_key(master['pki_dir'], pub, minion_id)

    instances.create_instance(
        config=config,
        profile_name=profile_name,
        state=state,
        data=data,
        instance_name=instance_name)