]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Jointly load ExternalNetwork with Network
authorSalvatore Orlando <salv.orlando@gmail.com>
Tue, 7 May 2013 22:07:17 +0000 (00:07 +0200)
committerSalvatore Orlando <salv.orlando@gmail.com>
Mon, 1 Jul 2013 15:38:54 +0000 (17:38 +0200)
Bug 1177572

This patch leverages the same approach as bug 1174111 for avoiding
loading ExternalNetwork element from db for each network element.
make_network_dict, _extend_network_dict_l3 are refactored accordingly.

Also, this patch sligthly alters the logic of process_l3_network_create
and process_l3_network_update as these methods assumed
_extend_network_dict_l3 was always executed before retuerning.

Finally, calls to get_network and get_networks in plugins which only
extended the response with l3 attributes have been completely removed.

Change-Id: I3b4c28ec0c78f731a534c2b66150d529fd797e72

16 files changed:
quantum/db/db_base_plugin_v2.py
quantum/db/l3_db.py
quantum/plugins/bigswitch/plugin.py
quantum/plugins/brocade/QuantumPlugin.py
quantum/plugins/hyperv/hyperv_quantum_plugin.py
quantum/plugins/linuxbridge/lb_quantum_plugin.py
quantum/plugins/metaplugin/meta_quantum_plugin.py
quantum/plugins/midonet/plugin.py
quantum/plugins/ml2/plugin.py
quantum/plugins/mlnx/mlnx_plugin.py
quantum/plugins/nec/nec_plugin.py
quantum/plugins/nicira/QuantumPlugin.py
quantum/plugins/openvswitch/ovs_quantum_plugin.py
quantum/plugins/ryu/ryu_quantum_plugin.py
quantum/tests/unit/metaplugin/fake_plugin.py
quantum/tests/unit/test_l3_plugin.py

index 3860a5b6cf3a373d943edaf578ab6a7597e27052..64de1b1530d6af84057b927b0bad272d89f4f718 100644 (file)
@@ -895,7 +895,8 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2,
             tenant_ids.pop() != original.tenant_id):
             raise q_exc.InvalidSharedSetting(network=original.name)
 
-    def _make_network_dict(self, network, fields=None):
+    def _make_network_dict(self, network, fields=None,
+                           process_extensions=True):
         res = {'id': network['id'],
                'name': network['name'],
                'tenant_id': network['tenant_id'],
@@ -904,7 +905,11 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2,
                'shared': network['shared'],
                'subnets': [subnet['id']
                            for subnet in network['subnets']]}
-
+        # Call auxiliary extend functions, if any
+        if process_extensions:
+            for func in self._dict_extend_functions.get(attributes.NETWORKS,
+                                                        []):
+                func(self, res, network)
         return self._fields(res, fields)
 
     def _make_subnet_dict(self, subnet, fields=None):
index 22fcf07f3861cb56bf1891cff46b82c98662badd..dca17b89313fe7bf26fa325a050eb947eeef380c 100644 (file)
@@ -64,6 +64,13 @@ class ExternalNetwork(model_base.BASEV2):
                            sa.ForeignKey('networks.id', ondelete="CASCADE"),
                            primary_key=True)
 
+    # Add a relationship to the Network model in order to instruct
+    # SQLAlchemy to eagerly load this association
+    network = orm.relationship(
+        models_v2.Network,
+        backref=orm.backref("external", lazy='joined',
+                            uselist=False, cascade='delete'))
+
 
 class FloatingIP(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
     """Represents a floating IP address.
@@ -214,8 +221,8 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
         # network_id attribute is required by API, so it must be present
         network_id = info['network_id'] if info else None
         if network_id:
-            self._get_network(context, network_id)
-            if not self._network_is_external(context, network_id):
+            network_db = self._get_network(context, network_id)
+            if not network_db.external:
                 msg = _("Network %s is not a valid external "
                         "network") % network_id
                 raise q_exc.BadRequest(resource='router', msg=msg)
@@ -786,12 +793,17 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
         except exc.NoResultFound:
             return False
 
-    def _extend_network_dict_l3(self, context, network):
-        network[l3.EXTERNAL] = self._network_is_external(
-            context, network['id'])
+    def _extend_network_dict_l3(self, network_res, network_db):
+        # Comparing with None for converting uuid into bool
+        network_res[l3.EXTERNAL] = network_db.external is not None
+        return network_res
+
+    # Register dict extend functions for networks
+    db_base_plugin_v2.QuantumDbPluginV2.register_dict_extend_funcs(
+        attributes.NETWORKS, [_extend_network_dict_l3])
 
-    def _process_l3_create(self, context, net_data, net_id):
-        external = net_data.get(l3.EXTERNAL)
+    def _process_l3_create(self, context, net_data, req_data):
+        external = req_data.get(l3.EXTERNAL)
         external_set = attributes.is_attr_set(external)
 
         if not external_set:
@@ -799,33 +811,35 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
 
         if external:
             # expects to be called within a plugin's session
-            context.session.add(ExternalNetwork(network_id=net_id))
+            context.session.add(ExternalNetwork(network_id=net_data['id']))
+        net_data[l3.EXTERNAL] = external
 
-    def _process_l3_update(self, context, net_data, net_id):
+    def _process_l3_update(self, context, net_data, req_data):
 
-        new_value = net_data.get(l3.EXTERNAL)
+        new_value = req_data.get(l3.EXTERNAL)
+        net_id = net_data['id']
         if not attributes.is_attr_set(new_value):
             return
 
-        existing_value = self._network_is_external(context, net_id)
-
-        if existing_value == new_value:
+        if net_data.get(l3.EXTERNAL) == new_value:
             return
 
         if new_value:
             context.session.add(ExternalNetwork(network_id=net_id))
+            net_data[l3.EXTERNAL] = True
         else:
             # must make sure we do not have any external gateway ports
             # (and thus, possible floating IPs) on this network before
             # allow it to be update to external=False
             port = context.session.query(models_v2.Port).filter_by(
                 device_owner=DEVICE_OWNER_ROUTER_GW,
-                network_id=net_id).first()
+                network_id=net_data['id']).first()
             if port:
                 raise l3.ExternalNetworkInUse(net_id=net_id)
 
             context.session.query(ExternalNetwork).filter_by(
                 network_id=net_id).delete()
+            net_data[l3.EXTERNAL] = False
 
     def _filter_nets_l3(self, context, nets, filters):
         vals = filters and filters.get('router:external', [])
index b9a6335e3714be314fe870cf4aeb991be607796e..5476993a4757d3c0cbabf7fa1c66293017ce99ad 100644 (file)
@@ -414,8 +414,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
             # create network in DB
             new_net = super(QuantumRestProxyV2, self).create_network(context,
                                                                      network)
-            self._process_l3_create(context, network['network'], new_net['id'])
-            self._extend_network_dict_l3(context, new_net)
+            self._process_l3_create(context, new_net, network['network'])
 
         # create network on the network controller
         try:
@@ -471,8 +470,7 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
             new_net = super(QuantumRestProxyV2, self).update_network(context,
                                                                      net_id,
                                                                      network)
-            self._process_l3_update(context, network['network'], net_id)
-            self._extend_network_dict_l3(context, new_net)
+            self._process_l3_update(context, new_net, network['network'])
 
         # update network on network controller
         try:
@@ -530,27 +528,6 @@ class QuantumRestProxyV2(db_base_plugin_v2.QuantumDbPluginV2,
                         "network: %s"), e.message)
             raise
 
-    def get_network(self, context, id, fields=None):
-        session = context.session
-        with session.begin(subtransactions=True):
-            net = super(QuantumRestProxyV2, self).get_network(context,
-                                                              id, None)
-            self._extend_network_dict_l3(context, net)
-        return self._fields(net, fields)
-
-    def get_networks(self, context, filters=None, fields=None,
-                     sorts=None,
-                     limit=None, marker=None, page_reverse=False):
-        session = context.session
-        with session.begin(subtransactions=True):
-            nets = super(QuantumRestProxyV2,
-                         self).get_networks(context, filters, None, sorts,
-                                            limit, marker, page_reverse)
-            for net in nets:
-                self._extend_network_dict_l3(context, net)
-
-        return [self._fields(net, fields) for net in nets]
-
     def create_port(self, context, port):
         """Create a port, which is a connection point of a device
         (e.g., a VM NIC) to attach to a L2 Quantum network.
index cbd46a7ca109c229cdb5dbe6c647ac7814388aa7..1495088db4a43c1f2955b9e5e835c84d64edb515 100644 (file)
@@ -280,8 +280,7 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                 raise Exception("Brocade plugin raised exception, check logs")
 
             brocade_db.create_network(context, net_uuid, vlan_id)
-            self._process_l3_create(context, network['network'], net['id'])
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_create(context, net, network['network'])
 
         LOG.info(_("Allocated vlan (%d) from the pool"), vlan_id)
         return net
@@ -333,31 +332,9 @@ class BrocadePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(BrocadePluginV2, self).update_network(context, id,
                                                               network)
-            self._process_l3_update(context, network['network'], id)
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_update(context, net, network['network'])
         return net
 
-    def get_network(self, context, id, fields=None):
-        session = context.session
-        with session.begin(subtransactions=True):
-            net = super(BrocadePluginV2, self).get_network(context,
-                                                           id, None)
-            self._extend_network_dict_l3(context, net)
-
-        return self._fields(net, fields)
-
-    def get_networks(self, context, filters=None, fields=None,
-                     sorts=None, limit=None, marker=None, page_reverse=False):
-        session = context.session
-        with session.begin(subtransactions=True):
-            nets = super(BrocadePluginV2,
-                         self).get_networks(context, filters, None, sorts,
-                                            limit, marker, page_reverse)
-            for net in nets:
-                self._extend_network_dict_l3(context, net)
-
-        return [self._fields(net, fields) for net in nets]
-
     def create_port(self, context, port):
         """Create logical port on the switch."""
 
index ab7459396f0e10fd3a8d729481d317b1ac8fae47..934fa1179c9c73076c4f0d159604357d4c9fbb46 100644 (file)
@@ -239,9 +239,8 @@ class HyperVQuantumPlugin(db_base_plugin_v2.QuantumDbPluginV2,
                 session, net['id'], network_type,
                 physical_network, segmentation_id)
 
-            self._process_l3_create(context, network['network'], net['id'])
+            self._process_l3_create(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
 
             LOG.debug(_("Created network: %s"), net['id'])
             return net
@@ -260,9 +259,8 @@ class HyperVQuantumPlugin(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(HyperVQuantumPlugin, self).update_network(context, id,
                                                                   network)
-            self._process_l3_update(context, network['network'], id)
+            self._process_l3_update(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
             return net
 
     def delete_network(self, context, id):
@@ -279,7 +277,6 @@ class HyperVQuantumPlugin(db_base_plugin_v2.QuantumDbPluginV2,
     def get_network(self, context, id, fields=None):
         net = super(HyperVQuantumPlugin, self).get_network(context, id, None)
         self._extend_network_dict_provider(context, net)
-        self._extend_network_dict_l3(context, net)
         return self._fields(net, fields)
 
     def get_networks(self, context, filters=None, fields=None):
@@ -287,7 +284,6 @@ class HyperVQuantumPlugin(db_base_plugin_v2.QuantumDbPluginV2,
             context, filters, None)
         for net in nets:
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
 
         return [self._fields(net, fields) for net in nets]
 
index f7a4310dc6554826fbe253f46cce3ba6120bd1ef..a54f1d0182495b6d745a1a668d9c2c547eae9e42 100644 (file)
@@ -389,9 +389,8 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                                                                   network)
             db.add_network_binding(session, net['id'],
                                    physical_network, vlan_id)
-            self._process_l3_create(context, network['network'], net['id'])
+            self._process_l3_create(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
             # note - exception will rollback entire transaction
         return net
 
@@ -402,9 +401,8 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(LinuxBridgePluginV2, self).update_network(context, id,
                                                                   network)
-            self._process_l3_update(context, network['network'], id)
+            self._process_l3_update(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
         return net
 
     def delete_network(self, context, id):
@@ -425,7 +423,6 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             net = super(LinuxBridgePluginV2, self).get_network(context,
                                                                id, None)
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
         return self._fields(net, fields)
 
     def get_networks(self, context, filters=None, fields=None,
@@ -437,7 +434,6 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                                             limit, marker, page_reverse)
             for net in nets:
                 self._extend_network_dict_provider(context, net)
-                self._extend_network_dict_l3(context, net)
 
         return [self._fields(net, fields) for net in nets]
 
index 4732b58402dd4e227ec6e7efc5ebd78b994e557e..fe428c592824714bb73acd7983bea79a25df374f 100644 (file)
@@ -160,8 +160,7 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         with context.session.begin(subtransactions=True):
             net = plugin.create_network(context, network)
             if not self._is_l3_plugin(plugin):
-                self._process_l3_create(context, network['network'], net['id'])
-                self._extend_network_dict_l3(context, net)
+                self._process_l3_create(context, net, network['network'])
             LOG.debug(_("Created network: %(net_id)s with flavor "
                         "%(flavor)s"), {'net_id': net['id'], 'flavor': flavor})
             try:
@@ -182,8 +181,7 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         with context.session.begin(subtransactions=True):
             net = plugin.update_network(context, id, network)
             if not self._is_l3_plugin(plugin):
-                self._process_l3_update(context, network['network'], id)
-                self._extend_network_dict_l3(context, net)
+                self._process_l3_update(context, net, network['network'])
         return net
 
     def delete_network(self, context, id):
@@ -196,8 +194,6 @@ class MetaPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         plugin = self._get_plugin(flavor)
         net = plugin.get_network(context, id, fields)
         net['id'] = id
-        if not fields or 'router:external' in fields:
-            self._extend_network_dict_l3(context, net)
         if not fields or FLAVOR_NETWORK in fields:
             self._extend_network_dict(context, net)
         if fields and 'id' not in fields:
index 1c8d3e1186f6757556f73613ada415f32227bc23..e485231965454cdc14d7b3fe18c3b8b06391cf7b 100644 (file)
@@ -114,7 +114,6 @@ class MidonetPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                                     prefix)
 
             # For external network, link the bridge to the provider router.
-            self._extend_network_dict_l3(context, net)
             if net['router:external']:
                 gateway_ip = sn_entry['gateway_ip']
                 network_address, length = sn_entry['cidr'].split('/')
@@ -142,7 +141,6 @@ class MidonetPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         self.client.delete_dhcp(bridge)
 
         # If the network is external, clean up routes, links, ports.
-        self._extend_network_dict_l3(context, net)
         if net['router:external']:
             self.client.unlink_bridge_from_provider_router(
                 bridge, self.provider_router)
@@ -176,8 +174,7 @@ class MidonetPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             net = super(MidonetPluginV2, self).create_network(context, network)
 
             # to handle l3 related data in DB
-            self._process_l3_create(context, network['network'], net['id'])
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_create(context, net, network['network'])
         LOG.debug(_("MidonetPluginV2.create_network exiting: net=%r"), net)
         return net
 
@@ -203,7 +200,6 @@ class MidonetPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                 context, id, network)
             self.client.update_bridge(id, net['name'])
 
-        self._extend_network_dict_l3(context, net)
         LOG.debug(_("MidonetPluginV2.update_network exiting: net=%r"), net)
         return net
 
@@ -215,29 +211,11 @@ class MidonetPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         LOG.debug(_("MidonetPluginV2.get_network called: id=%(id)r, "
                     "fields=%(fields)r"), {'id': id, 'fields': fields})
 
-        # NOTE: Get network data with all fields (fields=None) for
-        #       _extend_network_dict_l3() method, which needs 'id' field
-        qnet = super(MidonetPluginV2, self).get_network(context, id, None)
+        qnet = super(MidonetPluginV2, self).get_network(context, id, fields)
         self.client.get_bridge(id)
 
-        self._extend_network_dict_l3(context, qnet)
         LOG.debug(_("MidonetPluginV2.get_network exiting: qnet=%r"), qnet)
-        return self._fields(qnet, fields)
-
-    def get_networks(self, context, filters=None, fields=None):
-        """List quantum networks and verify that all exist in MidoNet."""
-        LOG.debug(_("MidonetPluginV2.get_networks called: "
-                    "filters=%(filters)r, fields=%(fields)r"),
-                  {'filters': filters, 'fields': fields})
-
-        # NOTE: Get network data with all fields (fields=None) for
-        #       _extend_network_dict_l3() method, which needs 'id' field
-        qnets = super(MidonetPluginV2, self).get_networks(context, filters,
-                                                          None)
-        for n in qnets:
-            self._extend_network_dict_l3(context, n)
-
-        return [self._fields(net, fields) for net in qnets]
+        return qnet
 
     def delete_network(self, context, id):
         """Delete a network and its corresponding MidoNet bridge."""
index 55f4cff4cfdbbd7de9ea53bda54bef78cd4771b7..f375f464be09a996021eb51e33e95a2e0a12748e 100644 (file)
@@ -196,12 +196,11 @@ class Ml2Plugin(db_base_plugin_v2.QuantumDbPluginV2,
                 segment = self.type_manager.allocate_tenant_segment(session)
             result = super(Ml2Plugin, self).create_network(context, network)
             id = result['id']
-            self._process_l3_create(context, attrs, id)
+            self._process_l3_create(context, result, attrs)
             # REVISIT(rkukura): Consider moving all segment management
             # to TypeManager.
             db.add_network_segment(session, id, segment)
             self._extend_network_dict_provider(context, result)
-            self._extend_network_dict_l3(context, result)
 
         return result
 
@@ -212,9 +211,8 @@ class Ml2Plugin(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             result = super(Ml2Plugin, self).update_network(context, id,
                                                            network)
-            self._process_l3_update(context, network['network'], id)
+            self._process_l3_update(context, result, network['network'])
             self._extend_network_dict_provider(context, result)
-            self._extend_network_dict_l3(context, result)
 
         return result
 
@@ -223,7 +221,6 @@ class Ml2Plugin(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             result = super(Ml2Plugin, self).get_network(context, id, None)
             self._extend_network_dict_provider(context, result)
-            self._extend_network_dict_l3(context, result)
 
         return self._fields(result, fields)
 
@@ -236,7 +233,6 @@ class Ml2Plugin(db_base_plugin_v2.QuantumDbPluginV2,
                                             limit, marker, page_reverse)
             for net in nets:
                 self._extend_network_dict_provider(context, net)
-                self._extend_network_dict_l3(context, net)
 
             nets = self._filter_nets_provider(context, nets, filters)
             nets = self._filter_nets_l3(context, nets, filters)
index 3743da2d9a194852936e3353ec1195ec2a56e2e4..8ebf3248e96896d76af021bbcbaaf6c10172553c 100644 (file)
@@ -265,9 +265,8 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.QuantumDbPluginV2,
                                    physical_network,
                                    vlan_id)
 
-            self._process_l3_create(context, network['network'], net['id'])
+            self._process_l3_create(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
             # note - exception will rollback entire transaction
             LOG.debug(_("Created network: %s"), net['id'])
             return net
@@ -279,9 +278,8 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.QuantumDbPluginV2,
             net = super(MellanoxEswitchPlugin, self).update_network(context,
                                                                     net_id,
                                                                     network)
-            self._process_l3_update(context, network['network'], net_id)
+            self._process_l3_update(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
         return net
 
     def delete_network(self, context, net_id):
@@ -306,7 +304,6 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.QuantumDbPluginV2,
                                                                  net_id,
                                                                  None)
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
         return self._fields(net, fields)
 
     def get_networks(self, context, filters=None, fields=None):
@@ -317,7 +314,6 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.QuantumDbPluginV2,
                                                                    None)
             for net in nets:
                 self._extend_network_dict_provider(context, net)
-                self._extend_network_dict_l3(context, net)
             # TODO(rkukura): Filter on extended provider attributes.
             nets = self._filter_nets_l3(context, nets, filters)
         return [self._fields(net, fields) for net in nets]
index 9a5e9b261f0ffd167f72d8aaee527d04f8953793..e3f18bedfc5a6d987155d83569436e51fb7dc780 100644 (file)
@@ -236,8 +236,7 @@ class NECPluginV2(nec_plugin_base.NECPluginV2Base,
 
         with context.session.begin(subtransactions=True):
             new_net = super(NECPluginV2, self).create_network(context, network)
-            self._process_l3_create(context, network['network'], new_net['id'])
-            self._extend_network_dict_l3(context, new_net)
+            self._process_l3_create(context, new_net, network['network'])
             self._update_resource_status(context, "network", new_net['id'],
                                          OperationalStatus.BUILD)
 
@@ -271,8 +270,7 @@ class NECPluginV2(nec_plugin_base.NECPluginV2Base,
             old_net = super(NECPluginV2, self).get_network(context, id)
             new_net = super(NECPluginV2, self).update_network(context, id,
                                                               network)
-            self._process_l3_update(context, network['network'], id)
-            self._extend_network_dict_l3(context, new_net)
+            self._process_l3_update(context, new_net, network['network'])
 
         changed = (old_net['admin_state_up'] is not new_net['admin_state_up'])
         if changed and not new_net['admin_state_up']:
@@ -359,17 +357,6 @@ class NECPluginV2(nec_plugin_base.NECPluginV2Base,
                 reason = _("delete_ofc_tenant() failed due to %s") % exc
                 LOG.warn(reason)
 
-    def get_network(self, context, id, fields=None):
-        net = super(NECPluginV2, self).get_network(context, id, None)
-        self._extend_network_dict_l3(context, net)
-        return self._fields(net, fields)
-
-    def get_networks(self, context, filters=None, fields=None):
-        nets = super(NECPluginV2, self).get_networks(context, filters, None)
-        for net in nets:
-            self._extend_network_dict_l3(context, net)
-        return [self._fields(net, fields) for net in nets]
-
     def _extend_port_dict_binding(self, context, port):
         port[portbindings.VIF_TYPE] = portbindings.VIF_TYPE_OVS
         port[portbindings.CAPABILITIES] = {
index bd8258625122a3565b519c019cb466a1bc11ae44..d66df43c299e00323533e34de2033b0ecb25a9b9 100644 (file)
@@ -813,7 +813,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             # Process port security extension
             self._process_network_create_port_security(context, net_data)
             # DB Operations for setting the network as external
-            self._process_l3_create(context, net_data, new_net['id'])
+            self._process_l3_create(context, new_net, net_data)
             # Process QoS queue extension
             if network['network'].get(ext_qos.QUEUE):
                 new_net[ext_qos.QUEUE] = network['network'][ext_qos.QUEUE]
@@ -831,7 +831,6 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                 self._extend_network_dict_provider(context, new_net,
                                                    net_binding)
             self._extend_network_port_security_dict(context, new_net)
-            self._extend_network_dict_l3(context, new_net)
         self.schedule_network(context, new_net)
         return new_net
 
@@ -886,7 +885,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             # goto to the plugin DB and fetch the network
             network = self._get_network(context, id)
             # if the network is external, do not go to NVP
-            if not self._network_is_external(context, id):
+            if not network.external:
                 # verify the fabric status of the corresponding
                 # logical switch(es) in nvp
                 try:
@@ -923,7 +922,6 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             net_result = self._make_network_dict(network, None)
             self._extend_network_dict_provider(context, net_result)
             self._extend_network_port_security_dict(context, net_result)
-            self._extend_network_dict_l3(context, net_result)
             self._extend_network_qos_queue(context, net_result)
         return self._fields(net_result, fields)
 
@@ -936,7 +934,6 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             for net in quantum_lswitches:
                 self._extend_network_dict_provider(context, net)
                 self._extend_network_port_security_dict(context, net)
-                self._extend_network_dict_l3(context, net)
                 self._extend_network_qos_queue(context, net)
 
             tenant_ids = filters and filters.get('tenant_id') or None
@@ -1029,9 +1026,8 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                 self._delete_network_queue_mapping(context, id)
                 self._process_network_queue_mapping(context, net)
             self._extend_network_port_security_dict(context, net)
-            self._process_l3_update(context, network['network'], id)
+            self._process_l3_update(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
             self._extend_network_qos_queue(context, net)
         return net
 
@@ -1428,7 +1424,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                               else None)
                 if network_id:
                     ext_net = self._get_network(context, network_id)
-                    if not self._network_is_external(context, network_id):
+                    if not ext_net.external:
                         msg = (_("Network '%s' is not a valid external "
                                  "network") % network_id)
                         raise q_exc.BadRequest(resource='router', msg=msg)
@@ -1472,7 +1468,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                           else None)
             if network_id:
                 ext_net = self._get_network(context, network_id)
-                if not self._network_is_external(context, network_id):
+                if not ext_net.external:
                     msg = (_("Network '%s' is not a valid external "
                              "network") % network_id)
                     raise q_exc.BadRequest(resource='router', msg=msg)
index d5b0a4c2600482a1f9519678ee626229d324574a..a7bd265bed01237aba6f648400623519cead73ae 100644 (file)
@@ -456,9 +456,8 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             ovs_db_v2.add_network_binding(session, net['id'], network_type,
                                           physical_network, segmentation_id)
 
-            self._process_l3_create(context, network['network'], net['id'])
+            self._process_l3_create(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
             # note - exception will rollback entire transaction
         LOG.debug(_("Created network: %s"), net['id'])
         return net
@@ -470,9 +469,8 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(OVSQuantumPluginV2, self).update_network(context, id,
                                                                  network)
-            self._process_l3_update(context, network['network'], id)
+            self._process_l3_update(context, net, network['network'])
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
         return net
 
     def delete_network(self, context, id):
@@ -498,7 +496,6 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             net = super(OVSQuantumPluginV2, self).get_network(context,
                                                               id, None)
             self._extend_network_dict_provider(context, net)
-            self._extend_network_dict_l3(context, net)
         return self._fields(net, fields)
 
     def get_networks(self, context, filters=None, fields=None,
@@ -511,7 +508,6 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
                                             limit, marker, page_reverse)
             for net in nets:
                 self._extend_network_dict_provider(context, net)
-                self._extend_network_dict_l3(context, net)
 
         return [self._fields(net, fields) for net in nets]
 
index 40ee96cff18f677d6fa0405dcc38be62b83427b7..c487098b8cf3fe70dd17311f67e793150105ce57 100644 (file)
@@ -157,8 +157,7 @@ class RyuQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
 
             net = super(RyuQuantumPluginV2, self).create_network(context,
                                                                  network)
-            self._process_l3_create(context, network['network'], net['id'])
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_create(context, net, network['network'])
 
             tunnel_key = self.tunnel_key.allocate(session, net['id'])
             try:
@@ -174,8 +173,7 @@ class RyuQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(RyuQuantumPluginV2, self).update_network(context, id,
                                                                  network)
-            self._process_l3_update(context, network['network'], id)
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_update(context, net, network['network'])
         return net
 
     def delete_network(self, context, id):
@@ -185,19 +183,6 @@ class RyuQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             self.tunnel_key.delete(session, id)
             super(RyuQuantumPluginV2, self).delete_network(context, id)
 
-    def get_network(self, context, id, fields=None):
-        net = super(RyuQuantumPluginV2, self).get_network(context, id, None)
-        self._extend_network_dict_l3(context, net)
-        return self._fields(net, fields)
-
-    def get_networks(self, context, filters=None, fields=None):
-        nets = super(RyuQuantumPluginV2, self).get_networks(context, filters,
-                                                            None)
-        for net in nets:
-            self._extend_network_dict_l3(context, net)
-
-        return [self._fields(net, fields) for net in nets]
-
     def create_port(self, context, port):
         session = context.session
         with session.begin(subtransactions=True):
index 2dac164379b865d50e3cca7e7837ee88987356d7..e8d9fcb09ee9ac36896e6a016bc5003b0d023d9b 100644 (file)
@@ -29,8 +29,7 @@ class Fake1(db_base_plugin_v2.QuantumDbPluginV2,
         session = context.session
         with session.begin(subtransactions=True):
             net = super(Fake1, self).create_network(context, network)
-            self._process_l3_create(context, network['network'], net['id'])
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_create(context, net, network['network'])
         return net
 
     def update_network(self, context, id, network):
@@ -38,8 +37,7 @@ class Fake1(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(Fake1, self).update_network(context, id,
                                                     network)
-            self._process_l3_update(context, network['network'], id)
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_update(context, net, network['network'])
         return net
 
     def delete_network(self, context, id):
index c91929089f0887caf2a77c9e54bf590f86a4bc41..5f5a3ab8eb50a20724e7d4f77b1407f7d0e6f166 100644 (file)
@@ -268,8 +268,7 @@ class TestL3NatPlugin(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(TestL3NatPlugin, self).create_network(context,
                                                               network)
-            self._process_l3_create(context, network['network'], net['id'])
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_create(context, net, network['network'])
         return net
 
     def update_network(self, context, id, network):
@@ -278,30 +277,9 @@ class TestL3NatPlugin(db_base_plugin_v2.QuantumDbPluginV2,
         with session.begin(subtransactions=True):
             net = super(TestL3NatPlugin, self).update_network(context, id,
                                                               network)
-            self._process_l3_update(context, network['network'], id)
-            self._extend_network_dict_l3(context, net)
+            self._process_l3_update(context, net, network['network'])
         return net
 
-    def delete_network(self, context, id):
-        session = context.session
-        with session.begin(subtransactions=True):
-            super(TestL3NatPlugin, self).delete_network(context, id)
-
-    def get_network(self, context, id, fields=None):
-        net = super(TestL3NatPlugin, self).get_network(context, id, None)
-        self._extend_network_dict_l3(context, net)
-        return self._fields(net, fields)
-
-    def get_networks(self, context, filters=None, fields=None,
-                     sorts=[], limit=None, marker=None,
-                     page_reverse=False):
-        nets = super(TestL3NatPlugin, self).get_networks(
-            context, filters=filters, fields=fields, sorts=sorts, limit=limit,
-            marker=marker, page_reverse=page_reverse)
-        for net in nets:
-            self._extend_network_dict_l3(context, net)
-        return [self._fields(net, fields) for net in nets]
-
     def delete_port(self, context, id, l3_port_check=True):
         if l3_port_check:
             self.prevent_l3_port_deletion(context, id)