From: Andy Bavier Date: Fri, 12 Feb 2010 16:23:26 +0000 (+0000) Subject: Return information about instances bound to a slice X-Git-Tag: sfa-0.9-11~110 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=1b3af3aefd6abdf0733c3824d1013d2c90a41dcd;p=sfa.git Return information about instances bound to a slice --- diff --git a/sfa/managers/aggregate_manager_eucalyptus.py b/sfa/managers/aggregate_manager_eucalyptus.py index 321ab895..41985cab 100644 --- a/sfa/managers/aggregate_manager_eucalyptus.py +++ b/sfa/managers/aggregate_manager_eucalyptus.py @@ -209,7 +209,9 @@ class EucaRSpecBuilder(object): # @param clusters Clusters information. # def __clustersXML(self, clusters): + cloud = self.cloudInfo xml = self.eucaRSpec + for cluster in clusters: instances = cluster['instances'] with xml.cluster(id=cluster['name']): @@ -230,7 +232,17 @@ class EucaRSpecBuilder(object): xml << str(inst[5]) if inst[0] == 'm1.small': self.__requestXML(1, 'emi-88760F45', 'eki-F26610C6', 'cortex') - + if 'instances' in cloud and inst[0] in cloud['instances']: + existingEucaInstances = cloud['instances'][inst[0]] + with xml.euca_instances: + for eucaInst in existingEucaInstances: + with xml.euca_instance(id=eucaInst['id']): + with xml.state: + xml << eucaInst['state'] + with xml.public_dns: + xml << eucaInst['public_dns'] + with xml.keypair: + xml << eucaInst['key'] ## # Creates the Images stanza. @@ -345,6 +357,38 @@ def get_rspec(api, xrn, origin_hrn): # Key Pairs keyPairs = conn.get_all_key_pairs() cloud['keypairs'] = keyPairs + + if hrn: + instanceId = [] + instances = [] + + # Get the instances that belong to the given slice from sqlite3 + # XXX use getOne() in production because the slice's hrn is supposed + # to be unique. For testing, uniqueness is turned off in the db. + theSlice = list(Slice.select(Slice.q.slice_hrn == hrn))[-1] + for instance in theSlice.instances: + instanceId.append(instance.instance_id) + + # Get the information about those instances using their ids. + reservations = conn.get_all_instances(instanceId) + for reservation in reservations: + for instance in reservation.instances: + instances.append(instance) + + # Construct a dictory for the EucaRSpecBuilder + instancesDict = {} + for instance in instances: + instList = instancesDict.setdefault(instance.instance_type, []) + instInfoDict = {} + + instInfoDict['id'] = instance.id + instInfoDict['public_dns'] = instance.public_dns_name + instInfoDict['state'] = instance.state + instInfoDict['key'] = instance.key_name + + instList.append(instInfoDict) + cloud['instances'] = instancesDict + except EC2ResponseError, ec2RespErr: errTree = ET.fromstring(ec2RespErr.body) errMsgE = errTree.find('.//Message') @@ -413,13 +457,13 @@ def create_slice(api, xrn, xml): def main(): init_server() - theRSpec = None - with open(sys.argv[1]) as xml: - theRSpec = xml.read() - create_slice(None, 'planetcloud.pc.test', theRSpec) + #theRSpec = None + #with open(sys.argv[1]) as xml: + #theRSpec = xml.read() + #create_slice(None, 'planetcloud.pc.test', theRSpec) - #rspec = get_rspec('euca', 'hrn:euca', 'oring_hrn') - #print rspec + rspec = get_rspec('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy') + print rspec if __name__ == "__main__": main() diff --git a/sfa/managers/eucalyptus/eucalyptus.rnc b/sfa/managers/eucalyptus/eucalyptus.rnc index c2fbc20d..271ca812 100644 --- a/sfa/managers/eucalyptus/eucalyptus.rnc +++ b/sfa/managers/eucalyptus/eucalyptus.rnc @@ -36,7 +36,8 @@ vm_type = element vm_type { cores, memory, disk_space, - request? + request?, + euca_instances? } request = element request { instances, @@ -45,6 +46,15 @@ request = element request { disk_image, keypair } +euca_instances = element euca_instances { + euca_instance+ +} +euca_instance = element euca_instance { + attribute id { xsd:ID }, + state, + public_dns, + keypair +} credential = element credential { text } ipv4 = element ipv4 { text } keypair = element keypair { text } @@ -55,6 +65,7 @@ location = element location { text } free_slots = element free_slots { text } max_instances = element max_instances { text } cores = element cores { text } +public_dns = element public_dns { text } memory = element memory { attribute unit { xsd:NMTOKEN }, text diff --git a/sfa/managers/eucalyptus/eucalyptus.rng b/sfa/managers/eucalyptus/eucalyptus.rng index 5cfc8c59..43c3f9a7 100644 --- a/sfa/managers/eucalyptus/eucalyptus.rng +++ b/sfa/managers/eucalyptus/eucalyptus.rng @@ -86,6 +86,9 @@ + + + @@ -97,6 +100,23 @@ + + + + + + + + + + + + + + + + + @@ -147,6 +167,11 @@ + + + + +