From 0c9b3061048800839338b0af567b6706f5168de2 Mon Sep 17 00:00:00 2001 From: Kyle Haley Date: Fri, 17 Feb 2017 11:47:32 -0800 Subject: [PATCH] Refactor extensions to align with upstream Upstream moved ExtensionDescriptor into neutron-lib as well as some functionality revolved around retrieving the plugin from NeutronManager. This refactor moves libraries around in order to align quark with upstream neutron's expectations. JIRA:NCP2115 Change-Id: Ie922d7778d370491166a00952bec7cea7f7b5a84 --- quark/api/extensions/diagnostics.py | 7 ++++--- quark/api/extensions/floatingip.py | 2 +- quark/api/extensions/ip_addresses.py | 9 +++++---- quark/api/extensions/ip_availability.py | 7 ++++--- quark/api/extensions/ip_policies.py | 7 ++++--- quark/api/extensions/jobs.py | 7 ++++--- quark/api/extensions/mac_address_ranges.py | 7 ++++--- quark/api/extensions/networks_quark.py | 2 +- quark/api/extensions/ports_quark.py | 2 +- quark/api/extensions/routes.py | 7 ++++--- quark/api/extensions/scalingip.py | 7 ++++--- quark/api/extensions/security_group_rules.py | 2 +- quark/api/extensions/security_groups.py | 2 +- quark/api/extensions/segment_allocation_ranges.py | 7 ++++--- quark/api/extensions/subnets_quark.py | 2 +- 15 files changed, 43 insertions(+), 34 deletions(-) diff --git a/quark/api/extensions/diagnostics.py b/quark/api/extensions/diagnostics.py index f685c4c..d8f8f40 100644 --- a/quark/api/extensions/diagnostics.py +++ b/quark/api/extensions/diagnostics.py @@ -16,8 +16,9 @@ import functools from neutron.api import extensions -from neutron import manager +from neutron_lib.api import extensions as nl_extensions from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_log import log as logging LOG = logging.getLogger(__name__) @@ -39,7 +40,7 @@ class Diagnostician(object): req.context, id, input['diag']) -class Diagnostics(extensions.ExtensionDescriptor): +class Diagnostics(nl_extensions.ExtensionDescriptor): def get_name(self): return "Diagnostics" @@ -56,7 +57,7 @@ class Diagnostics(extensions.ExtensionDescriptor): return "never" def get_actions(self): - diagnose = Diagnostician(manager.NeutronManager.get_plugin()).diagnose + diagnose = Diagnostician(directory.get_plugin()).diagnose resources = ['port', 'subnet', 'network'] return (extensions.ActionExtension('%ss' % res, 'diag', functools.partial(diagnose, res)) for res in resources) diff --git a/quark/api/extensions/floatingip.py b/quark/api/extensions/floatingip.py index 40a1eea..b49b9ee 100644 --- a/quark/api/extensions/floatingip.py +++ b/quark/api/extensions/floatingip.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from neutron.api import extensions +from neutron_lib.api import extensions RESOURCE_NAME = "floatingip" RESOURCE_COLLECTION = RESOURCE_NAME + "s" diff --git a/quark/api/extensions/ip_addresses.py b/quark/api/extensions/ip_addresses.py index 0a773cc..c02d0e9 100644 --- a/quark/api/extensions/ip_addresses.py +++ b/quark/api/extensions/ip_addresses.py @@ -14,8 +14,9 @@ # limitations under the License. from neutron.api import extensions -from neutron import manager from neutron import wsgi +from neutron_lib.api import extensions as nl_extensions +from neutron_lib.plugins import directory from oslo_log import log as logging import quark.utils as utils import webob @@ -119,7 +120,7 @@ class IpAddressPortController(wsgi.Controller): raise webob.exc.HTTPNotImplemented() -class Ip_addresses(extensions.ExtensionDescriptor): +class Ip_addresses(nl_extensions.ExtensionDescriptor): """IP Addresses support.""" @classmethod def get_name(cls): @@ -152,9 +153,9 @@ class Ip_addresses(extensions.ExtensionDescriptor): def get_resources(cls): """Returns Ext Resources.""" ip_controller = IpAddressesController( - manager.NeutronManager.get_plugin()) + directory.get_plugin()) ip_port_controller = IpAddressPortController( - manager.NeutronManager.get_plugin()) + directory.get_plugin()) resources = [] resources.append(extensions.ResourceExtension( Ip_addresses.get_alias(), diff --git a/quark/api/extensions/ip_availability.py b/quark/api/extensions/ip_availability.py index c74be33..fbfa136 100644 --- a/quark/api/extensions/ip_availability.py +++ b/quark/api/extensions/ip_availability.py @@ -14,9 +14,10 @@ # limitations under the License. from neutron.api import extensions -from neutron import manager from neutron import wsgi +from neutron_lib.api import extensions as nl_extensions from neutron_lib import exceptions as n_exc +from neutron_lib.plugins import directory from oslo_log import log as logging RESOURCE_NAME = "ip_availability" @@ -45,7 +46,7 @@ class IPAvailabilityController(wsgi.Controller): return self._plugin.get_ip_availability(**request.GET) -class Ip_availability(extensions.ExtensionDescriptor): +class Ip_availability(nl_extensions.ExtensionDescriptor): """IP Availability support.""" @classmethod def get_name(cls): @@ -77,7 +78,7 @@ class Ip_availability(extensions.ExtensionDescriptor): @classmethod def get_resources(cls): """Returns Ext Resources.""" - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() controller = IPAvailabilityController(plugin) return [extensions.ResourceExtension(Ip_availability.get_alias(), controller)] diff --git a/quark/api/extensions/ip_policies.py b/quark/api/extensions/ip_policies.py index 32e058c..158d130 100644 --- a/quark/api/extensions/ip_policies.py +++ b/quark/api/extensions/ip_policies.py @@ -14,8 +14,9 @@ # limitations under the License. from neutron.api import extensions -from neutron import manager from neutron import wsgi +from neutron_lib.api import extensions as nl_extensions +from neutron_lib.plugins import directory from oslo_log import log as logging import quark.utils as utils @@ -67,7 +68,7 @@ class IPPoliciesController(wsgi.Controller): return self._plugin.delete_ip_policy(context, id) -class Ip_policies(extensions.ExtensionDescriptor): +class Ip_policies(nl_extensions.ExtensionDescriptor): """IP Policies support.""" @classmethod def get_name(cls): @@ -100,7 +101,7 @@ class Ip_policies(extensions.ExtensionDescriptor): @classmethod def get_resources(cls): """Returns Ext Resources.""" - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() controller = IPPoliciesController(plugin) return [extensions.ResourceExtension(Ip_policies.get_alias(), controller)] diff --git a/quark/api/extensions/jobs.py b/quark/api/extensions/jobs.py index c51f22a..940070a 100644 --- a/quark/api/extensions/jobs.py +++ b/quark/api/extensions/jobs.py @@ -14,8 +14,9 @@ # limitations under the License. from neutron.api import extensions -from neutron import manager from neutron import wsgi +from neutron_lib.api import extensions as nl_extensions +from neutron_lib.plugins import directory from oslo_log import log as logging import quark.utils as utils @@ -69,7 +70,7 @@ class JobsController(wsgi.Controller): return self._plugin.delete_job(context, id) -class Jobs(extensions.ExtensionDescriptor): +class Jobs(nl_extensions.ExtensionDescriptor): """Jobs support.""" @classmethod def get_name(cls): @@ -102,7 +103,7 @@ class Jobs(extensions.ExtensionDescriptor): def get_resources(cls): """Returns Ext Resources.""" job_controller = JobsController( - manager.NeutronManager.get_plugin()) + directory.get_plugin()) resources = [] resources.append(extensions.ResourceExtension( Jobs.get_alias(), diff --git a/quark/api/extensions/mac_address_ranges.py b/quark/api/extensions/mac_address_ranges.py index 7d859bb..8bfff35 100644 --- a/quark/api/extensions/mac_address_ranges.py +++ b/quark/api/extensions/mac_address_ranges.py @@ -14,8 +14,9 @@ # limitations under the License. from neutron.api import extensions -from neutron import manager from neutron import wsgi +from neutron_lib.api import extensions as nl_extensions +from neutron_lib.plugins import directory from oslo_log import log as logging import quark.utils as utils @@ -68,7 +69,7 @@ class MacAddressRangesController(wsgi.Controller): return self._plugin.delete_mac_address_range(context, id) -class Mac_address_ranges(extensions.ExtensionDescriptor): +class Mac_address_ranges(nl_extensions.ExtensionDescriptor): """Mac Address Range support.""" @classmethod def get_name(cls): @@ -101,7 +102,7 @@ class Mac_address_ranges(extensions.ExtensionDescriptor): @classmethod def get_resources(cls): """Returns Ext Resources.""" - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() controller = MacAddressRangesController(plugin) return [extensions.ResourceExtension(Mac_address_ranges.get_alias(), controller)] diff --git a/quark/api/extensions/networks_quark.py b/quark/api/extensions/networks_quark.py index 6265e02..4f4b8ca 100644 --- a/quark/api/extensions/networks_quark.py +++ b/quark/api/extensions/networks_quark.py @@ -14,7 +14,7 @@ # limitations under the License. -from neutron.api import extensions +from neutron_lib.api import extensions RESOURCE_NAME = "network" RESOURCE_COLLECTION = RESOURCE_NAME + "s" diff --git a/quark/api/extensions/ports_quark.py b/quark/api/extensions/ports_quark.py index d9965dd..807c99a 100644 --- a/quark/api/extensions/ports_quark.py +++ b/quark/api/extensions/ports_quark.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from neutron.api import extensions from neutron.extensions import securitygroup from neutron_lib.api import converters as conv +from neutron_lib.api import extensions from neutron_lib import constants as const RESOURCE_NAME = "port" diff --git a/quark/api/extensions/routes.py b/quark/api/extensions/routes.py index 7132205..601873a 100644 --- a/quark/api/extensions/routes.py +++ b/quark/api/extensions/routes.py @@ -14,8 +14,9 @@ # limitations under the License. from neutron.api import extensions -from neutron import manager from neutron import wsgi +from neutron_lib.api import extensions as nl_extensions +from neutron_lib.plugins import directory from oslo_log import log as logging import quark.utils as utils @@ -67,7 +68,7 @@ class RoutesController(wsgi.Controller): self._plugin.delete_route(context, id) -class Routes(extensions.ExtensionDescriptor): +class Routes(nl_extensions.ExtensionDescriptor): """Routes support.""" @classmethod def get_name(cls): @@ -98,7 +99,7 @@ class Routes(extensions.ExtensionDescriptor): @classmethod def get_resources(cls): """Returns Ext Resources.""" - controller = RoutesController(manager.NeutronManager.get_plugin()) + controller = RoutesController(directory.get_plugin()) return [extensions.ResourceExtension( Routes.get_alias(), controller)] diff --git a/quark/api/extensions/scalingip.py b/quark/api/extensions/scalingip.py index 1ff6b8a..e358f76 100644 --- a/quark/api/extensions/scalingip.py +++ b/quark/api/extensions/scalingip.py @@ -13,9 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from neutron.api import extensions +from neutron._i18n import _ from neutron.api.v2 import attributes as attr from neutron.api.v2 import resource_helper +from neutron_lib.api import extensions from neutron_lib.api import validators from oslo_log import log as logging @@ -79,7 +80,7 @@ RESOURCE_ATTRIBUTE_MAP = { "tenant_id": { 'allow_post': True, 'allow_put': False, 'required_by_policy': True, - 'validate': {'type:string': attr.TENANT_ID_MAX_LEN}, + 'validate': {'type:string': None}, 'is_visible': True }, "scaling_network_id": { @@ -127,7 +128,7 @@ class Scalingip(extensions.ExtensionDescriptor): """Returns Ext Resources.""" plural_mappings = resource_helper.build_plural_mappings( {}, RESOURCE_ATTRIBUTE_MAP) - attr.PLURALS.update(plural_mappings) + # attr.PLURALS.update(plural_mappings) return resource_helper.build_resource_info(plural_mappings, RESOURCE_ATTRIBUTE_MAP, None, diff --git a/quark/api/extensions/security_group_rules.py b/quark/api/extensions/security_group_rules.py index 92b43b2..80cf966 100644 --- a/quark/api/extensions/security_group_rules.py +++ b/quark/api/extensions/security_group_rules.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.api import extensions +from neutron_lib.api import extensions EXTENDED_ATTRIBUTES_2_0 = { "security_group_rules": { diff --git a/quark/api/extensions/security_groups.py b/quark/api/extensions/security_groups.py index b2f01a3..04635d8 100644 --- a/quark/api/extensions/security_groups.py +++ b/quark/api/extensions/security_groups.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.api import extensions +from neutron_lib.api import extensions EXTENDED_ATTRIBUTES_2_0 = { "security_groups": { diff --git a/quark/api/extensions/segment_allocation_ranges.py b/quark/api/extensions/segment_allocation_ranges.py index 4e15722..b670b68 100644 --- a/quark/api/extensions/segment_allocation_ranges.py +++ b/quark/api/extensions/segment_allocation_ranges.py @@ -14,8 +14,9 @@ # limitations under the License. from neutron.api import extensions -from neutron import manager from neutron import wsgi +from neutron_lib.api import extensions as nl_extensions +from neutron_lib.plugins import directory from oslo_log import log as logging import quark.utils as utils @@ -65,7 +66,7 @@ class SegmentAllocationRangesController(wsgi.Controller): return self._plugin.delete_segment_allocation_range(context, id) -class Segment_allocation_ranges(extensions.ExtensionDescriptor): +class Segment_allocation_ranges(nl_extensions.ExtensionDescriptor): """Segment Allocation Range support.""" @classmethod def get_name(cls): @@ -98,7 +99,7 @@ class Segment_allocation_ranges(extensions.ExtensionDescriptor): @classmethod def get_resources(cls): """Returns Ext Resources.""" - plugin = manager.NeutronManager.get_plugin() + plugin = directory.get_plugin() controller = SegmentAllocationRangesController(plugin) return [extensions.ResourceExtension( Segment_allocation_ranges.get_alias(), diff --git a/quark/api/extensions/subnets_quark.py b/quark/api/extensions/subnets_quark.py index c78e322..410fb20 100644 --- a/quark/api/extensions/subnets_quark.py +++ b/quark/api/extensions/subnets_quark.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.api import extensions +from neutron_lib.api import extensions EXTENDED_ATTRIBUTES_2_0 = { "subnets": {