Prepare for neutron-lib DB support
Updates code following commit 8f80a52b01f77b8e2988f6ec78cfbfbecab4895d. Change-Id: Iba1067a22fd7bcc952ea1d81c32cc519168128f0
This commit is contained in:
parent
03ba194480
commit
11e54f5c21
@ -16,6 +16,7 @@
|
|||||||
from sqlalchemy.orm import exc
|
from sqlalchemy.orm import exc
|
||||||
|
|
||||||
from neutron.api.v2 import attributes
|
from neutron.api.v2 import attributes
|
||||||
|
from neutron.db import _utils as db_utils
|
||||||
from neutron.db import db_base_plugin_v2
|
from neutron.db import db_base_plugin_v2
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
@ -32,7 +33,7 @@ class MacLearningDbMixin(object):
|
|||||||
def _make_mac_learning_state_dict(self, port, fields=None):
|
def _make_mac_learning_state_dict(self, port, fields=None):
|
||||||
res = {'port_id': port['port_id'],
|
res = {'port_id': port['port_id'],
|
||||||
mac.MAC_LEARNING: port[mac.MAC_LEARNING]}
|
mac.MAC_LEARNING: port[mac.MAC_LEARNING]}
|
||||||
return self._fields(res, fields)
|
return db_utils.resource_fields(res, fields)
|
||||||
|
|
||||||
def _extend_port_mac_learning_state(self, port_res, port_db):
|
def _extend_port_mac_learning_state(self, port_res, port_db):
|
||||||
state = port_db.mac_learning_state
|
state = port_db.mac_learning_state
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
from sqlalchemy.orm import exc as sa_orm_exc
|
from sqlalchemy.orm import exc as sa_orm_exc
|
||||||
|
|
||||||
|
from neutron.db import _utils as db_utils
|
||||||
from neutron.plugins.common import utils
|
from neutron.plugins.common import utils
|
||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
from neutron_lib import exceptions
|
from neutron_lib import exceptions
|
||||||
@ -119,7 +120,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
|||||||
if not fields or 'ports' in fields:
|
if not fields or 'ports' in fields:
|
||||||
res['ports'] = [self._make_gw_connection_dict(conn)
|
res['ports'] = [self._make_gw_connection_dict(conn)
|
||||||
for conn in network_gateway.network_connections]
|
for conn in network_gateway.network_connections]
|
||||||
return self._fields(res, fields)
|
return db_utils.resource_fields(res, fields)
|
||||||
|
|
||||||
def _set_mapping_info_defaults(self, mapping_info):
|
def _set_mapping_info_defaults(self, mapping_info):
|
||||||
if not mapping_info.get('segmentation_type'):
|
if not mapping_info.get('segmentation_type'):
|
||||||
@ -390,7 +391,7 @@ class NetworkGatewayMixin(networkgw.NetworkGatewayPluginBase):
|
|||||||
if fields:
|
if fields:
|
||||||
fields.append('nsx_id')
|
fields.append('nsx_id')
|
||||||
res['nsx_id'] = gateway_device['nsx_id']
|
res['nsx_id'] = gateway_device['nsx_id']
|
||||||
return self._fields(res, fields)
|
return db_utils.resource_fields(res, fields)
|
||||||
|
|
||||||
def _get_gateway_device(self, context, device_id):
|
def _get_gateway_device(self, context, device_id):
|
||||||
try:
|
try:
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
from sqlalchemy.orm import exc
|
from sqlalchemy.orm import exc
|
||||||
|
|
||||||
from neutron.api.v2 import attributes as attr
|
from neutron.api.v2 import attributes as attr
|
||||||
|
from neutron.db import _utils as db_utils
|
||||||
from neutron.db import db_base_plugin_v2
|
from neutron.db import db_base_plugin_v2
|
||||||
from neutron.db import models_v2
|
from neutron.db import models_v2
|
||||||
|
|
||||||
@ -147,17 +148,17 @@ class QoSDbMixin(qos.QueuePluginBase):
|
|||||||
'max': queue.get('max'),
|
'max': queue.get('max'),
|
||||||
'qos_marking': queue.get('qos_marking'),
|
'qos_marking': queue.get('qos_marking'),
|
||||||
'dscp': queue.get('dscp')}
|
'dscp': queue.get('dscp')}
|
||||||
return self._fields(res, fields)
|
return db_utils.resource_fields(res, fields)
|
||||||
|
|
||||||
def _make_port_queue_binding_dict(self, queue, fields=None):
|
def _make_port_queue_binding_dict(self, queue, fields=None):
|
||||||
res = {'port_id': queue['port_id'],
|
res = {'port_id': queue['port_id'],
|
||||||
'queue_id': queue['queue_id']}
|
'queue_id': queue['queue_id']}
|
||||||
return self._fields(res, fields)
|
return db_utils.resource_fields(res, fields)
|
||||||
|
|
||||||
def _make_network_queue_binding_dict(self, queue, fields=None):
|
def _make_network_queue_binding_dict(self, queue, fields=None):
|
||||||
res = {'network_id': queue['network_id'],
|
res = {'network_id': queue['network_id'],
|
||||||
'queue_id': queue['queue_id']}
|
'queue_id': queue['queue_id']}
|
||||||
return self._fields(res, fields)
|
return db_utils.resource_fields(res, fields)
|
||||||
|
|
||||||
def _check_for_queue_and_create(self, context, port):
|
def _check_for_queue_and_create(self, context, port):
|
||||||
"""Check for queue and create.
|
"""Check for queue and create.
|
||||||
|
@ -19,6 +19,7 @@ from oslo_log import log as logging
|
|||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
|
||||||
from neutron.api import extensions as neutron_extensions
|
from neutron.api import extensions as neutron_extensions
|
||||||
|
from neutron.db import _utils as db_utils
|
||||||
from neutron.db import agentschedulers_db
|
from neutron.db import agentschedulers_db
|
||||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||||
from neutron.db import db_base_plugin_v2
|
from neutron.db import db_base_plugin_v2
|
||||||
@ -259,7 +260,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
net_result = self._make_network_dict(network,
|
net_result = self._make_network_dict(network,
|
||||||
context=context)
|
context=context)
|
||||||
self._extend_network_dict_provider(context, net_result)
|
self._extend_network_dict_provider(context, net_result)
|
||||||
return self._fields(net_result, fields)
|
return db_utils.resource_fields(net_result, fields)
|
||||||
|
|
||||||
def get_network(self, context, id, fields=None):
|
def get_network(self, context, id, fields=None):
|
||||||
return self._dvs_get_network(context, id, fields=None)
|
return self._dvs_get_network(context, id, fields=None)
|
||||||
@ -276,7 +277,8 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
for net in networks:
|
for net in networks:
|
||||||
self._extend_network_dict_provider(context, net)
|
self._extend_network_dict_provider(context, net)
|
||||||
return (networks if not fields else
|
return (networks if not fields else
|
||||||
[self._fields(network, fields) for network in networks])
|
[db_utils.resource_fields(network,
|
||||||
|
fields) for network in networks])
|
||||||
|
|
||||||
def update_network(self, context, id, network):
|
def update_network(self, context, id, network):
|
||||||
net_attrs = network['network']
|
net_attrs = network['network']
|
||||||
|
@ -32,6 +32,7 @@ from neutron.api import extensions as neutron_extensions
|
|||||||
from neutron.api.v2 import attributes as attr
|
from neutron.api.v2 import attributes as attr
|
||||||
from neutron.api.v2 import base
|
from neutron.api.v2 import base
|
||||||
from neutron import context as q_context
|
from neutron import context as q_context
|
||||||
|
from neutron.db import _utils as db_utils
|
||||||
from neutron.db import agentschedulers_db
|
from neutron.db import agentschedulers_db
|
||||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||||
from neutron.db import db_base_plugin_v2
|
from neutron.db import db_base_plugin_v2
|
||||||
@ -1043,7 +1044,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
net_result = self._make_network_dict(network,
|
net_result = self._make_network_dict(network,
|
||||||
context=context)
|
context=context)
|
||||||
self._extend_network_dict_provider(context, net_result)
|
self._extend_network_dict_provider(context, net_result)
|
||||||
return self._fields(net_result, fields)
|
return db_utils.resource_fields(net_result, fields)
|
||||||
|
|
||||||
def get_networks(self, context, filters=None, fields=None,
|
def get_networks(self, context, filters=None, fields=None,
|
||||||
sorts=None, limit=None, marker=None,
|
sorts=None, limit=None, marker=None,
|
||||||
@ -1057,7 +1058,8 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
for net in networks:
|
for net in networks:
|
||||||
self._extend_network_dict_provider(context, net)
|
self._extend_network_dict_provider(context, net)
|
||||||
return (networks if not fields else
|
return (networks if not fields else
|
||||||
[self._fields(network, fields) for network in networks])
|
[db_utils.resource_fields(network,
|
||||||
|
fields) for network in networks])
|
||||||
|
|
||||||
def update_network(self, context, id, network):
|
def update_network(self, context, id, network):
|
||||||
pnet._raise_if_updates_provider_attributes(network['network'])
|
pnet._raise_if_updates_provider_attributes(network['network'])
|
||||||
|
@ -39,6 +39,7 @@ from neutron.callbacks import resources
|
|||||||
from neutron.common import ipv6_utils
|
from neutron.common import ipv6_utils
|
||||||
from neutron.common import rpc as n_rpc
|
from neutron.common import rpc as n_rpc
|
||||||
from neutron import context as n_context
|
from neutron import context as n_context
|
||||||
|
from neutron.db import _utils as db_utils
|
||||||
from neutron.db import agents_db
|
from neutron.db import agents_db
|
||||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||||
from neutron.db.availability_zone import router as router_az_db
|
from neutron.db.availability_zone import router as router_az_db
|
||||||
@ -1181,7 +1182,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
net_result = self._make_network_dict(network,
|
net_result = self._make_network_dict(network,
|
||||||
context=context)
|
context=context)
|
||||||
self._extend_get_network_dict_provider(context, net_result)
|
self._extend_get_network_dict_provider(context, net_result)
|
||||||
return self._fields(net_result, fields)
|
return db_utils.resource_fields(net_result, fields)
|
||||||
|
|
||||||
def get_networks(self, context, filters=None, fields=None,
|
def get_networks(self, context, filters=None, fields=None,
|
||||||
sorts=None, limit=None, marker=None,
|
sorts=None, limit=None, marker=None,
|
||||||
@ -1195,7 +1196,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
for net in networks:
|
for net in networks:
|
||||||
self._extend_get_network_dict_provider(context, net)
|
self._extend_get_network_dict_provider(context, net)
|
||||||
return (networks if not fields else
|
return (networks if not fields else
|
||||||
[self._fields(network, fields) for network in networks])
|
[db_utils.resource_fields(network,
|
||||||
|
fields) for network in networks])
|
||||||
|
|
||||||
def update_network(self, context, id, network):
|
def update_network(self, context, id, network):
|
||||||
net_attrs = network['network']
|
net_attrs = network['network']
|
||||||
@ -1238,8 +1240,8 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
|||||||
net_attrs[psec.PORTSECURITY])
|
net_attrs[psec.PORTSECURITY])
|
||||||
except Exception:
|
except Exception:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
revert_update = self._fields(original_network,
|
revert_update = db_utils.resource_fields(
|
||||||
['shared', psec.PORTSECURITY])
|
original_network, ['shared', psec.PORTSECURITY])
|
||||||
self._process_network_port_security_update(
|
self._process_network_port_security_update(
|
||||||
context, revert_update, net_res)
|
context, revert_update, net_res)
|
||||||
super(NsxVPluginV2, self).update_network(
|
super(NsxVPluginV2, self).update_network(
|
||||||
|
@ -29,6 +29,7 @@ from neutron.callbacks import resources
|
|||||||
from neutron.common import rpc as n_rpc
|
from neutron.common import rpc as n_rpc
|
||||||
from neutron.common import topics
|
from neutron.common import topics
|
||||||
from neutron import context as q_context
|
from neutron import context as q_context
|
||||||
|
from neutron.db import _utils as db_utils
|
||||||
from neutron.db import agents_db
|
from neutron.db import agents_db
|
||||||
from neutron.db import agentschedulers_db
|
from neutron.db import agentschedulers_db
|
||||||
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
from neutron.db import allowedaddresspairs_db as addr_pair_db
|
||||||
@ -1280,7 +1281,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
# provider networks fields
|
# provider networks fields
|
||||||
net = self._make_network_dict(network, context=context)
|
net = self._make_network_dict(network, context=context)
|
||||||
self._extend_get_network_dict_provider(context, net)
|
self._extend_get_network_dict_provider(context, net)
|
||||||
return self._fields(net, fields)
|
return db_utils.resource_fields(net, fields)
|
||||||
|
|
||||||
def get_networks(self, context, filters=None, fields=None,
|
def get_networks(self, context, filters=None, fields=None,
|
||||||
sorts=None, limit=None, marker=None,
|
sorts=None, limit=None, marker=None,
|
||||||
@ -1296,7 +1297,8 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
for net in networks:
|
for net in networks:
|
||||||
self._extend_get_network_dict_provider(context, net)
|
self._extend_get_network_dict_provider(context, net)
|
||||||
return (networks if not fields else
|
return (networks if not fields else
|
||||||
[self._fields(network, fields) for network in networks])
|
[db_utils.resource_fields(network,
|
||||||
|
fields) for network in networks])
|
||||||
|
|
||||||
def _get_data_from_binding_profile(self, context, port):
|
def _get_data_from_binding_profile(self, context, port):
|
||||||
if (pbin.PROFILE not in port or
|
if (pbin.PROFILE not in port or
|
||||||
@ -2229,7 +2231,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
port = super(NsxV3Plugin, self).get_port(context, id, fields=None)
|
port = super(NsxV3Plugin, self).get_port(context, id, fields=None)
|
||||||
self._extend_get_port_dict_binding(context, port)
|
self._extend_get_port_dict_binding(context, port)
|
||||||
|
|
||||||
return self._fields(port, fields)
|
return db_utils.resource_fields(port, fields)
|
||||||
|
|
||||||
def get_ports(self, context, filters=None, fields=None,
|
def get_ports(self, context, filters=None, fields=None,
|
||||||
sorts=None, limit=None, marker=None,
|
sorts=None, limit=None, marker=None,
|
||||||
@ -2244,7 +2246,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||||||
for port in ports:
|
for port in ports:
|
||||||
self._extend_get_port_dict_binding(context, port)
|
self._extend_get_port_dict_binding(context, port)
|
||||||
return (ports if not fields else
|
return (ports if not fields else
|
||||||
[self._fields(port, fields) for port in ports])
|
[db_utils.resource_fields(port, fields) for port in ports])
|
||||||
|
|
||||||
def _extract_external_gw(self, context, router, is_extract=True):
|
def _extract_external_gw(self, context, router, is_extract=True):
|
||||||
r = router['router']
|
r = router['router']
|
||||||
|
Loading…
Reference in New Issue
Block a user