~ubuntu-branches/ubuntu/vivid/neutron/vivid-updates

« back to all changes in this revision

Viewing changes to neutron/agent/l3/namespaces.py

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2015-03-30 11:17:19 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20150330111719-h0gx7233p4jkkgfh
Tags: 1:2015.1~b3-0ubuntu1
* New upstream milestone release:
  - d/control: Align version requirements with upstream.
  - d/control: Add new dependency on oslo-log.
  - d/p/*: Rebase.
  - d/control,d/neutron-plugin-hyperv*: Dropped, decomposed into
    separate project upstream.
  - d/control,d/neutron-plugin-openflow*: Dropped, decomposed into
    separate project upstream.
  - d/neutron-common.install: Add neutron-rootwrap-daemon and 
    neutron-keepalived-state-change binaries.
  - d/rules: Ignore neutron-hyperv-agent when installing; only for Windows.
  - d/neutron-plugin-cisco.install: Drop neutron-cisco-cfg-agent as
    decomposed into separate project upstream.
  - d/neutron-plugin-vmware.install: Drop neutron-check-nsx-config and
    neutron-nsx-manage as decomposed into separate project upstream.
  - d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent.
* d/pydist-overrides: Add overrides for oslo packages.
* d/control: Fixup type in package description (LP: #1263539).
* d/p/fixup-driver-test-execution.patch: Cherry pick fix from upstream VCS
  to support unit test exection in out-of-tree vendor drivers.
* d/neutron-common.postinst: Allow general access to /etc/neutron but limit
  access to root/neutron to /etc/neutron/neutron.conf to support execution
  of unit tests in decomposed vendor drivers.
* d/control: Add dependency on python-neutron-fwaas to neutron-l3-agent
  package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2015 Hewlett-Packard Development Company, L.P.
 
2
#
 
3
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
4
#    not use this file except in compliance with the License. You may obtain
 
5
#    a copy of the License at
 
6
#
 
7
#         http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
#    Unless required by applicable law or agreed to in writing, software
 
10
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
11
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
12
#    License for the specific language governing permissions and limitations
 
13
#    under the License.
 
14
#
 
15
 
 
16
from oslo_log import log as logging
 
17
 
 
18
from neutron.agent.linux import ip_lib
 
19
from neutron.i18n import _LE
 
20
 
 
21
LOG = logging.getLogger(__name__)
 
22
 
 
23
NS_PREFIX = 'qrouter-'
 
24
INTERNAL_DEV_PREFIX = 'qr-'
 
25
EXTERNAL_DEV_PREFIX = 'qg-'
 
26
# TODO(Carl) It is odd that this file needs this.  It is a dvr detail.
 
27
ROUTER_2_FIP_DEV_PREFIX = 'rfp-'
 
28
 
 
29
 
 
30
class Namespace(object):
 
31
 
 
32
    def __init__(self, name, agent_conf, driver, use_ipv6):
 
33
        self.name = name
 
34
        self.ip_wrapper_root = ip_lib.IPWrapper()
 
35
        self.agent_conf = agent_conf
 
36
        self.driver = driver
 
37
        self.use_ipv6 = use_ipv6
 
38
 
 
39
    def create(self):
 
40
        ip_wrapper = self.ip_wrapper_root.ensure_namespace(self.name)
 
41
        cmd = ['sysctl', '-w', 'net.ipv4.ip_forward=1']
 
42
        ip_wrapper.netns.execute(cmd)
 
43
        if self.use_ipv6:
 
44
            cmd = ['sysctl', '-w', 'net.ipv6.conf.all.forwarding=1']
 
45
            ip_wrapper.netns.execute(cmd)
 
46
 
 
47
    def delete(self):
 
48
        if self.agent_conf.router_delete_namespaces:
 
49
            try:
 
50
                self.ip_wrapper_root.netns.delete(self.name)
 
51
            except RuntimeError:
 
52
                msg = _LE('Failed trying to delete namespace: %s')
 
53
                LOG.exception(msg, self.name)
 
54
 
 
55
 
 
56
class RouterNamespace(Namespace):
 
57
 
 
58
    def __init__(self, router_id, agent_conf, driver, use_ipv6):
 
59
        self.router_id = router_id
 
60
        name = self._get_ns_name(router_id)
 
61
        super(RouterNamespace, self).__init__(
 
62
            name, agent_conf, driver, use_ipv6)
 
63
 
 
64
    @staticmethod
 
65
    def _get_ns_name(router_id):
 
66
        return (NS_PREFIX + router_id)
 
67
 
 
68
    def delete(self):
 
69
        ns_ip = ip_lib.IPWrapper(namespace=self.name)
 
70
        for d in ns_ip.get_devices(exclude_loopback=True):
 
71
            if d.name.startswith(INTERNAL_DEV_PREFIX):
 
72
                # device is on default bridge
 
73
                self.driver.unplug(d.name, namespace=self.name,
 
74
                                   prefix=INTERNAL_DEV_PREFIX)
 
75
            elif d.name.startswith(ROUTER_2_FIP_DEV_PREFIX):
 
76
                ns_ip.del_veth(d.name)
 
77
            elif d.name.startswith(EXTERNAL_DEV_PREFIX):
 
78
                self.driver.unplug(
 
79
                    d.name,
 
80
                    bridge=self.agent_conf.external_network_bridge,
 
81
                    namespace=self.name,
 
82
                    prefix=EXTERNAL_DEV_PREFIX)
 
83
 
 
84
        super(RouterNamespace, self).delete()