~corey.bryant/ubuntu/trusty/neutron/lp1318721

« back to all changes in this revision

Viewing changes to neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Corey Bryant
  • Date: 2014-10-06 09:15:06 UTC
  • mfrom: (28.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20141006091506-cesvev43moce4y74
Tags: 1:2014.1.3-0ubuntu1
[ Corey Bryant ]
* Resynchronize with stable/icehouse (4a0210e) (LP: #1377136):
  - [3a30d19] Deletes floating ip related connection states
  - [dd4b77f] Forbid regular users to reset admin-only attrs to default values
  - [dc2c893] Add delete operations for the ODL MechanismDriver
  - [b51e2c7] Add missing ml2 plugin to migration 1fcfc149aca4
  - [a17a500] Don't convert numeric protocol values to int
  - [3a85946] NSX: Optionally not enforce nat rule match length check
  - [645f984] Don't spawn metadata-proxy for non-isolated nets
  - [b464d89] Big Switch: Check for 'id' in port before lookup
  - [3116ffa] use TRUE in SQL for boolean var
  - [3520e66] call security_groups_member_updated in port_update
  - [50e1534] Don't allow user to set firewall rule with port and no protocol
  - [0061533] BSN: Add context to backend request for debugging
  - [6de6d61] Improve ODL ML2 Exception Handling
  - [2a4153d] Send network name and uuid to subnet create
  - [b5e3c9a] BSN: Allow concurrent reads to consistency DB
  - [b201432] Big Switch: Retry on 503 errors from backend
  - [f6c47ee] NSX: log request body to NSX as debug
  - [97d622a] Fix metadata agent's auth info caching
  - [255df45] NSX: Correct allowed_address_pair return value on create_port
  - [5bea041] Neutron should not use the neutronclient utils module for import_class
  - [d5314e2] Cisco N1kv plugin to send subtype on network profile creation
  - [f32d1ce] Pass object to policy when finding fields to strip
  - [8b5f6be] Call policy.init() once per API request
  - [9a6d811] Perform policy checks only once on list responses
  - [c48db90] Datacenter moid should not be tuple
  - [161d465] Allow unsharing a network used as gateway/floatingip
  - [9574a2f] Add support for router scheduling in Cisco N1kv Plugin
  - [6f54565] Fix func job hook script permission problems
  - [ea43103] Add hook scripts for the functional infra job
  - [8161cb7] Fixes Hyper-V agent issue on Hyper-V 2008 R2
  - [8e99cfd] Fixes Hyper-V issue due to ML2 RPC versioning
  - [69f9121] Ensure ip6tables are used only if ipv6 is enabled in kernel
  - [399b809] Remove explicit dependency on amqplib
  - [a872143] Clear entries in Cisco N1KV specific tables on rollback
  - [ad82fad] Verify ML2 type driver exists before calling del
  - [af2cc98] Big Switch: Only update hash header on success
  - [b1e5eec] Ignore variable column widths in ovsdb functional tests
  - [4a0210e] VMWare: don't notify on disassociate_floatingips()

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import eventlet
23
23
 
 
24
from oslo.config import cfg as q_conf
 
25
 
24
26
from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api
25
27
from neutron.api.rpc.agentnotifiers import l3_rpc_agent_api
26
28
from neutron.api.v2 import attributes
35
37
from neutron.db import dhcp_rpc_base
36
38
from neutron.db import external_net_db
37
39
from neutron.db import extraroute_db
38
 
from neutron.db import l3_db
 
40
from neutron.db import l3_agentschedulers_db
39
41
from neutron.db import l3_rpc_base
40
42
from neutron.db import portbindings_db
41
43
from neutron.extensions import portbindings
42
44
from neutron.extensions import providernet
 
45
from neutron.openstack.common import excutils
 
46
from neutron.openstack.common import importutils
43
47
from neutron.openstack.common import log as logging
44
48
from neutron.openstack.common import rpc
45
49
from neutron.openstack.common import uuidutils as uuidutils
78
82
class N1kvNeutronPluginV2(db_base_plugin_v2.NeutronDbPluginV2,
79
83
                          external_net_db.External_net_db_mixin,
80
84
                          extraroute_db.ExtraRoute_db_mixin,
81
 
                          l3_db.L3_NAT_db_mixin,
82
85
                          portbindings_db.PortBindingMixin,
83
86
                          n1kv_db_v2.NetworkProfile_db_mixin,
84
87
                          n1kv_db_v2.PolicyProfile_db_mixin,
85
88
                          network_db_v2.Credential_db_mixin,
86
 
                          agentschedulers_db.AgentSchedulerDbMixin):
 
89
                          l3_agentschedulers_db.L3AgentSchedulerDbMixin,
 
90
                          agentschedulers_db.DhcpAgentSchedulerDbMixin):
87
91
 
88
92
    """
89
93
    Implement the Neutron abstractions using Cisco Nexus1000V.
99
103
    supported_extension_aliases = ["provider", "agent",
100
104
                                   "n1kv", "network_profile",
101
105
                                   "policy_profile", "external-net", "router",
102
 
                                   "binding", "credential"]
 
106
                                   "binding", "credential",
 
107
                                   "l3_agent_scheduler",
 
108
                                   "dhcp_agent_scheduler"]
103
109
 
104
110
    def __init__(self, configfile=None):
105
111
        """
119
125
        c_cred.Store.initialize()
120
126
        self._setup_vsm()
121
127
        self._setup_rpc()
 
128
        self.network_scheduler = importutils.import_object(
 
129
            q_conf.CONF.network_scheduler_driver
 
130
        )
 
131
        self.router_scheduler = importutils.import_object(
 
132
            q_conf.CONF.router_scheduler_driver
 
133
        )
122
134
 
123
135
    def _setup_rpc(self):
124
136
        # RPC support
967
979
                self._send_create_network_request(context, net, segment_pairs)
968
980
        except(cisco_exceptions.VSMError,
969
981
               cisco_exceptions.VSMConnectionFailed):
970
 
            super(N1kvNeutronPluginV2, self).delete_network(context, net['id'])
 
982
            with excutils.save_and_reraise_exception():
 
983
                self._delete_network_db(context, net['id'])
971
984
        else:
972
985
            LOG.debug(_("Created network: %s"), net['id'])
973
986
            return net
1039
1052
        """
1040
1053
        session = context.session
1041
1054
        with session.begin(subtransactions=True):
1042
 
            binding = n1kv_db_v2.get_network_binding(session, id)
1043
1055
            network = self.get_network(context, id)
1044
1056
            if n1kv_db_v2.is_trunk_member(session, id):
1045
1057
                msg = _("Cannot delete network '%s' "
1049
1061
                msg = _("Cannot delete network '%s' that is a member of a "
1050
1062
                        "multi-segment network") % network['name']
1051
1063
                raise n_exc.InvalidInput(error_message=msg)
 
1064
            self._delete_network_db(context, id)
 
1065
            # the network_binding record is deleted via cascade from
 
1066
            # the network record, so explicit removal is not necessary
 
1067
        self._send_delete_network_request(context, network)
 
1068
        LOG.debug("Deleted network: %s", id)
 
1069
 
 
1070
    def _delete_network_db(self, context, id):
 
1071
        session = context.session
 
1072
        with session.begin(subtransactions=True):
 
1073
            binding = n1kv_db_v2.get_network_binding(session, id)
1052
1074
            if binding.network_type == c_const.NETWORK_TYPE_OVERLAY:
1053
1075
                n1kv_db_v2.release_vxlan(session, binding.segmentation_id)
1054
1076
            elif binding.network_type == c_const.NETWORK_TYPE_VLAN:
1055
1077
                n1kv_db_v2.release_vlan(session, binding.physical_network,
1056
1078
                                        binding.segmentation_id)
1057
1079
            super(N1kvNeutronPluginV2, self).delete_network(context, id)
1058
 
            # the network_binding record is deleted via cascade from
1059
 
            # the network record, so explicit removal is not necessary
1060
 
        self._send_delete_network_request(context, network)
1061
 
        LOG.debug(_("Deleted network: %s"), id)
1062
1080
 
1063
1081
    def get_network(self, context, id, fields=None):
1064
1082
        """
1113
1131
        """
1114
1132
        p_profile = None
1115
1133
        port_count = None
 
1134
        vm_network = None
1116
1135
        vm_network_name = None
1117
1136
        profile_id_set = False
1118
1137
 
1119
1138
        # Set the network policy profile id for auto generated L3/DHCP ports
1120
1139
        if ('device_id' in port['port'] and port['port']['device_owner'] in
1121
 
            [constants.DEVICE_OWNER_DHCP, constants.DEVICE_OWNER_ROUTER_INTF]):
 
1140
            [constants.DEVICE_OWNER_DHCP, constants.DEVICE_OWNER_ROUTER_INTF,
 
1141
             constants.DEVICE_OWNER_ROUTER_GW,
 
1142
             constants.DEVICE_OWNER_FLOATINGIP]):
1122
1143
            p_profile_name = c_conf.CISCO_N1K.network_node_policy_profile
1123
1144
            p_profile = self._get_policy_profile_by_name(p_profile_name)
1124
1145
            if p_profile:
1156
1177
                                               profile_id,
1157
1178
                                               pt['network_id'])
1158
1179
                port_count = 1
1159
 
                n1kv_db_v2.add_vm_network(context.session,
1160
 
                                          vm_network_name,
1161
 
                                          profile_id,
1162
 
                                          pt['network_id'],
1163
 
                                          port_count)
 
1180
                vm_network = n1kv_db_v2.add_vm_network(context.session,
 
1181
                                                       vm_network_name,
 
1182
                                                       profile_id,
 
1183
                                                       pt['network_id'],
 
1184
                                                       port_count)
1164
1185
            else:
1165
1186
                # Update port count of the VM network.
1166
1187
                vm_network_name = vm_network['name']
1182
1203
                                           vm_network_name)
1183
1204
        except(cisco_exceptions.VSMError,
1184
1205
               cisco_exceptions.VSMConnectionFailed):
1185
 
            super(N1kvNeutronPluginV2, self).delete_port(context, pt['id'])
 
1206
            with excutils.save_and_reraise_exception():
 
1207
                self._delete_port_db(context, pt, vm_network)
1186
1208
        else:
1187
1209
            LOG.debug(_("Created port: %s"), pt)
1188
1210
            return pt
1221
1243
            vm_network = n1kv_db_v2.get_vm_network(context.session,
1222
1244
                                                   port[n1kv.PROFILE_ID],
1223
1245
                                                   port['network_id'])
 
1246
            router_ids = self.disassociate_floatingips(
 
1247
                context, id, do_notify=False)
 
1248
            self._delete_port_db(context, port, vm_network)
 
1249
 
 
1250
        # now that we've left db transaction, we are safe to notify
 
1251
        self.notify_routers_updated(context, router_ids)
 
1252
        self._send_delete_port_request(context, port, vm_network)
 
1253
 
 
1254
    def _delete_port_db(self, context, port, vm_network):
 
1255
        with context.session.begin(subtransactions=True):
1224
1256
            vm_network['port_count'] -= 1
1225
1257
            n1kv_db_v2.update_vm_network_port_count(context.session,
1226
1258
                                                    vm_network['name'],
1229
1261
                n1kv_db_v2.delete_vm_network(context.session,
1230
1262
                                             port[n1kv.PROFILE_ID],
1231
1263
                                             port['network_id'])
1232
 
            router_ids = self.disassociate_floatingips(
1233
 
                context, id, do_notify=False)
1234
 
            super(N1kvNeutronPluginV2, self).delete_port(context, id)
1235
 
 
1236
 
        # now that we've left db transaction, we are safe to notify
1237
 
        self.notify_routers_updated(context, router_ids)
1238
 
 
1239
 
        self._send_delete_port_request(context, port, vm_network)
 
1264
            super(N1kvNeutronPluginV2, self).delete_port(context, port['id'])
1240
1265
 
1241
1266
    def get_port(self, context, id, fields=None):
1242
1267
        """
1289
1314
            self._send_create_subnet_request(context, sub)
1290
1315
        except(cisco_exceptions.VSMError,
1291
1316
               cisco_exceptions.VSMConnectionFailed):
1292
 
            super(N1kvNeutronPluginV2, self).delete_subnet(context, sub['id'])
 
1317
            with excutils.save_and_reraise_exception():
 
1318
                super(N1kvNeutronPluginV2,
 
1319
                      self).delete_subnet(context, sub['id'])
1293
1320
        else:
1294
1321
            LOG.debug(_("Created subnet: %s"), sub['id'])
1295
1322
            return sub
1380
1407
                                                      context.tenant_id)
1381
1408
        except(cisco_exceptions.VSMError,
1382
1409
               cisco_exceptions.VSMConnectionFailed):
1383
 
            n1kv_db_v2.delete_profile_binding(context.session,
1384
 
                                              context.tenant_id,
1385
 
                                              net_p['id'])
 
1410
            with excutils.save_and_reraise_exception():
 
1411
                super(N1kvNeutronPluginV2,
 
1412
                      self).delete_network_profile(context, net_p['id'])
1386
1413
        try:
1387
1414
            self._send_create_network_profile_request(context, net_p)
1388
1415
        except(cisco_exceptions.VSMError,
1389
1416
               cisco_exceptions.VSMConnectionFailed):
1390
 
            n1kv_db_v2.delete_profile_binding(context.session,
1391
 
                                              context.tenant_id,
1392
 
                                              net_p['id'])
1393
 
            self._send_delete_logical_network_request(net_p)
 
1417
            with excutils.save_and_reraise_exception():
 
1418
                super(N1kvNeutronPluginV2,
 
1419
                      self).delete_network_profile(context, net_p['id'])
 
1420
                self._send_delete_logical_network_request(net_p)
1394
1421
        return net_p
1395
1422
 
1396
1423
    def delete_network_profile(self, context, id):
1423
1450
                                            network_profile))
1424
1451
        self._send_update_network_profile_request(net_p)
1425
1452
        return net_p
 
1453
 
 
1454
    def create_router(self, context, router):
 
1455
        """
 
1456
        Handle creation of router.
 
1457
 
 
1458
        Schedule router to L3 agent as part of the create handling.
 
1459
        :param context: neutron api request context
 
1460
        :param router: router dictionary
 
1461
        :returns: router object
 
1462
        """
 
1463
        session = context.session
 
1464
        with session.begin(subtransactions=True):
 
1465
            rtr = (super(N1kvNeutronPluginV2, self).
 
1466
                   create_router(context, router))
 
1467
            LOG.debug(_("Scheduling router %s"), rtr['id'])
 
1468
            self.schedule_router(context, rtr['id'])
 
1469
        return rtr