Jointly load ExternalNetwork with Network
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
This commit is contained in:
parent
6426a7e445
commit
cfaec705c8
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
||||
def _process_l3_create(self, context, net_data, net_id):
|
||||
external = net_data.get(l3.EXTERNAL)
|
||||
# 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, 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', [])
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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."""
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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] = {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue