def ip6_dict(): return { 'ip': ipv6.to_global(network['cidr_v6'], vif['address'], network['project_id']), 'netmask': network['netmask_v6'], 'enabled': '1'}
def ip6_dict(): return { "ip": ipv6.to_global(network['cidr_v6'], vif['address'], network['project_id']), "netmask": network['netmask_v6'], "enabled": "1"}
def get_ip_info_for_instance(context, instance): """Return a list of all fixed IPs for an instance""" ip_info = dict(fixed_ips=[], fixed_ip6s=[], floating_ips=[]) fixed_ips = instance['fixed_ips'] for fixed_ip in fixed_ips: fixed_addr = fixed_ip['address'] network = fixed_ip.get('network') vif = fixed_ip.get('virtual_interface') if not network or not vif: name = instance['name'] ip = fixed_ip['address'] LOG.warn( _("Instance %(name)s has stale IP " "address: %(ip)s (no network or vif)") % locals()) continue cidr_v6 = network.get('cidr_v6') if FLAGS.use_ipv6 and cidr_v6: ipv6_addr = ipv6.to_global(cidr_v6, vif['address'], network['project_id']) if ipv6_addr not in ip_info['fixed_ip6s']: ip_info['fixed_ip6s'].append(ipv6_addr) for floating_ip in fixed_ip.get('floating_ips', []): float_addr = floating_ip['address'] ip_info['floating_ips'].append(float_addr) ip_info['fixed_ips'].append(fixed_addr) return ip_info
def get_ip_info_for_instance(context, instance): """Return a list of all fixed IPs for an instance""" ip_info = dict(fixed_ips=[], fixed_ip6s=[], floating_ips=[]) fixed_ips = instance['fixed_ips'] for fixed_ip in fixed_ips: fixed_addr = fixed_ip['address'] network = fixed_ip.get('network') vif = fixed_ip.get('virtual_interface') if not network or not vif: name = instance['name'] ip = fixed_ip['address'] LOG.warn(_("Instance %(name)s has stale IP " "address: %(ip)s (no network or vif)") % locals()) continue cidr_v6 = network.get('cidr_v6') if FLAGS.use_ipv6 and cidr_v6: ipv6_addr = ipv6.to_global(cidr_v6, vif['address'], network['project_id']) if ipv6_addr not in ip_info['fixed_ip6s']: ip_info['fixed_ip6s'].append(ipv6_addr) for floating_ip in fixed_ip.get('floating_ips', []): float_addr = floating_ip['address'] ip_info['floating_ips'].append(float_addr) ip_info['fixed_ips'].append(fixed_addr) return ip_info
def ip6_dict(): prefix = network['cidr_v6'] mac = vif['address'] project_id = instance['project_id'] return { 'ip': ipv6.to_global(prefix, mac, project_id), 'netmask': network['netmask_v6'], 'enabled': '1'}
def ip6_dict(): prefix = network['cidr_v6'] mac = vif['address'] project_id = instance['project_id'] return { 'ip': ipv6.to_global(prefix, mac, project_id), 'netmask': network['netmask_v6'], 'enabled': '1' }
def fixed_ipv6(self): cidr_v6 = self.network.cidr_v6 if cidr_v6 is None: ipv6_address = None else: project_id = self.instance.project_id mac = self.address ipv6_address = ipv6.to_global(cidr_v6, mac, project_id) return ipv6_address
def get_v6_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list containing a single IPv6 address strings associated with the specified virtual interface. """ admin_context = context.elevated() network = objects.Network.get_by_uuid(admin_context, net_id) vif_rec = objects.VirtualInterface.get_by_uuid(context, vif_id) if network.cidr_v6 and vif_rec and vif_rec.address: ip = ipv6.to_global(network.cidr_v6, vif_rec.address, project_id) return [ip] return []
def get_v6_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list containing a single IPv6 address strings associated with the specified virtual interface. """ admin_context = context.elevated() network = db.network_get_by_uuid(admin_context, net_id) vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) if network["cidr_v6"]: ip = ipv6.to_global(network["cidr_v6"], vif_rec["address"], project_id) return [ip] return []
def get_v6_ips_by_interface(self, context, net_id, vif_id, project_id): """Returns a list containing a single IPv6 address strings associated with the specified virtual interface. """ admin_context = context.elevated() network = db.network_get_by_uuid(admin_context, net_id) vif_rec = db.virtual_interface_get_by_uuid(context, vif_id) if network['cidr_v6']: ip = ipv6.to_global(network['cidr_v6'], vif_rec['address'], project_id) return [ip] return []
def get_networks_for_instance(context, instance): """Returns a prepared nw_info list for passing into the view builders We end up with a data structure like: {'public': {'ips': [{'addr': '10.0.0.1', 'version': 4}, {'addr': '2001::1', 'version': 6}], 'floating_ips': [{'addr': '172.16.0.1', 'version': 4}, {'addr': '172.16.2.1', 'version': 4}]}, ...} """ def _emit_addr(ip, version): return {'addr': ip, 'version': version} networks = {} fixed_ips = instance['fixed_ips'] ipv6_addrs_seen = {} for fixed_ip in fixed_ips: fixed_addr = fixed_ip['address'] network = fixed_ip['network'] vif = fixed_ip.get('virtual_interface') if not network or not vif: name = instance['name'] ip = fixed_ip['address'] LOG.warn( _("Instance %(name)s has stale IP " "address: %(ip)s (no network or vif)") % locals()) continue label = network.get('label', None) if label is None: continue if label not in networks: networks[label] = {'ips': [], 'floating_ips': []} nw_dict = networks[label] cidr_v6 = network.get('cidr_v6') if FLAGS.use_ipv6 and cidr_v6: ipv6_addr = ipv6.to_global(cidr_v6, vif['address'], network['project_id']) # Only add same IPv6 address once. It's possible we've # seen it before if there was a previous fixed_ip with # same network and vif as this one if not ipv6_addrs_seen.get(ipv6_addr): nw_dict['ips'].append(_emit_addr(ipv6_addr, 6)) ipv6_addrs_seen[ipv6_addr] = True nw_dict['ips'].append(_emit_addr(fixed_addr, 4)) for floating_ip in fixed_ip.get('floating_ips', []): float_addr = floating_ip['address'] nw_dict['floating_ips'].append(_emit_addr(float_addr, 4)) return networks
def get_networks_for_instance(context, instance): """Returns a prepared nw_info list for passing into the view builders We end up with a data structure like: {'public': {'ips': [{'addr': '10.0.0.1', 'version': 4}, {'addr': '2001::1', 'version': 6}], 'floating_ips': [{'addr': '172.16.0.1', 'version': 4}, {'addr': '172.16.2.1', 'version': 4}]}, ...} """ def _emit_addr(ip, version): return {'addr': ip, 'version': version} networks = {} fixed_ips = instance['fixed_ips'] ipv6_addrs_seen = {} for fixed_ip in fixed_ips: fixed_addr = fixed_ip['address'] network = fixed_ip['network'] vif = fixed_ip.get('virtual_interface') if not network or not vif: name = instance['name'] ip = fixed_ip['address'] LOG.warn(_("Instance %(name)s has stale IP " "address: %(ip)s (no network or vif)") % locals()) continue label = network.get('label', None) if label is None: continue if label not in networks: networks[label] = {'ips': [], 'floating_ips': []} nw_dict = networks[label] cidr_v6 = network.get('cidr_v6') if FLAGS.use_ipv6 and cidr_v6: ipv6_addr = ipv6.to_global(cidr_v6, vif['address'], network['project_id']) # Only add same IPv6 address once. It's possible we've # seen it before if there was a previous fixed_ip with # same network and vif as this one if not ipv6_addrs_seen.get(ipv6_addr): nw_dict['ips'].append(_emit_addr(ipv6_addr, 6)) ipv6_addrs_seen[ipv6_addr] = True nw_dict['ips'].append(_emit_addr(fixed_addr, 4)) for floating_ip in fixed_ip.get('floating_ips', []): float_addr = floating_ip['address'] nw_dict['floating_ips'].append(_emit_addr(float_addr, 4)) return networks
def test_private_ipv6(self): """Make sure ipv6 is OK""" if FLAGS.use_ipv6: instance_ref = self._create_instance(0) address = self._create_address(0, instance_ref['id']) network_ref = db.project_get_network( context.get_admin_context(), self.context.project_id) address_v6 = db.instance_get_fixed_address_v6( context.get_admin_context(), instance_ref['id']) self.assertEqual(instance_ref['mac_address'], ipv6.to_mac(address_v6)) instance_ref2 = db.fixed_ip_get_instance_v6( context.get_admin_context(), address_v6) self.assertEqual(instance_ref['id'], instance_ref2['id']) self.assertEqual(address_v6, ipv6.to_global(network_ref['cidr_v6'], instance_ref['mac_address'], 'test')) self._deallocate_address(0, address) db.instance_destroy(context.get_admin_context(), instance_ref['id'])
def _format_instances(self, context, instance_id=None, **kwargs): # TODO(termie): this method is poorly named as its name does not imply # that it will be making a variety of database calls # rather than simply formatting a bunch of instances that # were handed to it reservations = {} # NOTE(vish): instance_id is an optional list of ids to filter by if instance_id: instances = [] for ec2_id in instance_id: internal_id = ec2utils.ec2_id_to_id(ec2_id) instance = self.compute_api.get(context, instance_id=internal_id) instances.append(instance) else: instances = self.compute_api.get_all(context, **kwargs) for instance in instances: if not context.is_admin: if instance['image_id'] == str(FLAGS.vpn_image_id): continue i = {} instance_id = instance['id'] ec2_id = ec2utils.id_to_ec2_id(instance_id) i['instanceId'] = ec2_id i['imageId'] = self.image_ec2_id(instance['image_id']) i['instanceState'] = { 'code': instance['state'], 'name': instance['state_description']} fixed_addr = None floating_addr = None if instance['fixed_ip']: fixed_addr = instance['fixed_ip']['address'] if instance['fixed_ip']['floating_ips']: fixed = instance['fixed_ip'] floating_addr = fixed['floating_ips'][0]['address'] if instance['fixed_ip']['network'] and 'use_v6' in kwargs: i['dnsNameV6'] = ipv6.to_global( instance['fixed_ip']['network']['cidr_v6'], instance['mac_address'], instance['project_id']) i['privateDnsName'] = fixed_addr i['privateIpAddress'] = fixed_addr i['publicDnsName'] = floating_addr i['ipAddress'] = floating_addr or fixed_addr i['dnsName'] = i['publicDnsName'] or i['privateDnsName'] i['keyName'] = instance['key_name'] if context.is_admin: i['keyName'] = '%s (%s, %s)' % (i['keyName'], instance['project_id'], instance['host']) i['productCodesSet'] = self._convert_to_set([], 'product_codes') if instance['instance_type']: i['instanceType'] = instance['instance_type'].get('name') else: i['instanceType'] = None i['launchTime'] = instance['created_at'] i['amiLaunchIndex'] = instance['launch_index'] i['displayName'] = instance['display_name'] i['displayDescription'] = instance['display_description'] host = instance['host'] zone = self._get_availability_zone_by_host(context, host) i['placement'] = {'availabilityZone': zone} if instance['reservation_id'] not in reservations: r = {} r['reservationId'] = instance['reservation_id'] r['ownerId'] = instance['project_id'] security_group_names = [] if instance.get('security_groups'): for security_group in instance['security_groups']: security_group_names.append(security_group['name']) r['groupSet'] = self._convert_to_set(security_group_names, 'groupId') r['instancesSet'] = [] reservations[instance['reservation_id']] = r reservations[instance['reservation_id']]['instancesSet'].append(i) return list(reservations.values())
def test_to_global(self): addr = ipv6.to_global('2001:db8::', '02:16:3e:33:44:55', 'test') self.assertEquals(addr, '2001:db8::a94a:8fe5:ff33:4455')
def _get_fixed_ipv6_dict(cidr, mac, project_id): ip_string = ipv6.to_global(cidr, mac, project_id) return {'version': 6, 'address': ip_string, 'floating_ips': []}
def ip6_dict(): return { "ip": ipv6.to_global(network["cidr_v6"], vif["address"], network["project_id"]), "netmask": network["netmask_v6"], "enabled": "1", }
def test_to_global(self): addr = ipv6.to_global('2001:db8::', '02:16:3e:33:44:55', 'test') self.assertEqual(addr, '2001:db8::16:3eff:fe33:4455')