components/openstack/neutron/files/agent/evs_l3_agent.py
author Girish Moodalbail <Girish.Moodalbail@oracle.COM>
Thu, 26 Jun 2014 19:18:52 -0700
changeset 1977 12e9c20eef5a
parent 1959 ba86b21a837b
child 1987 6fa18b7a0af6
permissions -rw-r--r--
19034270 IPv6 filter rules are not properly handled
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     2
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     3
# Copyright 2012 Nicira Networks, Inc.  All rights reserved.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     4
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     5
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     6
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     8
#    not use this file except in compliance with the License. You may obtain
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     9
#    a copy of the License at
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    10
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    11
#         http://www.apache.org/licenses/LICENSE-2.0
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    12
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    13
#    Unless required by applicable law or agreed to in writing, software
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    14
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    15
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    16
#    License for the specific language governing permissions and limitations
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    17
#    under the License.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    18
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    19
# @author: Dan Wendlandt, Nicira, Inc
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    20
# @author: Girish Moodalbail, Oracle, Inc.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    21
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    22
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    23
"""
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    24
Based off generic l3_agent (neutron/agent/l3_agent) code
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    25
"""
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    26
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    27
import netaddr
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    28
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    29
from oslo.config import cfg
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    30
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    31
from neutron.agent import l3_agent
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    32
from neutron.agent.linux import utils
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    33
from neutron.agent.solaris import interface
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    34
from neutron.agent.solaris import ipfilters_manager
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    35
from neutron.agent.solaris import net_lib
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    36
from neutron.common import constants as l3_constants
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    37
from neutron.openstack.common import log as logging
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    38
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    39
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    40
LOG = logging.getLogger(__name__)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    41
INTERNAL_DEV_PREFIX = 'l3i'
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    42
EXTERNAL_DEV_PREFIX = 'l3e'
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    43
FLOATING_IP_CIDR_SUFFIX = '/32'
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    44
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    45
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    46
class RouterInfo(object):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    47
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    48
    def __init__(self, router_id, root_helper, use_namespaces, router):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    49
        self.router_id = router_id
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    50
        self.ex_gw_port = None
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    51
        self._snat_enabled = None
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    52
        self._snat_action = None
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    53
        self.internal_ports = []
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    54
        # We do not need either root_helper or namespace, so set them to None
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    55
        self.root_helper = None
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    56
        self.use_namespaces = None
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    57
        # Invoke the setter for establishing initial SNAT action
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    58
        self.router = router
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    59
        self.ipfilters_manager = ipfilters_manager.IPfiltersManager()
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    60
        self.routes = []
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    61
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    62
    @property
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    63
    def router(self):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    64
        return self._router
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    65
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    66
    @router.setter
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    67
    def router(self, value):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    68
        self._router = value
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    69
        if not self._router:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    70
            return
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    71
        # enable_snat by default if it wasn't specified by plugin
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    72
        self._snat_enabled = self._router.get('enable_snat', True)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    73
        # Set a SNAT action for the router
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    74
        if self._router.get('gw_port'):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    75
            self._snat_action = ('add_rules' if self._snat_enabled
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    76
                                 else 'remove_rules')
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    77
        elif self.ex_gw_port:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    78
            # Gateway port was removed, remove rules
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    79
            self._snat_action = 'remove_rules'
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    80
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    81
    def ns_name(self):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    82
        pass
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    83
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    84
    def perform_snat_action(self, snat_callback, *args):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    85
        # Process SNAT rules for attached subnets
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    86
        if self._snat_action:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    87
            snat_callback(self, self._router.get('gw_port'),
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    88
                          *args, action=self._snat_action)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    89
        self._snat_action = None
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    90
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    91
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    92
class EVSL3NATAgent(l3_agent.L3NATAgent):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    93
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    94
    RouterInfo = RouterInfo
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    95
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    96
    OPTS = [
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    97
        cfg.StrOpt('external_network_datalink', default='net0',
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    98
                   help=_("Name of the datalink that connects to "
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    99
                          "an external network.")),
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   100
        cfg.BoolOpt('allow_forwarding_between_networks', default=False,
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   101
                    help=_("Allow forwarding of packets between tenant's "
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   102
                           "networks")),
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   103
    ]
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   104
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   105
    def __init__(self, host, conf=None):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   106
        cfg.CONF.register_opts(self.OPTS)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   107
        cfg.CONF.register_opts(interface.OPTS)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   108
        super(EVSL3NATAgent, self).__init__(host=host, conf=conf)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   109
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   110
    def _router_added(self, router_id, router):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   111
        ri = RouterInfo(router_id, self.root_helper,
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   112
                        self.conf.use_namespaces, router)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   113
        self.router_info[router_id] = ri
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   114
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   115
    def _router_removed(self, router_id):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   116
        ri = self.router_info[router_id]
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   117
        ri.router['gw_port'] = None
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   118
        ri.router[l3_constants.INTERFACE_KEY] = []
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   119
        ri.router[l3_constants.FLOATINGIP_KEY] = []
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   120
        self.process_router(ri)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   121
        del self.router_info[router_id]
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   122
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   123
    def process_router(self, ri):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   124
        ex_gw_port = self._get_ex_gw_port(ri)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   125
        internal_ports = ri.router.get(l3_constants.INTERFACE_KEY, [])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   126
        existing_port_ids = set([p['id'] for p in ri.internal_ports])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   127
        current_port_ids = set([p['id'] for p in internal_ports
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   128
                                if p['admin_state_up']])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   129
        new_ports = [p for p in internal_ports if
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   130
                     p['id'] in current_port_ids and
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   131
                     p['id'] not in existing_port_ids]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   132
        old_ports = [p for p in ri.internal_ports if
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   133
                     p['id'] not in current_port_ids]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   134
        for p in new_ports:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   135
            self._set_subnet_info(p)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   136
            ri.internal_ports.append(p)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   137
            self.internal_network_added(ri, p)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   138
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   139
        for p in old_ports:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   140
            ri.internal_ports.remove(p)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   141
            self.internal_network_removed(ri, p)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   142
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   143
        internal_cidrs = [p['ip_cidr'] for p in ri.internal_ports]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   144
        # TODO(salv-orlando): RouterInfo would be a better place for
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   145
        # this logic too
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   146
        ex_gw_port_id = (ex_gw_port and ex_gw_port['id'] or
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   147
                         ri.ex_gw_port and ri.ex_gw_port['id'])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   148
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   149
        interface_name = None
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   150
        if ex_gw_port_id:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   151
            interface_name = self.get_external_device_name(ex_gw_port_id)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   152
        if ex_gw_port and not ri.ex_gw_port:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   153
            self._set_subnet_info(ex_gw_port)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   154
            self.external_gateway_added(ri, ex_gw_port,
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   155
                                        interface_name, internal_cidrs)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   156
        elif not ex_gw_port and ri.ex_gw_port:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   157
            self.external_gateway_removed(ri, ri.ex_gw_port,
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   158
                                          interface_name, internal_cidrs)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   159
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   160
        # We don't need this since our IPnat rules are bi-directional
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   161
        # Process SNAT rules for external gateway
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   162
        # ri.perform_snat_action(self._handle_router_snat_rules,
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   163
        #                       internal_cidrs, interface_name)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   164
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   165
        # Process DNAT rules for floating IPs
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   166
        if ex_gw_port:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   167
            self.process_router_floating_ips(ri, ex_gw_port)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   168
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   169
        ri.ex_gw_port = ex_gw_port
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   170
        ri.enable_snat = ri.router.get('enable_snat')
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   171
        self.routes_updated(ri)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   172
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   173
    def process_router_floating_ips(self, ri, ex_gw_port):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   174
        """Configure the router's floating IPs
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   175
        Configures floating ips using ipnat(1m) on the router's gateway device.
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   176
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   177
        Cleans up floating ips that should not longer be configured.
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   178
        """
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   179
        ifname = self.get_external_device_name(ex_gw_port['id'])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   180
        ipintf = net_lib.IPInterface(ifname)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   181
        ipaddr_list = ipintf.ipaddr_list()['static']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   182
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   183
        # Clear out all ipnat rules for floating ips
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   184
        ri.ipfilters_manager.remove_nat_rules(ri.ipfilters_manager.ipv4['nat'])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   185
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   186
        existing_cidrs = set([addr for addr in ipaddr_list])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   187
        new_cidrs = set()
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   188
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   189
        # Loop once to ensure that floating ips are configured.
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   190
        for fip in ri.router.get(l3_constants.FLOATINGIP_KEY, []):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   191
            fip_ip = fip['floating_ip_address']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   192
            fip_cidr = str(fip_ip) + FLOATING_IP_CIDR_SUFFIX
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   193
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   194
            new_cidrs.add(fip_cidr)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   195
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   196
            if fip_cidr not in existing_cidrs:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   197
                ipintf.create_address(fip_cidr)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   198
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   199
            # Rebuild iptables rules for the floating ip.
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   200
            fixed_cidr = str(fip['fixed_ip_address']) + '/32'
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   201
            nat_rules = ['bimap %s %s -> %s' % (ifname, fixed_cidr, fip_cidr)]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   202
            ri.ipfilters_manager.add_nat_rules(nat_rules)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   203
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   204
        # Clean up addresses that no longer belong on the gateway interface.
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   205
        for ip_cidr in existing_cidrs - new_cidrs:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   206
            if ip_cidr.endswith(FLOATING_IP_CIDR_SUFFIX):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   207
                ipintf.delete_address(ip_cidr)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   208
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   209
    def get_internal_device_name(self, port_id):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   210
        # Because of the way how dnsmasq works on Solaris, the length
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   211
        # of datalink name cannot exceed 16 (includes terminating nul
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   212
        # character). So, the linkname can only have 15 characters and
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   213
        # the last two characters are set aside for '_0'. So, we only
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   214
        # have 13 characters left.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   215
        dname = (INTERNAL_DEV_PREFIX + port_id)[:13]
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   216
        dname += '_0'
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   217
        return dname.replace('-', '_')
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   218
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   219
    def get_external_device_name(self, port_id):
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   220
        # please see the comment above
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   221
        dname = (EXTERNAL_DEV_PREFIX + port_id)[:13]
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   222
        dname += '_0'
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   223
        return dname.replace('-', '_')
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   224
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   225
    def external_gateway_added(self, ri, ex_gw_port,
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   226
                               external_dlname, internal_cidrs):
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   227
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   228
        if not net_lib.Datalink.datalink_exists(external_dlname):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   229
            dl = net_lib.Datalink(external_dlname)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   230
            # need to determine the VLAN ID for the VNIC
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   231
            evsname = ex_gw_port['network_id']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   232
            tenantname = ex_gw_port['tenant_id']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   233
            cmd = ['/usr/sbin/evsadm', 'show-evs', '-co', 'vid',
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   234
                   '-f', 'tenant=%s' % tenantname, evsname]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   235
            try:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   236
                stdout = utils.execute(cmd)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   237
            except Exception as err:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   238
                LOG.error(_("Failed to retrieve the VLAN ID associated "
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   239
                            "with the external network, and it is required "
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   240
                            "to create external gateway port: %s") % err)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   241
                return
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   242
            vid = stdout.splitlines()[0].strip()
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   243
            if vid == "":
1959
ba86b21a837b 19026240 Extract tenantid using the framework provided function
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
   244
                LOG.error(_("External Network does not have a VLAN ID "
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   245
                            "associated with it, and it is required to "
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   246
                            "create external gateway port"))
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   247
                return
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   248
            mac_address = ex_gw_port['mac_address']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   249
            dl.create_vnic(self.conf.external_network_datalink,
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   250
                           mac_address=mac_address, vid=vid)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   251
        self.driver.init_l3(external_dlname, [ex_gw_port['ip_cidr']])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   252
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   253
        # TODO(gmoodalb): wrap route(1m) command within a class in net_lib.py
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   254
        gw_ip = ex_gw_port['subnet']['gateway_ip']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   255
        if gw_ip:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   256
            cmd = ['/usr/bin/pfexec', '/usr/sbin/route', 'add', 'default',
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   257
                   gw_ip]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   258
            utils.execute(cmd, check_exit_code=False)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   259
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   260
    def external_gateway_removed(self, ri, ex_gw_port,
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   261
                                 external_dlname, internal_cidrs):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   262
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   263
        if net_lib.Datalink.datalink_exists(external_dlname):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   264
            self.driver.fini_l3(external_dlname)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   265
            self.driver.unplug(external_dlname)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   266
        gw_ip = ex_gw_port['subnet']['gateway_ip']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   267
        if gw_ip:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   268
            cmd = ['/usr/bin/pfexec', '/usr/sbin/route', 'delete', 'default',
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   269
                   gw_ip]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   270
            utils.execute(cmd, check_exit_code=False)
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   271
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   272
    def _get_ippool_name(self, mac_address):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   273
        # generate a unique-name for ippool(1m) from that last 3
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   274
        # bytes of mac-address
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   275
        mac_suffix = mac_address.split(':')[3:]
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   276
        return int("".join(mac_suffix), 16)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   277
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   278
    def internal_network_added(self, ri, port):
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   279
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   280
        internal_dlname = self.get_internal_device_name(port['id'])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   281
        if not net_lib.Datalink.datalink_exists(internal_dlname):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   282
            self.driver.plug(port['tenant_id'], port['network_id'], port['id'],
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   283
                             internal_dlname)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   284
        self.driver.init_l3(internal_dlname, [port['ip_cidr']])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   285
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   286
        # add ippool(1m) for the new internal port
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   287
        new_ippool_name = self._get_ippool_name(port['mac_address'])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   288
        ri.ipfilters_manager.add_ippool(new_ippool_name, None)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   289
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   290
        # walk through the other internal ports and retrieve their
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   291
        # cidrs and at the same time add the new internal port's
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   292
        # cidr to them
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   293
        subnet_cidr = port['subnet']['cidr']
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   294
        other_subnet_cidrs = []
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   295
        for oip in ri.internal_ports:
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   296
            if oip['mac_address'] != port['mac_address']:
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   297
                if (self.conf.allow_forwarding_between_networks and
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   298
                        oip['tenant_id'] == port['tenant_id']):
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   299
                    continue
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   300
                other_subnet_cidrs.append(oip['subnet']['cidr'])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   301
                ippool_name = self._get_ippool_name(oip['mac_address'])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   302
                ri.ipfilters_manager.add_ippool(ippool_name, [subnet_cidr])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   303
        # update the new port's pool with other port's cidrs
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   304
        ri.ipfilters_manager.add_ippool(new_ippool_name, other_subnet_cidrs)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   305
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   306
        # now setup the IPF rule
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   307
        rules = ['block in quick on %s from %s to pool/%d' %
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   308
                 (internal_dlname, subnet_cidr, new_ippool_name)]
1977
12e9c20eef5a 19034270 IPv6 filter rules are not properly handled
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1959
diff changeset
   309
        ipversion = netaddr.IPNetwork(subnet_cidr).version
12e9c20eef5a 19034270 IPv6 filter rules are not properly handled
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1959
diff changeset
   310
        ri.ipfilters_manager.add_ipf_rules(rules, ipversion)
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   311
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   312
    def internal_network_removed(self, ri, port):
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   313
        internal_dlname = self.get_internal_device_name(port['id'])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   314
        if net_lib.Datalink.datalink_exists(internal_dlname):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   315
            self.driver.fini_l3(internal_dlname)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   316
            self.driver.unplug(internal_dlname)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   317
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   318
        # remove all the IP filter rules that we added during addition.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   319
        ippool_name = self._get_ippool_name(port['mac_address'])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   320
        rules = ['block in quick on %s from %s to pool/%d' %
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   321
                 (internal_dlname, port['subnet']['cidr'], ippool_name)]
1977
12e9c20eef5a 19034270 IPv6 filter rules are not properly handled
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1959
diff changeset
   322
        ipversion = netaddr.IPNetwork(port['subnet']['cidr']).version
12e9c20eef5a 19034270 IPv6 filter rules are not properly handled
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1959
diff changeset
   323
        ri.ipfilters_manager.remove_ipf_rules(rules, ipversion)
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   324
        # remove the ippool
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   325
        ri.ipfilters_manager.remove_ippool(ippool_name, None)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   326
        for internal_port in ri.internal_ports:
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   327
            if (self.conf.allow_forwarding_between_networks and
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   328
                    internal_port['tenant_id'] == port['tenant_id']):
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   329
                continue
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   330
            ippool_name = \
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   331
                self._get_ippool_name(internal_port['mac_address'])
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   332
            subnet_cidr = internal_port['subnet']['cidr']
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   333
            ri.ipfilters_manager.remove_ippool(ippool_name, [subnet_cidr])
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   334
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   335
    def routers_updated(self, context, routers):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   336
        super(EVSL3NATAgent, self).routers_updated(context, routers)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   337
        if routers:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   338
            # If router's interface was removed, then the VNIC associated
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   339
            # with that interface must be deleted immediately. The EVS
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   340
            # plugin can delete the virtual port iff the VNIC associated
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   341
            # with that virtual port is deleted first.
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
   342
            self._rpc_loop()
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   343
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   344
    def routes_updated(self, ri):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
   345
        pass