Example #1
0
def sync_full_manifest(manifest):
    cloud = cloudseed.cloud.Cloud(__opts__)
    vm_ = cloud.vm_profile('master')

    keyname = '%s-%s' % (env.location_name(), env.env_name())

    filename = os.path.join(env.current_env_path(), 'salt', '%s.pem' % keyname)

    manifest.add(filename, '/etc/salt/cloud.pem')

    # changing the path to the private_key file to work on
    # the bootstrapped master
    providers = filesystem.read_file(__opts__['providers_config'])

    providers_data = yaml.load(providers)
    alias, driver = vm_['provider'].split(':')
    master_provider = providers_data[alias]

    master_provider['private_key'] = '/etc/salt/cloud.pem'
    cloud_providers = yaml.safe_dump(providers_data, default_flow_style=False)

    manifest.remove('cloudseed/current/salt/cloud.providers')

    manifest.add(writers.write_stringio(cloud_providers),
                 '/etc/salt/cloud.providers')
Example #2
0
def sync_full_manifest(manifest):
    cloud = cloudseed.cloud.Cloud(__opts__)
    vm_ = cloud.vm_profile('master')

    keyname = '%s-%s' % (env.location_name(), env.env_name())

    filename = os.path.join(
        env.current_env_path(),
        'salt',
        '%s.pem' % keyname)

    manifest.add(filename, '/etc/salt/cloud.pem')

    # changing the path to the private_key file to work on
    # the bootstrapped master
    providers = filesystem.read_file(__opts__['providers_config'])

    providers_data = yaml.load(providers)
    alias, driver = vm_['provider'].split(':')
    master_provider = providers_data[alias]

    master_provider['private_key'] = '/etc/salt/cloud.pem'
    cloud_providers = yaml.safe_dump(providers_data, default_flow_style=False)

    manifest.remove('cloudseed/current/salt/cloud.providers')

    manifest.add(
        writers.write_stringio(cloud_providers),
        '/etc/salt/cloud.providers')
Example #3
0
def run(argv):
    prefix = os.path.join(env.current_env_path(), 'salt')

    cs_saltcloud.destroy(
        cloud_config=os.path.join(prefix, 'cloud'),
        cloud_providers=os.path.join(prefix, 'cloud.providers'),
        cloud_profiles=os.path.join(prefix, 'cloud.profiles'),
        master_config=os.path.join(prefix, 'master'))
Example #4
0
def run(argv):
    prefix = os.path.join(env.current_env_path(), 'salt')

    cs_saltcloud.destroy(cloud_config=os.path.join(prefix, 'cloud'),
                         cloud_providers=os.path.join(prefix,
                                                      'cloud.providers'),
                         cloud_profiles=os.path.join(prefix, 'cloud.profiles'),
                         master_config=os.path.join(prefix, 'master'))
def run(argv):
    tag = 'cloudseed-%s-%s-master' % (env.location_name(), env.env_name())
    prefix = os.path.join(env.current_env_path(), 'salt')

    saltcloud.execute_profile(
        'master',
        tag=tag,
        cloud_config=os.path.join(prefix, 'cloud'),
        cloud_providers=os.path.join(prefix, 'cloud.providers'),
        cloud_profiles=os.path.join(prefix, 'cloud.profiles'),
        master_config=os.path.join(prefix, 'master'))
Example #6
0
def run(argv):
    tag = "cloudseed-%s-%s-master" % (env.location_name(), env.env_name())
    prefix = os.path.join(env.current_env_path(), "salt")

    saltcloud.execute_profile(
        "master",
        tag=tag,
        cloud_config=os.path.join(prefix, "cloud"),
        cloud_providers=os.path.join(prefix, "cloud.providers"),
        cloud_profiles=os.path.join(prefix, "cloud.profiles"),
        master_config=os.path.join(prefix, "master"),
    )
Example #7
0
def create_master(vm_=None, call=None):
    # always assumes we are running locally, creating a
    # master for the 1st time
    cloud = cloudseed.cloud.Cloud(__opts__)
    bootstrap_master(vm_, cloud)

    master = filesystem.read_file(__opts__['master_config'])

    vm_['cloudseed'] = {
        'master': master
    }

    data = saltcloud_ec2_create(vm_)
    log.debug('VM: %s', vm_)
    log.debug('VM Created: %s', data)

    if 'Errors' in data:
        message = data['Errors']['Error']['Message']
        log.error('%s', message)
        return

    conf = {
    'ip_address': data['ipAddress'],
    'dns_name': data['dnsName'],
    'private_ip_address': data['privateIpAddress'],
    'instance_id': data['instanceId'],
    'profile': vm_.get('profile', None),
    'name': vm_['name'],
    }

    conf_filename = os.path.join(env.current_env_path(), 'salt', 'cloudseed')

    with open(conf_filename, 'w') as f:
        f.write(yaml.safe_dump(conf, default_flow_style=False))

    sync.sync_full()
    salt.master_salt_call_highstate()

    event = {
    'fun': 'create.master',
    'return': conf
    }

    # assumes being run locally
    cloudseed.agent.commands.fire_event(event)

    return data
Example #8
0
def create_master(vm_=None, call=None):
    # always assumes we are running locally, creating a
    # master for the 1st time
    cloud = cloudseed.cloud.Cloud(__opts__)
    bootstrap_master(vm_, cloud)

    master = filesystem.read_file(__opts__['master_config'])

    vm_['cloudseed'] = {'master': master}

    data = saltcloud_ec2_create(vm_)
    log.debug('VM: %s', vm_)
    log.debug('VM Created: %s', data)

    if 'Errors' in data:
        message = data['Errors']['Error']['Message']
        log.error('%s', message)
        return

    conf = {
        'ip_address': data['ipAddress'],
        'dns_name': data['dnsName'],
        'private_ip_address': data['privateIpAddress'],
        'instance_id': data['instanceId'],
        'profile': vm_.get('profile', None),
        'name': vm_['name'],
    }

    conf_filename = os.path.join(env.current_env_path(), 'salt', 'cloudseed')

    with open(conf_filename, 'w') as f:
        f.write(yaml.safe_dump(conf, default_flow_style=False))

    sync.sync_full()
    salt.master_salt_call_highstate()

    event = {'fun': 'create.master', 'return': conf}

    # assumes being run locally
    cloudseed.agent.commands.fire_event(event)

    return data
Example #9
0
def bootstrap_master(vm_, cloud):
    provider = cloud.provider_profile_full(vm_)

    provider['ssh_interface'] = 'public_ips'
    append_data = {}

    if not provider.get('keyname', False):
        keyname = '%s-%s' % (env.location_name(), env.env_name())

        filename = os.path.join(
            env.current_env_path(),
            'salt',
            '%s.pem' % keyname)

        bootstrap_create_keypair(keyname, filename)

        # set it for the current command
        provider['keyname'] = keyname
        provider['private_key'] = filename

        append_data['keyname'] = keyname
        append_data['private_key'] = 'cloudseed/current/salt/%s.pem' % keyname

    else:
        if not os.path.isabs(provider['private_key']):
            new_path = os.path.abspath(provider['private_key'])
            provider['private_key'] = new_path

    groups = bootstrap_master_security_groups(vm_, provider)
    append_data['securitygroup'] = groups

    # write down and new data
    if append_data:
        provider_bytes = filesystem.read_file(cloud.opts['providers_config'])
        provider_data = yaml.load(provider_bytes)
        alias, driver = vm_['provider'].split(':')

        target = provider_data[alias]
        target.update(append_data)
        writers.write_yaml(cloud.opts['providers_config'], provider_data)
Example #10
0
def bootstrap_master(vm_, cloud):
    provider = cloud.provider_profile_full(vm_)

    provider['ssh_interface'] = 'public_ips'
    append_data = {}

    if not provider.get('keyname', False):
        keyname = '%s-%s' % (env.location_name(), env.env_name())

        filename = os.path.join(env.current_env_path(), 'salt',
                                '%s.pem' % keyname)

        bootstrap_create_keypair(keyname, filename)

        # set it for the current command
        provider['keyname'] = keyname
        provider['private_key'] = filename

        append_data['keyname'] = keyname
        append_data['private_key'] = 'cloudseed/current/salt/%s.pem' % keyname

    else:
        if not os.path.isabs(provider['private_key']):
            new_path = os.path.abspath(provider['private_key'])
            provider['private_key'] = new_path

    groups = bootstrap_master_security_groups(vm_, provider)
    append_data['securitygroup'] = groups

    # write down and new data
    if append_data:
        provider_bytes = filesystem.read_file(cloud.opts['providers_config'])
        provider_data = yaml.load(provider_bytes)
        alias, driver = vm_['provider'].split(':')

        target = provider_data[alias]
        target.update(append_data)
        writers.write_yaml(cloud.opts['providers_config'], provider_data)
Example #11
0
def run(argv):
    args = docopt(__doc__, argv=argv)

    # TODO We can capture all this loading and error handling
    # in 1 function
    try:
        with open('cloudseed/current/salt/cloud.profiles') as f:
            profiles = yaml.load(f.read())
    except IOError:
        print('No Cloud Profiles Found')
        return

    try:
        with open('cloudseed/current/salt/cloud.providers') as f:
            providers = yaml.load(f.read())
    except IOError:
        print('No Cloud Providers Found')
        return

    try:
        with open('cloudseed/current/salt/cloudseed') as f:
            conf = yaml.load(f.read())
    except IOError:
        print('Have you bootstrapped?')
        return

    profile = profiles.get('master', None)

    if not profile:
        # TODO Add Error Messaging
        return

    prefix = os.path.join(env.current_env_path(), 'salt')
    cloud_config = os.path.join(prefix, 'cloud')
    cloud_providers = os.path.join(prefix, 'cloud.providers')
    cloud_profiles = os.path.join(prefix, 'cloud.profiles')
    master_config = os.path.join(prefix, 'master')

    cloudseed_args = [
        '--cloud-config', cloud_config, '--providers-config', cloud_providers,
        '--profiles', cloud_profiles, '--master-config', master_config
    ]

    cli = saltcloud.cli.SaltCloud()
    cli.parse_args(args=cloudseed_args)

    cloud = cloudseed.cloud.Cloud(cli.config)
    vm_ = cloud.vm_profile('master')

    provider = config.get_config_value('provider', vm_, cloud.opts)

    if not provider:
        # TODO Add Error Messaging
        return

    username = config.get_config_value('ssh_username', vm_, cloud.opts)
    identity = config.get_config_value('private_key', vm_, cloud.opts)
    host = conf.get('ip_address', False)

    if username and identity and host:
        identity = os.path.abspath(identity)
        #sys.stdout.write('Connecting to environment \'%s\'\n' % current_env)
        ssh.connect(host=host, username=username, identity=identity)
Example #12
0
def run(argv):
    args = docopt(__doc__, argv=argv)

    # TODO We can capture all this loading and error handling
    # in 1 function
    try:
        with open('cloudseed/current/salt/cloud.profiles') as f:
            profiles = yaml.load(f.read())
    except IOError:
        print('No Cloud Profiles Found')
        return

    try:
        with open('cloudseed/current/salt/cloud.providers') as f:
            providers = yaml.load(f.read())
    except IOError:
        print('No Cloud Providers Found')
        return

    try:
        with open('cloudseed/current/salt/cloudseed') as f:
            conf = yaml.load(f.read())
    except IOError:
        print('Have you bootstrapped?')
        return

    profile = profiles.get('master', None)

    if not profile:
        # TODO Add Error Messaging
        return

    prefix = os.path.join(env.current_env_path(), 'salt')
    cloud_config = os.path.join(prefix, 'cloud')
    cloud_providers = os.path.join(prefix, 'cloud.providers')
    cloud_profiles = os.path.join(prefix, 'cloud.profiles')
    master_config = os.path.join(prefix, 'master')

    cloudseed_args = [
    '--cloud-config', cloud_config,
    '--providers-config', cloud_providers,
    '--profiles', cloud_profiles,
    '--master-config', master_config]

    cli = saltcloud.cli.SaltCloud()
    cli.parse_args(args=cloudseed_args)

    cloud = cloudseed.cloud.Cloud(cli.config)
    vm_ = cloud.vm_profile('master')

    provider = config.get_config_value(
        'provider',
        vm_,
        cloud.opts)

    if not provider:
        # TODO Add Error Messaging
        return

    username = config.get_config_value('ssh_username', vm_, cloud.opts)
    identity = config.get_config_value('private_key', vm_, cloud.opts)
    host = conf.get('ip_address', False)

    if username and identity and host:
        identity = os.path.abspath(identity)
        #sys.stdout.write('Connecting to environment \'%s\'\n' % current_env)
        ssh.connect(
            host=host,
            username=username,
            identity=identity)