~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/network/nova_ipam_lib.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2011 Nicira Networks, Inc
 
4
# All Rights Reserved.
 
5
#
 
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
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
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
 
16
#    under the License.
 
17
 
 
18
from nova import db
 
19
from nova import exception
 
20
from nova import ipv6
 
21
from nova.openstack.common import log as logging
 
22
 
 
23
 
 
24
LOG = logging.getLogger(__name__)
 
25
 
 
26
 
 
27
def get_ipam_lib(net_man):
 
28
    return QuantumNovaIPAMLib(net_man)
 
29
 
 
30
 
 
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.
 
35
    """
 
36
 
 
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
 
40
           code duplication.
 
41
        """
 
42
        self.net_manager = net_manager
 
43
 
 
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.
 
47
        """
 
48
        n = db.network_get_by_uuid(context.elevated(), net_id)
 
49
        subnet_v4 = {
 
50
            'network_id': n['uuid'],
 
51
            'cidr': n['cidr'],
 
52
            'gateway': n['gateway'],
 
53
            'broadcast': n['broadcast'],
 
54
            'netmask': n['netmask'],
 
55
            'version': 4,
 
56
            'dns1': n['dns1'],
 
57
            'dns2': n['dns2']}
 
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
 
60
        #                 dns to nova
 
61
        subnet_v6 = {
 
62
            'network_id': n['uuid'],
 
63
            'cidr': n['cidr_v6'],
 
64
            'gateway': n['gateway_v6'],
 
65
            'broadcast': None,
 
66
            'netmask': n['netmask_v6'],
 
67
            'version': 6,
 
68
            'dns1': None,
 
69
            'dns2': None}
 
70
        return [subnet_v4, subnet_v6]
 
71
 
 
72
    def get_routes_by_ip_block(self, context, block_id, project_id):
 
73
        """Returns the list of routes for the IP block"""
 
74
        return []
 
75
 
 
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.
 
79
        """
 
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,
 
83
                                                      vif_rec['id'])
 
84
        return [fixed_ip['address'] for fixed_ip in fixed_ips]
 
85
 
 
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.
 
89
        """
 
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'],
 
95
                                vif_rec['address'],
 
96
                                project_id)
 
97
            return [ip]
 
98
        return []
 
99
 
 
100
    def get_floating_ips_by_fixed_address(self, context, fixed_address):
 
101
        return db.floating_ip_get_by_fixed_address(context, fixed_address)