From ea6571d29b202bd8c8e83d2fccdf72029fd2a24f Mon Sep 17 00:00:00 2001 From: Angus Salkeld Date: Fri, 23 Mar 2012 12:04:54 +1100 Subject: [PATCH] Add elastic ip association to parser. Signed-off-by: Angus Salkeld --- heat/engine/parser.py | 60 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/heat/engine/parser.py b/heat/engine/parser.py index 2c8eb734..b9bd97ca 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -18,8 +18,8 @@ import logging logger = logging.getLogger('heat.engine.parser') -#parse_debug = False -parse_debug = True +parse_debug = False +#parse_debug = True class Resource(object): @@ -90,6 +90,58 @@ class GenericResource(Resource): print 'Starting GenericResource %s' % self.name +class ElasticIp(Resource): + def __init__(self, name, json_snippet, stack): + super(ElasticIp, self).__init__(name, json_snippet, stack) + self.instance_id = '' + + if self.t.has_key('Properties') and self.t['Properties'].has_key('Domain'): + print '*** can\'t support Domain %s yet' % (self.t['Properties']['Domain']) + + def start(self): + if self.state != None: + return + self.state = Resource.CREATE_IN_PROGRESS + super(ElasticIp, self).start() + self.instance_id = 'eip-000003' + + def FnGetRefId(self): + return unicode('0.0.0.0') + + def FnGetAtt(self, key): + return unicode(self.instance_id) + +class ElasticIpAssociation(Resource): + def __init__(self, name, json_snippet, stack): + super(ElasticIpAssociation, self).__init__(name, json_snippet, stack) + + # note we only support already assigned ipaddress + # + # Done with: + # nova-manage floating create 172.31.0.224/28 + # euca-allocate-address + # + + if not self.t['Properties'].has_key('EIP'): + print '*** can\'t support this yet' + if self.t['Properties'].has_key('AllocationId'): + print '*** can\'t support AllocationId %s yet' % (self.t['Properties']['AllocationId']) + + def FnGetRefId(self): + if not self.t['Properties'].has_key('EIP'): + return unicode('0.0.0.0') + else: + return unicode(self.t['Properties']['EIP']) + + def start(self): + + if self.state != None: + return + self.state = Resource.CREATE_IN_PROGRESS + super(ElasticIpAssociation, self).start() + print '$ euca-associate-address -i %s %s' % (self.t['Properties']['InstanceId'], + self.t['Properties']['EIP']) + class Volume(Resource): def __init__(self, name, json_snippet, stack): super(Volume, self).__init__(name, json_snippet, stack) @@ -256,6 +308,10 @@ class Stack: self.resources[r] = Volume(r, self.t['Resources'][r], self) elif type == 'AWS::EC2::VolumeAttachment': self.resources[r] = VolumeAttachment(r, self.t['Resources'][r], self) + elif type == 'AWS::EC2::EIP': + self.resources[r] = ElasticIp(r, self.t['Resources'][r], self) + elif type == 'AWS::EC2::EIPAssociation': + self.resources[r] = ElasticIpAssociation(r, self.t['Resources'][r], self) else: self.resources[r] = GenericResource(r, self.t['Resources'][r], self) -- 2.45.2