¡@

Home 

OpenStack Study: l3.py

OpenStack Index

**** CubicPower OpenStack Study ****

# Copyright 2012 Nicira Networks, Inc

# All Rights Reserved.

#

# Licensed under the Apache License, Version 2.0 (the "License"); you may

# not use this file except in compliance with the License. You may obtain

# a copy of the License at

#

# http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT

# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

# License for the specific language governing permissions and limitations

# under the License.

from nova.network import linux_net

from nova.openstack.common import log as logging

from nova import utils

LOG = logging.getLogger(__name__)

**** CubicPower OpenStack Study ****

class L3Driver(object):

"""Abstract class that

**** CubicPower OpenStack Study ****

    def __init__(self, l3_lib=None):

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def initialize(self, **kwargs):

        """Set up basic L3 networking functionality."""

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def initialize_network(self, network):

        """Enable rules for a specific network."""

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def initialize_gateway(self, network):

        """Set up a gateway on this network."""

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def remove_gateway(self, network_ref):

        """Remove an existing gateway on this network."""

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def is_initialized(self):

        """:returns: True/False (whether the driver is initialized)."""

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def add_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,

                        network=None):

        """Add a floating IP bound to the fixed IP with an optional

           l3_interface_id.  Some drivers won't care about the

           l3_interface_id so just pass None in that case. Network

           is also an optional parameter.

        """

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def remove_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,

                           network=None):

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def add_vpn(self, public_ip, port, private_ip):

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def remove_vpn(self, public_ip, port, private_ip):

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def clean_conntrack(self, fixed_ip):

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

    def teardown(self):

        raise NotImplementedError()

**** CubicPower OpenStack Study ****

class LinuxNetL3(L3Driver):

"""L3 driver that uses linux_net as the backend."""

**** CubicPower OpenStack Study ****

    def __init__(self):

        self.initialized = False

**** CubicPower OpenStack Study ****

    def initialize(self, **kwargs):

        if self.initialized:

            return

        LOG.debug("Initializing linux_net L3 driver")

        fixed_range = kwargs.get('fixed_range', False)

        networks = kwargs.get('networks', None)

        if not fixed_range and networks is not None:

            for network in networks:

                self.initialize_network(network['cidr'])

        else:

            linux_net.init_host()

        linux_net.ensure_metadata_ip()

        linux_net.metadata_forward()

        self.initialized = True

**** CubicPower OpenStack Study ****

    def is_initialized(self):

        return self.initialized

**** CubicPower OpenStack Study ****

    def initialize_network(self, cidr):

        linux_net.init_host(cidr)

**** CubicPower OpenStack Study ****

    def initialize_gateway(self, network_ref):

        mac_address = utils.generate_mac_address()

        dev = linux_net.plug(network_ref, mac_address,

                    gateway=(network_ref['gateway'] is not None))

        linux_net.initialize_gateway_device(dev, network_ref)

**** CubicPower OpenStack Study ****

    def remove_gateway(self, network_ref):

        linux_net.unplug(network_ref)

**** CubicPower OpenStack Study ****

    def add_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,

                        network=None):

        linux_net.ensure_floating_forward(floating_ip, fixed_ip,

                                          l3_interface_id, network)

        linux_net.bind_floating_ip(floating_ip, l3_interface_id)

**** CubicPower OpenStack Study ****

    def remove_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,

                           network=None):

        linux_net.unbind_floating_ip(floating_ip, l3_interface_id)

        linux_net.remove_floating_forward(floating_ip, fixed_ip,

                                          l3_interface_id, network)

**** CubicPower OpenStack Study ****

    def add_vpn(self, public_ip, port, private_ip):

        linux_net.ensure_vpn_forward(public_ip, port, private_ip)

**** CubicPower OpenStack Study ****

    def remove_vpn(self, public_ip, port, private_ip):

        # Linux net currently doesn't implement any way of removing

        # the VPN forwarding rules

        pass

**** CubicPower OpenStack Study ****

    def clean_conntrack(self, fixed_ip):

        linux_net.clean_conntrack(fixed_ip)

**** CubicPower OpenStack Study ****

    def teardown(self):

        pass

**** CubicPower OpenStack Study ****

class NullL3(L3Driver):

"""The L3 driver that doesn't do anything. This class can be used when

nova-network should not manipulate L3 forwarding at all (e.g., in a Flat

or FlatDHCP scenario).

"""

**** CubicPower OpenStack Study ****

    def __init__(self):

        pass

**** CubicPower OpenStack Study ****

    def initialize(self, **kwargs):

        pass

**** CubicPower OpenStack Study ****

    def is_initialized(self):

        return True

**** CubicPower OpenStack Study ****

    def initialize_network(self, cidr):

        pass

**** CubicPower OpenStack Study ****

    def initialize_gateway(self, network_ref):

        pass

**** CubicPower OpenStack Study ****

    def remove_gateway(self, network_ref):

        pass

**** CubicPower OpenStack Study ****

    def add_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,

                        network=None):

        pass

**** CubicPower OpenStack Study ****

    def remove_floating_ip(self, floating_ip, fixed_ip, l3_interface_id,

                           network=None):

        pass

**** CubicPower OpenStack Study ****

    def add_vpn(self, public_ip, port, private_ip):

        pass

**** CubicPower OpenStack Study ****

    def remove_vpn(self, public_ip, port, private_ip):

        pass

**** CubicPower OpenStack Study ****

    def clean_conntrack(self, fixed_ip):

        pass

**** CubicPower OpenStack Study ****

    def teardown(self):

        pass