47
42
def get_ip_version(cidr):
48
43
net = netaddr.IPNetwork(cidr)
49
44
return int(net.version)
52
def get_network_info(instance):
53
# TODO(tr3buchet): this function needs to go away! network info
54
# MUST be passed down from compute
55
# TODO(adiantum) If we will keep this function
56
# we should cache network_info
57
admin_context = context.get_admin_context()
60
fixed_ips = db.fixed_ip_get_by_instance(admin_context, instance['id'])
61
except exception.FixedIpNotFoundForInstance:
64
vifs = db.virtual_interface_get_by_instance(admin_context, instance['id'])
65
flavor = db.instance_type_get(admin_context,
66
instance['instance_type_id'])
70
network = vif['network']
72
# determine which of the instance's IPs belong to this network
73
network_ips = [fixed_ip['address'] for fixed_ip in fixed_ips if
74
fixed_ip['network_id'] == network['id']]
79
'netmask': network['netmask'],
83
prefix = network['cidr_v6']
85
project_id = instance['project_id']
87
'ip': ipv6.to_global(prefix, mac, project_id),
88
'netmask': network['netmask_v6'],
92
'label': network['label'],
93
'gateway': network['gateway'],
94
'broadcast': network['broadcast'],
95
'dhcp_server': network['gateway'],
96
'mac': vif['address'],
97
'rxtx_cap': flavor['rxtx_cap'],
99
'ips': [ip_dict(ip) for ip in network_ips]}
102
mapping['dns'].append(network['dns1'])
104
mapping['dns'].append(network['dns2'])
107
mapping['ip6s'] = [ip6_dict()]
108
mapping['gateway6'] = network['gateway_v6']
110
network_info.append((network, mapping))