Exemple #1
0
def sync_key(key_name, client=None):
    if not client:
        cloud = env.cloud()
        client = ssh.master_client(cloud)

    ssh.sudo(
            client,
            'salt \'*\' ssh.set_auth_key_from_file ubuntu salt://keys/%s' % \
            key_name)
Exemple #2
0
def highstate(minion_id=None, grain=None):

    cloud = env.cloud()
    client = ssh.master_client(cloud)

    if minion_id:
        ssh.sudo(client, 'salt \'%s\' state.highstate' % minion_id)
    elif grain:
        ssh.sudo(client, 'salt -G \'%s\' state.highstate' % grain)
Exemple #3
0
def sync_key(key_name, client=None):
    if not client:
        cloud = env.cloud()
        client = ssh.master_client(cloud)

    ssh.sudo(
            client,
            'salt \'*\' ssh.set_auth_key_from_file ubuntu salt://keys/%s' % \
            key_name)
Exemple #4
0
def highstate(minion_id=None, grain=None):

    cloud = env.cloud()
    client = ssh.master_client(cloud)

    if minion_id:
        ssh.sudo(client, 'salt \'%s\' state.highstate' % minion_id)
    elif grain:
        ssh.sudo(client, 'salt -G \'%s\' state.highstate' % grain)
Exemple #5
0
def _sync_partial_action(filename, cloud):
    ssh_client = ssh.master_client(cloud)
    sudo = functools.partial(ssh.sudo, ssh_client)
    run = functools.partial(ssh.run, ssh_client)

    vm_ = cloud.vm_profile('master')
    alias, driver = cloud.lookup_providers(vm_['provider'])

    _sync_action(filename, cloud, run, sudo)

    sudo('chmod 600 /etc/salt/cloud.profiles')

    provider_action = cloud.clouds.get('%s.sync_full_action' % driver,
                                       lambda x, y: None)

    provider_action(run, sudo)
Exemple #6
0
def _sync_partial_action(filename, cloud):
    ssh_client = ssh.master_client(cloud)
    sudo = functools.partial(ssh.sudo, ssh_client)
    run = functools.partial(ssh.run, ssh_client)

    vm_ = cloud.vm_profile('master')
    alias, driver = cloud.lookup_providers(vm_['provider'])

    _sync_action(filename, cloud, run, sudo)

    sudo('chmod 600 /etc/salt/cloud.profiles')

    provider_action = cloud.clouds.get(
        '%s.sync_full_action' % driver,
        lambda x, y: None)

    provider_action(run, sudo)
Exemple #7
0
def _add_key():
    user_path = os.path.expanduser('~/.ssh')
    files = glob.glob(os.path.join(user_path, 'id_rsa.pub'))

    if len(files) < 1:
        # TODO ERROR MESSAGES
        return

    target = files[0]
    log.debug('Transferring public key \'%s\' to master', target)
    cloud = env.cloud()

    with open(target, 'rb') as f:
        key_name = hashlib.md5(f.read()).hexdigest()

    sync_file(target, '/tmp/%s' % key_name, cloud)

    client = ssh.master_client(cloud)
    ssh.sudo(
        client,
        'mv /tmp/%s /srv/cloudseed/keys && chmod 600 /srv/cloudseed/keys/%s' % \
        (key_name, key_name))

    salt.sync_key(key_name, client=client)