コード例 #1
0
 def __init__(self, config, client=None):
     self.config = config
     if client is None:
         client = Client(auth=self.config['auth'],
                         endpoint_url=self.config['endpoint_url'])
     self.client = client
     self.ssh = SshKeyManager(client)
     self.instances = CCIManager(client)
コード例 #2
0
def global_search(search):
    client = get_client()
    match_string = '<span class="text-primary">%s</span>' % search

    term = re.compile(search, re.IGNORECASE)

    results = []

    if 'vm' in app.config['installed_blueprints']:
        cci = CCIManager(client)
        #        if hostname_regex.match(term):
        for vm in cci.list_instances():
            if term.match(vm['hostname']) or \
               term.match(vm.get('primaryIpAddress', '')):
                text = '%s (%s)' % (vm['fullyQualifiedDomainName'],
                                    vm.get('primaryIpAddress', 'No Public IP'))
                text = term.sub(match_string, text)

                results.append({
                    'label':
                    '<strong>VM:</strong> ' + text,
                    'value':
                    url_for('vm_module.view', vm_id=vm['id'])
                })
    if 'servers' in app.config['installed_blueprints']:
        hw = HardwareManager(client)

        for svr in hw.list_hardware():
            if term.match(svr['hostname']) or \
               term.match(svr.get('primaryIpAddress', '')):
                text = '%s (%s)' % (svr['fullyQualifiedDomainName'],
                                    svr.get('primaryIpAddress',
                                            'No Public IP'))
                text = term.sub(match_string, text)

                results.append({
                    'label':
                    '<strong>Server:</strong> ' + text,
                    'value':
                    url_for('server_module.view', server_id=svr['id'])
                })
    if 'sshkeys' in app.config['installed_blueprints']:
        ssh = SshKeyManager(client)

        for key in ssh.list_keys():
            if term.match(key['label']) or term.match(key['fingerprint']):
                text = '%s (%s)' % (key['label'], key['fingerprint'])
                text = term.sub(match_string, text)

                results.append({
                    'label':
                    '<strong>SSH Key:</strong> ' + text,
                    'value':
                    url_for('ssh_module.view', key_id=key['id'])
                })

    return results
コード例 #3
0
def get_sshkey_manager():
    return SshKeyManager(get_client())
コード例 #4
0
ファイル: servers.py プロジェクト: amol/jumpgate
    def on_post(self, req, resp, tenant_id):
        client = req.env['sl_client']
        body = json.loads(req.stream.read().decode())
        flavor_id = int(body['server'].get('flavorRef'))
        if flavor_id not in FLAVORS:
            return bad_request(resp, 'Flavor could not be found')

        flavor = FLAVORS[flavor_id]

        ssh_keys = []
        key_name = body['server'].get('key_name')
        if key_name:
            sshkey_mgr = SshKeyManager(client)
            keys = sshkey_mgr.list_keys(label=key_name)
            if len(keys) == 0:
                return bad_request(resp, 'KeyPair could not be found')
            ssh_keys.append(keys[0]['id'])

        private_network_only = False
        networks = lookup(body, 'server', 'networks')
        if networks:
            # Make sure they're valid networks
            if not all([
                    network['uuid'] in ['public', 'private'] in network
                    for network in networks
            ]):
                return bad_request(resp, message='Invalid network')

            # Find out if it's private only
            if not any([
                    network['uuid'] == 'public' in network
                    for network in networks
            ]):
                private_network_only = True

        user_data = {}
        if lookup(body, 'server', 'metadata'):
            user_data['metadata'] = lookup(body, 'server', 'metadata')
        if lookup(body, 'server', 'user_data'):
            user_data['user_data'] = lookup(body, 'server', 'user_data')
        if lookup(body, 'server', 'personality'):
            user_data['personality'] = lookup(body, 'server', 'personality')

        datacenter = None
        if lookup(body, 'server', 'availability_zone'):
            datacenter = lookup(body, 'server', 'availability_zone')

        cci = CCIManager(client)

        payload = {
            'hostname': body['server']['name'],
            'domain': 'jumpgate.com',  # TODO - Don't hardcode this
            'cpus': flavor['cpus'],
            'memory': flavor['ram'],
            'hourly': True,  # TODO - How do we set this accurately?
            'datacenter': datacenter,
            'image_id': body['server']['imageRef'],
            'ssh_keys': ssh_keys,
            'private': private_network_only,
            'userdata': json.dumps(user_data),
        }

        try:
            new_instance = cci.create_instance(**payload)
        except ValueError as e:
            return bad_request(resp, message=str(e))

        resp.set_header('x-compute-request-id', 'create')
        resp.status = 202
        resp.body = {
            'server': {
                'id':
                new_instance['id'],
                'links': [{
                    'href':
                    self.app.get_endpoint_url('compute',
                                              req,
                                              'v2_server',
                                              instance_id=new_instance['id']),
                    'rel':
                    'self'
                }],
                'adminPass':
                '',
            }
        }
コード例 #5
0
def listSSHKeys(label=None):
    sshManager = SshKeyManager(client)
    sshKeys = sshManager.list_keys(label=label)
    return sshKeys