def sync_partial(): cloud = env.cloud() file_roots = cloud.opts['file_roots']['base'][0] pillar_roots = cloud.opts['pillar_roots']['base'][0] manifest = Manifest() manifest.add('cloudseed/current/srv/salt', file_roots) manifest.add('cloudseed/current/srv/pillar', pillar_roots) manifest.add( 'cloudseed/current/salt/cloud.profiles', '/etc/salt/cloud.profiles') vm_ = cloud.vm_profile('master') alias, driver = cloud.lookup_providers(vm_['provider']) action = cloud.clouds.get( '%s.sync_partial_manifest' % driver, lambda x: None) action(manifest) tmp = tempfile.NamedTemporaryFile(delete=False) Archive.tar(tmp, manifest) _sync_partial_action(tmp.name, cloud)
def run(argv): data = cloudseed.agent.commands.status() cloud = env.cloud() cloud.opts["color"] = True display_output(data, out="nested", opts=cloud.opts)
def sync_full(): cloud = env.cloud() file_roots = cloud.opts['file_roots']['base'][0] pillar_roots = cloud.opts['pillar_roots']['base'][0] manifest = Manifest() manifest.add('cloudseed/current/srv/salt', file_roots) manifest.add('cloudseed/current/srv/pillar', pillar_roots) manifest.add('cloudseed/current/salt/cloud.profiles', '/etc/salt/cloud.profiles') # the cloud providers may need a rewrite (private_key path # if applicable, etc) and the salt-cloud conf will need to know # the master's IP for subsequent minions. Changes to salt-cloud # conf are fixed, the providers will vary by provider. manifest.add('cloudseed/current/salt/cloud.providers', '/etc/salt/cloud.providers') _add_saltcloud_conf(manifest, cloud) vm_ = cloud.vm_profile('master') alias, driver = cloud.lookup_providers(vm_['provider']) action = cloud.clouds.get('%s.sync_full_manifest' % driver, lambda x: None) action(manifest) tmp = tempfile.NamedTemporaryFile(delete=False) Archive.tar(tmp, manifest) _sync_full_action(tmp.name, cloud)
def run(argv): data = cloudseed.agent.commands.status() cloud = env.cloud() cloud.opts['color'] = True display_output(data, out='nested', opts=cloud.opts)
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)
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)
def action(*args, **kwargs): cloud = env.cloud() vm_ = cloud.vm_profile('master') ip_address = cloud.opts['cloudseed']['ip_address'] private_key = config.get_config_value('private_key', vm_, cloud.opts) username = config.get_config_value('ssh_username', vm_, cloud.opts) password = config.get_config_value('password', vm_, cloud.opts) socket = ssh.agent_zmq_tunnel(socket_type=zmq.REQ, host=ip_address, port='5556', private_key=private_key, username=username, password=password) socket.send_json(fun(*args, **kwargs)) response = socket.recv_json() if 'data' in response: return response['data']
def action(*args, **kwargs): cloud = env.cloud() vm_ = cloud.vm_profile('master') ip_address = cloud.opts['cloudseed']['ip_address'] private_key = config.get_config_value('private_key', vm_, cloud.opts) username = config.get_config_value('ssh_username', vm_, cloud.opts) password = config.get_config_value('password', vm_, cloud.opts) socket = ssh.agent_zmq_tunnel( socket_type=zmq.REQ, host=ip_address, port='5556', private_key=private_key, username=username, password=password) socket.send_json(fun(*args, **kwargs)) response = socket.recv_json() if 'data' in response: return response['data']
def sync_full(): cloud = env.cloud() file_roots = cloud.opts['file_roots']['base'][0] pillar_roots = cloud.opts['pillar_roots']['base'][0] manifest = Manifest() manifest.add('cloudseed/current/srv/salt', file_roots) manifest.add('cloudseed/current/srv/pillar', pillar_roots) manifest.add( 'cloudseed/current/salt/cloud.profiles', '/etc/salt/cloud.profiles') # the cloud providers may need a rewrite (private_key path # if applicable, etc) and the salt-cloud conf will need to know # the master's IP for subsequent minions. Changes to salt-cloud # conf are fixed, the providers will vary by provider. manifest.add( 'cloudseed/current/salt/cloud.providers', '/etc/salt/cloud.providers') _add_saltcloud_conf(manifest, cloud) vm_ = cloud.vm_profile('master') alias, driver = cloud.lookup_providers(vm_['provider']) action = cloud.clouds.get( '%s.sync_full_manifest' % driver, lambda x: None) action(manifest) tmp = tempfile.NamedTemporaryFile(delete=False) Archive.tar(tmp, manifest) _sync_full_action(tmp.name, cloud)
def sync_partial(): cloud = env.cloud() file_roots = cloud.opts['file_roots']['base'][0] pillar_roots = cloud.opts['pillar_roots']['base'][0] manifest = Manifest() manifest.add('cloudseed/current/srv/salt', file_roots) manifest.add('cloudseed/current/srv/pillar', pillar_roots) manifest.add('cloudseed/current/salt/cloud.profiles', '/etc/salt/cloud.profiles') vm_ = cloud.vm_profile('master') alias, driver = cloud.lookup_providers(vm_['provider']) action = cloud.clouds.get('%s.sync_partial_manifest' % driver, lambda x: None) action(manifest) tmp = tempfile.NamedTemporaryFile(delete=False) Archive.tar(tmp, manifest) _sync_partial_action(tmp.name, cloud)
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)