Пример #1
0
 def fake_fixed_ip_update(context, address, values):
     fixed_ip = fake_fixed_ip_get_by_address(context, address)
     if fixed_ip is None:
         raise exception.FixedIpNotFoundForAddress(address=address)
     else:
         for key in values:
             fixed_ip[key] = values[key]
Пример #2
0
 def fake_fixed_ip_get_by_address(context,
                                  address,
                                  columns_to_join=None):
     for fixed_ip in fake_fixed_ips:
         if fixed_ip['address'] == address:
             return fixed_ip
     raise exception.FixedIpNotFoundForAddress(address=address)
Пример #3
0
 def fake_fixed_ip_get_by_address_detailed(context, address):
     network = {'id': 1, 'cidr': "192.168.1.0/24"}
     host = {'host': "host", 'hostname': 'openstack'}
     for fixed_ip in fake_fixed_ips:
         if fixed_ip['address'] == address:
             return (fixed_ip, network, host)
     raise exception.FixedIpNotFoundForAddress(address=address)
Пример #4
0
def fake_fixed_ip_get_by_address_detailed(context, address):
    network = {'id': 1,
               'cidr': "192.168.1.0/24"}
    for fixed_ip in fake_fixed_ips:
        if fixed_ip['address'] == address and not fixed_ip['deleted']:
            return (fixed_ip, FakeModel(network), None)
    raise exception.FixedIpNotFoundForAddress(address=address)
Пример #5
0
def fake_fixed_ip_get_by_address(context, address, columns_to_join=None):
    if address == 'inv.ali.d.ip':
        msg = "Invalid fixed IP Address %s in request" % address
        raise exception.FixedIpInvalid(msg)
    for fixed_ip in fake_fixed_ips:
        if fixed_ip['address'] == address and not fixed_ip['deleted']:
            return fixed_ip
    raise exception.FixedIpNotFoundForAddress(address=address)
Пример #6
0
 def get_fixed_ip_by_address(self, context, address):
     uuid_maps = self._get_instance_uuids_by_ip(context, address)
     if len(uuid_maps) == 1:
         return uuid_maps[0]
     elif not uuid_maps:
         raise exception.FixedIpNotFoundForAddress(address=address)
     else:
         raise exception.FixedIpAssociatedWithMultipleInstances(
             address=address)
Пример #7
0
 def _get_port_id_by_fixed_address(self, client, instance, address):
     zone = 'compute:%s' % CONF.node_availability_zone
     search_opts = {'device_id': instance['uuid'], 'device_owner': zone}
     data = client.list_ports(**search_opts)
     ports = data['ports']
     port_id = None
     for p in ports:
         for ip in p['fixed_ips']:
             if ip['ip_address'] == address:
                 port_id = p['id']
                 break
     if not port_id:
         raise exception.FixedIpNotFoundForAddress(address=address)
     return port_id
Пример #8
0
    def get_metadata_by_remote_address(self, address):
        if not address:
            raise exception.FixedIpNotFoundForAddress(address=address)

        cache_key = 'metadata-%s' % address
        data = self._cache.get(cache_key)
        if data:
            return data

        try:
            data = base.get_metadata_by_address(self.conductor_api, address)
        except exception.NotFound:
            return None

        self._cache.set(cache_key, data, CACHE_EXPIRATION)

        return data
Пример #9
0
    def get_metadata(self, address):
        if not address:
            raise exception.FixedIpNotFoundForAddress(address=address)

        cache_key = 'metadata-%s' % address
        data = self._cache.get(cache_key)
        if data:
            return data

        try:
            data = base.get_metadata_by_address(address)
        except exception.NotFound:
            return None

        self._cache.set(cache_key, data, 15)

        return data
Пример #10
0
    def get_metadata_by_remote_address(self, address):
        if not address:
            raise exception.FixedIpNotFoundForAddress(address=address)

        cache_key = 'metadata-%s' % address
        data = self._cache.get(cache_key)
        if data:
            LOG.debug("Using cached metadata for %s", address)
            return data

        try:
            data = base.get_metadata_by_address(address)
        except exception.NotFound:
            return None

        if CONF.metadata_cache_expiration > 0:
            self._cache.set(cache_key, data, CONF.metadata_cache_expiration)

        return data
Пример #11
0
def fake_fixed_ip_get_by_address(context, address):
    for fixed_ip in fake_fixed_ips:
        if fixed_ip['address'] == address and not fixed_ip['deleted']:
            return fixed_ip
    raise exception.FixedIpNotFoundForAddress(address=address)
    def get_metadata(self, address):
        if not address:
            raise exception.FixedIpNotFoundForAddress(address=address)

        cache_key = 'metadata-%s' % address
        data = self._cache.get(cache_key)
        if data:
            return data

        ctxt = context.get_admin_context()
        try:
            fixed_ip = self.network_api.get_fixed_ip_by_address(ctxt, address)
            instance_ref = db.instance_get(ctxt, fixed_ip['instance_id'])
        except exception.NotFound:
            return None

        hostname = "%s.%s" % (instance_ref['hostname'], FLAGS.dhcp_domain)
        host = instance_ref['host']
        services = db.service_get_all_by_host(ctxt.elevated(), host)
        availability_zone = ec2utils.get_availability_zone_by_host(
            services, host)

        ip_info = ec2utils.get_ip_info_for_instance(ctxt, instance_ref)
        floating_ips = ip_info['floating_ips']
        floating_ip = floating_ips and floating_ips[0] or ''

        ec2_id = ec2utils.id_to_ec2_id(instance_ref['id'])
        image_id = instance_ref['image_ref']
        ctxt = context.get_admin_context()
        image_ec2_id = ec2utils.glance_id_to_ec2_id(ctxt, image_id)
        security_groups = db.security_group_get_by_instance(
            ctxt, instance_ref['id'])
        security_groups = [x['name'] for x in security_groups]
        mappings = self._format_instance_mapping(ctxt, instance_ref)
        data = {
            'user-data': base64.b64decode(instance_ref['user_data']),
            'meta-data': {
                'ami-id': image_ec2_id,
                'ami-launch-index': instance_ref['launch_index'],
                'ami-manifest-path': 'FIXME',
                'block-device-mapping': mappings,
                'hostname': hostname,
                'instance-action': 'none',
                'instance-id': ec2_id,
                'instance-type': instance_ref['instance_type']['name'],
                'local-hostname': hostname,
                'local-ipv4': address,
                'placement': {
                    'availability-zone': availability_zone
                },
                'public-hostname': hostname,
                'public-ipv4': floating_ip,
                'reservation-id': instance_ref['reservation_id'],
                'security-groups': security_groups
            }
        }

        # public-keys should be in meta-data only if user specified one
        if instance_ref['key_name']:
            data['meta-data']['public-keys'] = {
                '0': {
                    '_name': instance_ref['key_name'],
                    'openssh-key': instance_ref['key_data']
                }
            }

        for image_type in ['kernel', 'ramdisk']:
            if instance_ref.get('%s_id' % image_type):
                image_id = instance_ref['%s_id' % image_type]
                image_type = ec2utils.image_type(image_type)
                ec2_id = ec2utils.glance_id_to_ec2_id(ctxt, image_id,
                                                      image_type)
                data['meta-data']['%s-id' % image_type] = ec2_id

        if False:  # TODO(vish): store ancestor ids
            data['ancestor-ami-ids'] = []
        if False:  # TODO(vish): store product codes
            data['product-codes'] = []

        self._cache.set(cache_key, data, 15)

        return data