use core resource attribute constants from neutron-lib

neutron-lib now contains the API definitions for neutron's core
resources. This patch switches neutron core resource variables to
neutron-lib.

Change-Id: Id178e46f5fb220860de09316abff7684eff272ef
This commit is contained in:
Boden R 2017-05-23 13:08:46 -06:00
parent b7950ee00d
commit e86347e3a0
7 changed files with 33 additions and 25 deletions

View File

@ -20,11 +20,11 @@ from sqlalchemy import orm
from sqlalchemy.orm import exc
from sqlalchemy import sql
from neutron.api.v2 import attributes
from neutron.db import _resource_extend as resource_extend
from neutron.db import api as db_api
from neutron.db.models import securitygroup as securitygroups_db
from neutron.extensions import securitygroup as ext_sg
from neutron_lib.api.definitions import port as port_def
from neutron_lib.api import validators
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
@ -355,7 +355,7 @@ class ExtendedSecurityGroupPropertiesMixin(object):
sg_res[sg_policy.POLICY] = sg_db.ext_properties.policy
@staticmethod
@resource_extend.extends([attributes.PORTS])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _extend_port_dict_provider_security_group(port_res, port_db):
# Add the provider sg list to the port.
# later we will remove those from the regular sg list

View File

@ -15,12 +15,13 @@
from sqlalchemy.orm import exc
from neutron.api.v2 import attributes
from neutron.db import _model_query as model_query
from neutron.db import _resource_extend as resource_extend
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron_lib.api.definitions import port as port_def
from oslo_log import log as logging
from vmware_nsx.db import nsx_models
@ -39,7 +40,7 @@ class MacLearningDbMixin(object):
return db_utils.resource_fields(res, fields)
@staticmethod
@resource_extend.extends([attributes.PORTS])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _extend_port_mac_learning_state(port_res, port_db):
state = port_db.mac_learning_state
if state and state.mac_learning_enabled:

View File

@ -15,13 +15,15 @@
from sqlalchemy.orm import exc
from neutron.api.v2 import attributes as attr
from neutron.db import _model_query as model_query
from neutron.db import _resource_extend as resource_extend
from neutron.db import _utils as db_utils
from neutron.db import api as db_api
from neutron.db import models_v2
from neutron_lib.api.definitions import network as net_def
from neutron_lib.api.definitions import port as port_def
from oslo_log import log
from oslo_utils import uuidutils
@ -130,8 +132,8 @@ class QoSDbMixin(qos.QueuePluginBase):
context.session.delete(binding)
@staticmethod
@resource_extend.extends([attr.NETWORKS])
@resource_extend.extends([attr.PORTS])
@resource_extend.extends([net_def.COLLECTION_NAME])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _extend_dict_qos_queue(obj_res, obj_db):
queue_mapping = obj_db['qos_queue']
if queue_mapping:

View File

@ -15,9 +15,10 @@
from sqlalchemy.orm import exc
from neutron.api.v2 import attributes as attr
from neutron.db import _resource_extend as resource_extend
from neutron_lib.api.definitions import port as port_def
from oslo_db import exception as db_exc
from oslo_log import log as logging
@ -31,7 +32,7 @@ LOG = logging.getLogger(__name__)
class VnicIndexDbMixin(object):
@staticmethod
@resource_extend.extends([attr.PORTS])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _extend_port_vnic_index_binding(port_res, port_db):
state = port_db.vnic_index
port_res[vnicidx.VNIC_INDEX] = state.index if state else None

View File

@ -15,13 +15,13 @@
import uuid
from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import port_security as psec
from neutron_lib.exceptions import port_security as psec_exc
from oslo_log import log as logging
from oslo_utils import excutils
from neutron.api import extensions as neutron_extensions
from neutron.api.v2 import attributes as attr
from neutron.db import _resource_extend as resource_extend
from neutron.db import _utils as db_utils
from neutron.db import agentschedulers_db
@ -107,7 +107,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
self.setup_dhcpmeta_access()
@staticmethod
@resource_extend.extends([attr.PORTS])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _extend_port_dict_binding(result, portdb):
result[pbin.VIF_TYPE] = nsx_constants.VIF_TYPE_DVS
port_attr = portdb.get('nsx_port_attributes')

View File

@ -18,8 +18,11 @@ import six
import uuid
import netaddr
from neutron_lib.api.definitions import network as net_def
from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import provider_net as pnet
from neutron_lib.api.definitions import subnet as subnet_def
from neutron_lib.api import validators
from neutron_lib import constants
from neutron_lib import context as n_context
@ -37,7 +40,6 @@ from oslo_utils import uuidutils
from sqlalchemy.orm import exc as sa_exc
from neutron.api import extensions as neutron_extensions
from neutron.api.v2 import attributes as attr
from neutron.common import ipv6_utils
from neutron.common import rpc as n_rpc
from neutron.common import topics
@ -373,7 +375,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self.fwaas_callbacks = fwaas_callbacks.NsxvFwaasCallbacks()
@staticmethod
@resource_extend.extends([attr.NETWORKS])
@resource_extend.extends([net_def.COLLECTION_NAME])
def _ext_extend_network_dict(result, netdb):
ctx = n_context.get_admin_context()
# get the core plugin as this is a static method with no 'self'
@ -383,7 +385,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
ctx.session, netdb, result)
@staticmethod
@resource_extend.extends([attr.PORTS])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _ext_extend_port_dict(result, portdb):
ctx = n_context.get_admin_context()
# get the core plugin as this is a static method with no 'self'
@ -393,7 +395,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
ctx.session, portdb, result)
@staticmethod
@resource_extend.extends([attr.SUBNETS])
@resource_extend.extends([subnet_def.COLLECTION_NAME])
def _ext_extend_subnet_dict(result, subnetdb):
ctx = n_context.get_admin_context()
# get the core plugin as this is a static method with no 'self'
@ -1717,7 +1719,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self._check_update_has_security_groups(port))
# allowed address pair checks
attrs = port[attr.PORT]
attrs = port[port_def.RESOURCE_NAME]
if self._check_update_has_allowed_address_pairs(port):
if not port_security:
raise addr_pair.AddressPairAndPortSecurityRequired()
@ -1881,7 +1883,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
def _update_port(self, context, id, port, original_port, is_compute_port,
device_id):
attrs = port[attr.PORT]
attrs = port[port_def.RESOURCE_NAME]
port_data = port['port']
dhcp_opts = port_data.get(ext_edo.EXTRADHCPOPTS)
self._validate_extra_dhcp_options(dhcp_opts)
@ -2229,7 +2231,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
self._delete_dhcp_static_binding(context, neutron_db_port)
@staticmethod
@resource_extend.extends([attr.PORTS])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _extend_nsx_port_dict_binding(result, portdb):
result[pbin.VIF_TYPE] = nsx_constants.VIF_TYPE_DVS
port_attr = portdb.get('nsx_port_attributes')
@ -2502,7 +2504,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
return subnet
@staticmethod
@resource_extend.extends([attr.SUBNETS])
@resource_extend.extends([subnet_def.COLLECTION_NAME])
def _extend_subnet_dict_extended_attributes(subnet_res, subnet_db):
subnet_attr = subnet_db.get('nsxv_subnet_attributes')
if subnet_attr:
@ -3080,7 +3082,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
router_driver.delete_router(context, id)
@staticmethod
@resource_extend.extends([attr.NETWORKS])
@resource_extend.extends([net_def.COLLECTION_NAME])
def _extend_availability_zone_hints(net_res, net_db):
net_res[az_ext.AZ_HINTS] = az_ext.convert_az_string_to_list(
net_db[az_ext.AZ_HINTS])

View File

@ -14,14 +14,16 @@
# under the License.
import netaddr
from neutron_lib.api.definitions import network as net_def
from neutron_lib.api.definitions import port as port_def
from neutron_lib.api.definitions import port_security as psec
from neutron_lib.api.definitions import subnet as subnet_def
from neutron_lib.exceptions import port_security as psec_exc
import six
from neutron.api.rpc.agentnotifiers import dhcp_rpc_agent_api
from neutron.api.rpc.handlers import dhcp_rpc
from neutron.api.rpc.handlers import metadata_rpc
from neutron.api.v2 import attributes
from neutron.common import rpc as n_rpc
from neutron.common import topics
from neutron.db import _resource_extend as resource_extend
@ -537,7 +539,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
return self.conn.consume_in_threads()
@staticmethod
@resource_extend.extends([attributes.NETWORKS])
@resource_extend.extends([net_def.COLLECTION_NAME])
def _ext_extend_network_dict(result, netdb):
ctx = q_context.get_admin_context()
# get the core plugin as this is a static method with no 'self'
@ -547,7 +549,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
ctx.session, netdb, result)
@staticmethod
@resource_extend.extends([attributes.PORTS])
@resource_extend.extends([port_def.COLLECTION_NAME])
def _ext_extend_port_dict(result, portdb):
ctx = q_context.get_admin_context()
# get the core plugin as this is a static method with no 'self'
@ -557,7 +559,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
ctx.session, portdb, result)
@staticmethod
@resource_extend.extends([attributes.SUBNETS])
@resource_extend.extends([subnet_def.COLLECTION_NAME])
def _ext_extend_subnet_dict(result, subnetdb):
ctx = q_context.get_admin_context()
# get the core plugin as this is a static method with no 'self'
@ -3558,7 +3560,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
return self.validate_obj_azs(availability_zones)
@staticmethod
@resource_extend.extends([attributes.NETWORKS])
@resource_extend.extends([net_def.COLLECTION_NAME])
def _extend_availability_zone_hints(net_res, net_db):
net_res[az_ext.AZ_HINTS] = az_ext.convert_az_string_to_list(
net_db[az_ext.AZ_HINTS])