logger = logging.getLogger(__name__)
+_resource_classes = {}
+
+
+def get_class(resource_type):
+ return _resource_classes.get(resource_type)
+
+
+def _register_class(resource_type, resource_class):
+ logger.info(_('Registering resource type %s') % resource_type)
+ if resource_type in _resource_classes:
+ logger.warning(_('Replacing existing resource type %s') %
+ resource_type)
+
+ _resource_classes[resource_type] = resource_class
+
+
class Metadata(object):
'''
A descriptor for accessing the metadata of a resource while ensuring the
return super(Resource, cls).__new__(cls)
# Select the correct subclass to instantiate
- from heat.engine.resources import register
- ResourceClass = register.get_class(json['Type']) or GenericResource
+ ResourceClass = get_class(json['Type']) or GenericResource
return ResourceClass(name, json, stack)
def __init__(self, name, json_snippet, stack):
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
+
+
+def _register_resources(type_pairs):
+ from heat.engine import resource
+
+ for res_name, res_class in type_pairs:
+ resource._register_class(res_name, res_class)
+
+
+def _get_module_resources(module):
+ if callable(getattr(module, 'resource_mapping', None)):
+ try:
+ return module.resource_mapping().iteritems()
+ except Exception as ex:
+ logger.error(_('Failed to load resources from %s') % str(module))
+ else:
+ return []
+
+
+def _register_modules(modules):
+ import itertools
+
+ resource_lists = (_get_module_resources(m) for m in modules)
+ _register_resources(itertools.chain.from_iterable(resource_lists))
+
+
+def _initialise():
+ import sys
+ from heat.common import plugin_loader
+
+ _register_modules(plugin_loader.load_modules(sys.modules[__name__]))
+
+
+_initialise()
+++ /dev/null
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-"""
-Register of resource types and their mapping to Resource classes.
-"""
-
-from heat.engine.resources import autoscaling
-from heat.engine.resources import cloud_watch
-from heat.engine.resources import dbinstance
-from heat.engine.resources import eip
-from heat.engine.resources import instance
-from heat.engine.resources import loadbalancer
-from heat.engine.resources import s3
-from heat.engine.resources import security_group
-from heat.engine.resources import stack
-from heat.engine.resources import user
-from heat.engine.resources import volume
-from heat.engine.resources import wait_condition
-from heat.engine.resources.quantum import floatingip
-from heat.engine.resources.quantum import net
-from heat.engine.resources.quantum import port
-from heat.engine.resources.quantum import router
-from heat.engine.resources.quantum import subnet
-
-from heat.openstack.common import log as logging
-
-logger = logging.getLogger('heat.engine.resources.register')
-
-
-_modules = [
- autoscaling, cloud_watch, dbinstance, eip, instance, loadbalancer, s3,
- security_group, stack, user, volume, wait_condition, floatingip, net, port,
- router, subnet,
-]
-
-_resource_classes = {}
-
-
-def get_class(resource_type):
- return _resource_classes.get(resource_type)
-
-
-def _register_class(resource_type, resource_class):
- logger.info(_('Registering resource type %s') % resource_type)
- if resource_type in _resource_classes:
- logger.warning(_('Replacing existing resource type %s') %
- resource_type)
-
- _resource_classes[resource_type] = resource_class
-
-
-for m in _modules:
- for res_type, res_class in m.resource_mapping().items():
- _register_class(res_type, res_class)