1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 Nicira Networks, Inc
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
19
from nova import exception
21
from nova.openstack.common import log as logging
24
LOG = logging.getLogger(__name__)
27
def get_ipam_lib(net_man):
28
return QuantumNovaIPAMLib(net_man)
31
class QuantumNovaIPAMLib(object):
32
"""Implements Quantum IP Address Management (IPAM) interface
33
using the local Nova database. This implementation is inline
34
with how IPAM is used by other NetworkManagers.
37
def __init__(self, net_manager):
38
"""Holds a reference to the "parent" network manager, used
39
to take advantage of various FlatManager methods to avoid
42
self.net_manager = net_manager
44
def get_subnets_by_net_id(self, context, tenant_id, net_id, _vif_id=None):
45
"""Returns information about the IPv4 and IPv6 subnets
46
associated with a Quantum Network UUID.
48
n = db.network_get_by_uuid(context.elevated(), net_id)
50
'network_id': n['uuid'],
52
'gateway': n['gateway'],
53
'broadcast': n['broadcast'],
54
'netmask': n['netmask'],
58
#TODO(tr3buchet): I'm noticing we've assumed here that all dns is v4.
59
# this is probably bad as there is no way to add v6
62
'network_id': n['uuid'],
64
'gateway': n['gateway_v6'],
66
'netmask': n['netmask_v6'],
70
return [subnet_v4, subnet_v6]
72
def get_routes_by_ip_block(self, context, block_id, project_id):
73
"""Returns the list of routes for the IP block"""
76
def get_v4_ips_by_interface(self, context, net_id, vif_id, project_id):
77
"""Returns a list of IPv4 address strings associated with
78
the specified virtual interface, based on the fixed_ips table.
80
# TODO(tr3buchet): link fixed_ips to vif by uuid so only 1 db call
81
vif_rec = db.virtual_interface_get_by_uuid(context, vif_id)
82
fixed_ips = db.fixed_ips_by_virtual_interface(context,
84
return [fixed_ip['address'] for fixed_ip in fixed_ips]
86
def get_v6_ips_by_interface(self, context, net_id, vif_id, project_id):
87
"""Returns a list containing a single IPv6 address strings
88
associated with the specified virtual interface.
90
admin_context = context.elevated()
91
network = db.network_get_by_uuid(admin_context, net_id)
92
vif_rec = db.virtual_interface_get_by_uuid(context, vif_id)
93
if network['cidr_v6']:
94
ip = ipv6.to_global(network['cidr_v6'],
100
def get_floating_ips_by_fixed_address(self, context, fixed_address):
101
return db.floating_ip_get_by_fixed_address(context, fixed_address)