]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Distribute resource mapping to individual modules
authorZane Bitter <zbitter@redhat.com>
Tue, 27 Nov 2012 14:38:44 +0000 (15:38 +0100)
committerZane Bitter <zbitter@redhat.com>
Wed, 28 Nov 2012 14:26:19 +0000 (15:26 +0100)
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 <zbitter@redhat.com>
18 files changed:
heat/engine/resources/autoscaling.py
heat/engine/resources/cloud_watch.py
heat/engine/resources/dbinstance.py
heat/engine/resources/eip.py
heat/engine/resources/instance.py
heat/engine/resources/loadbalancer.py
heat/engine/resources/quantum/floatingip.py
heat/engine/resources/quantum/net.py
heat/engine/resources/quantum/port.py
heat/engine/resources/quantum/router.py
heat/engine/resources/quantum/subnet.py
heat/engine/resources/register.py
heat/engine/resources/s3.py
heat/engine/resources/security_group.py
heat/engine/resources/stack.py
heat/engine/resources/user.py
heat/engine/resources/volume.py
heat/engine/resources/wait_condition.py

index 897621987484df76e518aeb5719984aad4664c45..f8318fef8a5edf51b94aa581f3393f6c33a16a72 100644 (file)
@@ -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,
+    }
index 6fdb809cebee94feb999c21aa2c24b56754f614b..45b723f7c609aa1c9d8ccc1e9c3ef2521b3b9a4b 100644 (file)
@@ -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,
+    }
index b3b14d99508c717b591e56260825ce22ac940720..f8acebc58e61b040627e8f2d0d193e9cfd3899fc 100644 (file)
@@ -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,
+    }
index b1ddffc11f670531de197e9b53b20b0e16710d0b..c0b6dbf8239476fb07448b104de77bbec9b27237 100644 (file)
@@ -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,
+    }
index d4e42b49af17dc4440bc26a70603813640b63c5e..5d31fc6a83a414d0db360fe05a748e6dc6bfcaaa 100644 (file)
@@ -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,
+    }
index 2d7135c5ce59af2105c50fe0807dbcba34e408c8..dd8950b20bb065ff65d77706f75b0793a4381360 100644 (file)
@@ -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,
+    }
index 4f8a70b192b3e3c8ee576f0b80806c1a180902d5..8739492a2e6d16021977fd797aafcbc4f80fb109 100644 (file)
@@ -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,
+    }
index 02be17ad3c7beccd08811b54e2aa7b44c049292a..ba88945b01246983cdbc43d2f69585965ac04f9b 100644 (file)
@@ -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,
+    }
index b76f699bf668f5c1352598974df9326533b2fa1a..36fa9bece03d4a044c555bb4c5a84c5c07cb2d6a 100644 (file)
@@ -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,
+    }
index 9a13924dc83f4ad78035a35b5985ff728ecd6e2d..6b33a3bfe7fb908fd49aeb777c69eedd37d7c489 100644 (file)
@@ -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,
+    }
index 3c0c13e9424a69d3b8f9d70e77810c5f28e3d6ff..9680f51cddbab452313fb8ade84dec39cea5ec28 100644 (file)
@@ -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,
+    }
index 16d6e4eb3872daa258c69a19c08d7d87b67ebf5e..a61d657add662b922426f4ee6591edf5888ac348 100644 (file)
@@ -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)
index d69e2abf3a8df422f986e30607fc8ba0d0f4d553..f066825ba5b25942c0f5d0459174cf90041b422c 100644 (file)
@@ -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,
+    }
index d60860d1386174de709126181497758370308f93..f94006da1f56b2d9cc958d3cb112d579be59a38a 100644 (file)
@@ -87,3 +87,9 @@ class SecurityGroup(resource.Resource):
 
     def FnGetRefId(self):
         return unicode(self.name)
+
+
+def resource_mapping():
+    return {
+        'AWS::EC2::SecurityGroup': SecurityGroup,
+    }
index fb5737826dec72f40641eb122157e8dda9a66298..87ebf72c42b246758a25956d9d608a7a58c4024a 100644 (file)
@@ -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,
+    }
index cd02f11f3429c8b1f1b69654e86ab6c609aff722..f59634fda42cc3d21ad2e09b21898c6b92a29098 100644 (file)
@@ -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,
+    }
index 8ef0304a67bf81e91ea9d04587bb6e55878af196..204d43ad154f970e136c2e8c6b4d8bacd57c77bd 100644 (file)
@@ -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,
+    }
index 33f4e69eed6c0888b005b11bb56a850f5381c48a..39ce59fa223e54f470e25d97a62ca76b4954940f 100644 (file)
@@ -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,
+    }