X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmanagers%2Faggregate_manager_eucalyptus.py;h=e62381a12470b493aa8db2a36ad27fcd4e0b8ed1;hb=52b4cb21f33f380f55d467709b1b9bc8ba84bd57;hp=41985cab98c5b36d4de25c87f5367394ac892d8f;hpb=1b3af3aefd6abdf0733c3824d1013d2c90a41dcd;p=sfa.git diff --git a/sfa/managers/aggregate_manager_eucalyptus.py b/sfa/managers/aggregate_manager_eucalyptus.py index 41985cab..e62381a1 100644 --- a/sfa/managers/aggregate_manager_eucalyptus.py +++ b/sfa/managers/aggregate_manager_eucalyptus.py @@ -370,7 +370,10 @@ def get_rspec(api, xrn, origin_hrn): instanceId.append(instance.instance_id) # Get the information about those instances using their ids. - reservations = conn.get_all_instances(instanceId) + if len(instanceId) > 0: + reservations = conn.get_all_instances(instanceId) + else: + reservations = [] for reservation in reservations: for instance in reservation.instances: instances.append(instance) @@ -396,6 +399,11 @@ def get_rspec(api, xrn, origin_hrn): rspec = EucaRSpecBuilder(cloud).toXML() + # Remove the instances records so next time they won't + # show up. + if 'instances' in cloud: + del cloud['instances'] + return rspec """ @@ -410,12 +418,6 @@ def create_slice(api, xrn, xml): print >>sys.stderr, 'Error: Cannot create a connection to Eucalyptus' return False - # Get the slice from db or create one. - # XXX: For testing purposes, I'll just create the slice. - #s = Slice.select(Slice.q.slice_hrn == hrn).getOne(None) - #if s is None: - s = Slice(slice_hrn = hrn) - # Validate RSpec schemaXML = ET.parse(EUCALYPTUS_RSPEC_SCHEMA) rspecValidator = ET.RelaxNG(schemaXML) @@ -423,9 +425,31 @@ def create_slice(api, xrn, xml): if not rspecValidator(rspecXML): error = rspecValidator.error_log.last_error message = '%s (line %s)' % (error.message, error.line) - raise InvalidRSpec(message) + # XXX: InvalidRSpec is new. Currently, I am not working with Trunk code. + #raise InvalidRSpec(message) + raise Exception(message) - # Process the RSpec + # Get the slice from db or create one. + s = Slice.select(Slice.q.slice_hrn == hrn).getOne(None) + if s is None: + s = Slice(slice_hrn = hrn) + + # Process any changes in existing instance allocation + pendingRmInst = [] + for sliceInst in s.instances: + pendingRmInst.append(sliceInst.instance_id) + existingInstGroup = rspecXML.findall('.//euca_instances') + for instGroup in existingInstGroup: + for existingInst in instGroup: + if existingInst.get('id') in pendingRmInst: + pendingRmInst.remove(existingInst.get('id')) + for inst in pendingRmInst: + print >>sys.stderr, 'Instance %s will be terminated' % inst + dbInst = EucaInstance.select(EucaInstance.q.instance_id == inst).getOne(None) + dbInst.destroySelf() + conn.terminate_instances(pendingRmInst) + + # Process new instance requests requests = rspecXML.findall('.//request') for req in requests: vmTypeElement = req.getparent() @@ -457,13 +481,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', 'planetcloud.pc.test', 'planetcloud.pc.marcoy') - print rspec + #rspec = get_rspec('euca', 'planetcloud.pc.test', 'planetcloud.pc.marcoy') + #print rspec if __name__ == "__main__": main()