From a0cf5dfa5c7eb070ee6aefcdfb23c04ece7c0b70 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Tue, 27 Nov 2012 15:38:44 +0100 Subject: [PATCH] Distribute resource mapping to individual modules Define the mapping from resource names to classes locally in each module and then aggregate them. This moves the mappings near the definitions, and provides the format for an eventual plug-in resource architecture. Change-Id: I3e70d495c5a490ae20d38bf1aec7e28080a55520 Signed-off-by: Zane Bitter --- heat/engine/resources/autoscaling.py | 8 +++ heat/engine/resources/cloud_watch.py | 6 +++ heat/engine/resources/dbinstance.py | 6 +++ heat/engine/resources/eip.py | 7 +++ heat/engine/resources/instance.py | 7 +++ heat/engine/resources/loadbalancer.py | 6 +++ heat/engine/resources/quantum/floatingip.py | 7 +++ heat/engine/resources/quantum/net.py | 6 +++ heat/engine/resources/quantum/port.py | 6 +++ heat/engine/resources/quantum/router.py | 8 +++ heat/engine/resources/quantum/subnet.py | 6 +++ heat/engine/resources/register.py | 55 ++++++++++----------- heat/engine/resources/s3.py | 6 +++ heat/engine/resources/security_group.py | 6 +++ heat/engine/resources/stack.py | 6 +++ heat/engine/resources/user.py | 7 +++ heat/engine/resources/volume.py | 7 +++ heat/engine/resources/wait_condition.py | 7 +++ 18 files changed, 137 insertions(+), 30 deletions(-) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index 89762198..f8318fef 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -196,3 +196,11 @@ class ScalingPolicy(resource.Resource): self.properties['ScalingAdjustment'])) group.adjust(int(self.properties['ScalingAdjustment']), self.properties['AdjustmentType']) + + +def resource_mapping(): + return { + 'AWS::AutoScaling::LaunchConfiguration': LaunchConfiguration, + 'AWS::AutoScaling::AutoScalingGroup': AutoScalingGroup, + 'AWS::AutoScaling::ScalingPolicy': ScalingPolicy, + } diff --git a/heat/engine/resources/cloud_watch.py b/heat/engine/resources/cloud_watch.py index 6fdb809c..45b723f7 100644 --- a/heat/engine/resources/cloud_watch.py +++ b/heat/engine/resources/cloud_watch.py @@ -72,3 +72,9 @@ class CloudWatchAlarm(resource.Resource): def FnGetRefId(self): return unicode(self.physical_resource_name()) + + +def resource_mapping(): + return { + 'AWS::CloudWatch::Alarm': CloudWatchAlarm, + } diff --git a/heat/engine/resources/dbinstance.py b/heat/engine/resources/dbinstance.py index b3b14d99..f8acebc5 100644 --- a/heat/engine/resources/dbinstance.py +++ b/heat/engine/resources/dbinstance.py @@ -236,3 +236,9 @@ class DBInstance(stack.Stack): else: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) + + +def resource_mapping(): + return { + 'AWS::RDS::DBInstance': DBInstance, + } diff --git a/heat/engine/resources/eip.py b/heat/engine/resources/eip.py index b1ddffc1..c0b6dbf8 100644 --- a/heat/engine/resources/eip.py +++ b/heat/engine/resources/eip.py @@ -99,3 +99,10 @@ class ElasticIpAssociation(resource.Resource): server.remove_floating_ip(self.properties['EIP']) except NotFound as ex: pass + + +def resource_mapping(): + return { + 'AWS::EC2::EIP': ElasticIp, + 'AWS::EC2::EIPAssociation': ElasticIpAssociation, + } diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index d4e42b49..5d31fc6a 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -318,3 +318,10 @@ class Instance(resource.Resource): break eventlet.sleep(0.2) self.resource_id = None + + +def resource_mapping(): + return { + 'AWS::EC2::Instance': Instance, + 'HEAT::HA::Restarter': Restarter, + } diff --git a/heat/engine/resources/loadbalancer.py b/heat/engine/resources/loadbalancer.py index 2d7135c5..dd8950b2 100644 --- a/heat/engine/resources/loadbalancer.py +++ b/heat/engine/resources/loadbalancer.py @@ -346,3 +346,9 @@ class LoadBalancer(stack.Stack): return stack.Stack.FnGetAtt(self, 'Outputs.PublicIp') else: return '' + + +def resource_mapping(): + return { + 'AWS::ElasticLoadBalancing::LoadBalancer': LoadBalancer, + } diff --git a/heat/engine/resources/quantum/floatingip.py b/heat/engine/resources/quantum/floatingip.py index 4f8a70b1..8739492a 100644 --- a/heat/engine/resources/quantum/floatingip.py +++ b/heat/engine/resources/quantum/floatingip.py @@ -75,3 +75,10 @@ class FloatingIPAssociation(quantum.QuantumResource): {'floatingip': {'port_id': None}}) except: pass + + +def resource_mapping(): + return { + 'OS::Quantum::FloatingIP': FloatingIP, + 'OS::Quantum::FloatingIPAssociation': FloatingIPAssociation, + } diff --git a/heat/engine/resources/quantum/net.py b/heat/engine/resources/quantum/net.py index 02be17ad..ba88945b 100644 --- a/heat/engine/resources/quantum/net.py +++ b/heat/engine/resources/quantum/net.py @@ -46,3 +46,9 @@ class Net(quantum.QuantumResource): attributes = self.quantum().show_network( self.resource_id)['network'] return self.handle_get_attributes(self.name, key, attributes) + + +def resource_mapping(): + return { + 'OS::Quantum::Net': Net, + } diff --git a/heat/engine/resources/quantum/port.py b/heat/engine/resources/quantum/port.py index b76f699b..36fa9bec 100644 --- a/heat/engine/resources/quantum/port.py +++ b/heat/engine/resources/quantum/port.py @@ -59,3 +59,9 @@ class Port(quantum.QuantumResource): attributes = self.quantum().show_port( self.resource_id)['port'] return self.handle_get_attributes(self.name, key, attributes) + + +def resource_mapping(): + return { + 'OS::Quantum::Port': Port, + } diff --git a/heat/engine/resources/quantum/router.py b/heat/engine/resources/quantum/router.py index 9a13924d..6b33a3bf 100644 --- a/heat/engine/resources/quantum/router.py +++ b/heat/engine/resources/quantum/router.py @@ -100,3 +100,11 @@ class RouterGateway(quantum.QuantumResource): client.remove_gateway_router(router_id) except: pass + + +def resource_mapping(): + return { + 'OS::Quantum::Router': Router, + 'OS::Quantum::RouterInterface': RouterInterface, + 'OS::Quantum::RouterGateway': RouterGateway, + } diff --git a/heat/engine/resources/quantum/subnet.py b/heat/engine/resources/quantum/subnet.py index 3c0c13e9..9680f51c 100644 --- a/heat/engine/resources/quantum/subnet.py +++ b/heat/engine/resources/quantum/subnet.py @@ -67,3 +67,9 @@ class Subnet(quantum.QuantumResource): attributes = self.quantum().show_subnet( self.resource_id)['subnet'] return self.handle_get_attributes(self.name, key, attributes) + + +def resource_mapping(): + return { + 'OS::Quantum::Subnet': Subnet, + } diff --git a/heat/engine/resources/register.py b/heat/engine/resources/register.py index 16d6e4eb..a61d657a 100644 --- a/heat/engine/resources/register.py +++ b/heat/engine/resources/register.py @@ -35,38 +35,33 @@ 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 -_resource_classes = { - 'AWS::CloudFormation::Stack': stack.Stack, - 'AWS::CloudFormation::WaitCondition': wait_condition.WaitCondition, - 'AWS::CloudFormation::WaitConditionHandle': - wait_condition.WaitConditionHandle, - 'AWS::CloudWatch::Alarm': cloud_watch.CloudWatchAlarm, - 'AWS::EC2::EIP': eip.ElasticIp, - 'AWS::EC2::EIPAssociation': eip.ElasticIpAssociation, - 'AWS::EC2::Instance': instance.Instance, - 'AWS::EC2::SecurityGroup': security_group.SecurityGroup, - 'AWS::EC2::Volume': volume.Volume, - 'AWS::EC2::VolumeAttachment': volume.VolumeAttachment, - 'AWS::ElasticLoadBalancing::LoadBalancer': loadbalancer.LoadBalancer, - 'AWS::S3::Bucket': s3.S3Bucket, - 'AWS::IAM::User': user.User, - 'AWS::IAM::AccessKey': user.AccessKey, - 'HEAT::HA::Restarter': instance.Restarter, - 'AWS::AutoScaling::LaunchConfiguration': autoscaling.LaunchConfiguration, - 'AWS::AutoScaling::AutoScalingGroup': autoscaling.AutoScalingGroup, - 'AWS::AutoScaling::ScalingPolicy': autoscaling.ScalingPolicy, - 'AWS::RDS::DBInstance': dbinstance.DBInstance, - 'OS::Quantum::FloatingIP': floatingip.FloatingIP, - 'OS::Quantum::FloatingIPAssociation': floatingip.FloatingIPAssociation, - 'OS::Quantum::Net': net.Net, - 'OS::Quantum::Port': port.Port, - 'OS::Quantum::Router': router.Router, - 'OS::Quantum::RouterInterface': router.RouterInterface, - 'OS::Quantum::RouterGateway': router.RouterGateway, - 'OS::Quantum::Subnet': subnet.Subnet, -} +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) diff --git a/heat/engine/resources/s3.py b/heat/engine/resources/s3.py index d69e2abf..f066825b 100644 --- a/heat/engine/resources/s3.py +++ b/heat/engine/resources/s3.py @@ -124,3 +124,9 @@ class S3Bucket(resource.Resource): else: raise exception.InvalidTemplateAttribute(resource=self.name, key=key) + + +def resource_mapping(): + return { + 'AWS::S3::Bucket': S3Bucket, + } diff --git a/heat/engine/resources/security_group.py b/heat/engine/resources/security_group.py index d60860d1..f94006da 100644 --- a/heat/engine/resources/security_group.py +++ b/heat/engine/resources/security_group.py @@ -87,3 +87,9 @@ class SecurityGroup(resource.Resource): def FnGetRefId(self): return unicode(self.name) + + +def resource_mapping(): + return { + 'AWS::EC2::SecurityGroup': SecurityGroup, + } diff --git a/heat/engine/resources/stack.py b/heat/engine/resources/stack.py index fb573782..87ebf72c 100644 --- a/heat/engine/resources/stack.py +++ b/heat/engine/resources/stack.py @@ -107,3 +107,9 @@ class Stack(resource.Resource): resource=self.physical_resource_name(), key=key) return stack.output(op) + + +def resource_mapping(): + return { + 'AWS::CloudFormation::Stack': Stack, + } diff --git a/heat/engine/resources/user.py b/heat/engine/resources/user.py index cd02f11f..f59634fd 100644 --- a/heat/engine/resources/user.py +++ b/heat/engine/resources/user.py @@ -212,3 +212,10 @@ class AccessKey(resource.Resource): logger.info('%s.GetAtt(%s) == %s' % (self.physical_resource_name(), key, log_res)) return unicode(res) + + +def resource_mapping(): + return { + 'AWS::IAM::User': User, + 'AWS::IAM::AccessKey': AccessKey, + } diff --git a/heat/engine/resources/volume.py b/heat/engine/resources/volume.py index 8ef0304a..204d43ad 100644 --- a/heat/engine/resources/volume.py +++ b/heat/engine/resources/volume.py @@ -121,3 +121,10 @@ class VolumeAttachment(resource.Resource): logger.warning('Deleting VolumeAttachment %s %s - not found' % (server_id, volume_id)) return + + +def resource_mapping(): + return { + 'AWS::EC2::Volume': Volume, + 'AWS::EC2::VolumeAttachment': VolumeAttachment, + } diff --git a/heat/engine/resources/wait_condition.py b/heat/engine/resources/wait_condition.py index 33f4e69e..39ce59fa 100644 --- a/heat/engine/resources/wait_condition.py +++ b/heat/engine/resources/wait_condition.py @@ -152,3 +152,10 @@ class WaitCondition(resource.Resource): logger.debug('%s.GetAtt(%s) == %s' % (self.name, key, res)) return unicode(res) + + +def resource_mapping(): + return { + 'AWS::CloudFormation::WaitCondition': WaitCondition, + 'AWS::CloudFormation::WaitConditionHandle': WaitConditionHandle, + } -- 2.45.2