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 <zbitter@redhat.com>
This commit is contained in:
Zane Bitter 2012-11-27 15:38:44 +01:00
parent b0026981a5
commit a0cf5dfa5c
18 changed files with 137 additions and 30 deletions

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}

View 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)

View 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,
}

View File

@ -87,3 +87,9 @@ class SecurityGroup(resource.Resource):
def FnGetRefId(self):
return unicode(self.name)
def resource_mapping():
return {
'AWS::EC2::SecurityGroup': SecurityGroup,
}

View 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,
}

View 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,
}

View 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,
}

View 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,
}