From 204a89e7ddf605d5df89dca1c69bb8071deb5886 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Wed, 19 Oct 2016 14:13:04 -0700 Subject: [PATCH] Simplify resources module in RPC callbacks This just eliminates some repetition and intermediary variables that weren't necessary in the RPC callbacks resources file. This makes adding a new resources as simple as adding one line to the _VALID_CLS tuple and a constant name for external references. Partially-Implements: push-notificaitons Change-Id: Icb63cb8a1251e103ae4483c71c6ac6868917c4ec --- neutron/api/rpc/callbacks/resources.py | 31 +++++++++----------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/neutron/api/rpc/callbacks/resources.py b/neutron/api/rpc/callbacks/resources.py index 7e5d79b5504..84e4025789d 100644 --- a/neutron/api/rpc/callbacks/resources.py +++ b/neutron/api/rpc/callbacks/resources.py @@ -14,30 +14,19 @@ from neutron.objects.qos import policy from neutron.objects import trunk -_TRUNK_CLS = trunk.Trunk -_QOS_POLICY_CLS = policy.QosPolicy -_SUBPORT_CLS = trunk.SubPort +# Supported types +TRUNK = trunk.Trunk.obj_name() +QOS_POLICY = policy.QosPolicy.obj_name() +SUBPORT = trunk.SubPort.obj_name() + _VALID_CLS = ( - _TRUNK_CLS, - _QOS_POLICY_CLS, - _SUBPORT_CLS, + policy.QosPolicy, + trunk.Trunk, + trunk.SubPort, ) -_VALID_TYPES = [cls.obj_name() for cls in _VALID_CLS] - - -# Supported types -TRUNK = _TRUNK_CLS.obj_name() -QOS_POLICY = _QOS_POLICY_CLS.obj_name() -SUBPORT = _SUBPORT_CLS.obj_name() - - -_TYPE_TO_CLS_MAP = { - TRUNK: _TRUNK_CLS, - QOS_POLICY: _QOS_POLICY_CLS, - SUBPORT: _SUBPORT_CLS, -} +_TYPE_TO_CLS_MAP = {cls.obj_name(): cls for cls in _VALID_CLS} LOCAL_RESOURCE_VERSIONS = { resource_type: cls.VERSION @@ -56,7 +45,7 @@ def get_resource_type(resource_cls): def is_valid_resource_type(resource_type): - return resource_type in _VALID_TYPES + return resource_type in _TYPE_TO_CLS_MAP def get_resource_cls(resource_type):