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
This commit is contained in:
Kevin Benton 2016-10-19 14:13:04 -07:00
parent 196158253a
commit 204a89e7dd
1 changed files with 10 additions and 21 deletions

View File

@ -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):