From a4ad1da82a1f71f257aac2b6797834a37a242975 Mon Sep 17 00:00:00 2001 From: Marco Yuen Date: Mon, 31 Jan 2011 15:44:54 -0500 Subject: [PATCH] Update RSpec, and create_slice() GENICLOUD-4 Bundles are dynamically generated based on currently available images. create_slice() can figure the ids for the images based on bundle name. --- sfa/managers/aggregate_manager_eucalyptus.py | 52 ++++++++++---------- sfa/managers/eucalyptus/eucalyptus.rnc | 41 ++++++++++----- sfa/managers/eucalyptus/eucalyptus.rng | 46 ++++++++++++----- 3 files changed, 89 insertions(+), 50 deletions(-) diff --git a/sfa/managers/aggregate_manager_eucalyptus.py b/sfa/managers/aggregate_manager_eucalyptus.py index ce44fa7c..721ba6ae 100644 --- a/sfa/managers/aggregate_manager_eucalyptus.py +++ b/sfa/managers/aggregate_manager_eucalyptus.py @@ -112,17 +112,15 @@ def init_server(): cloudURL = cloudURL.replace('http://', '') (cloud['ip'], parts) = cloudURL.split(':') - # Read the bundle images config file. - if not os.path.exists('/etc/sfa/bundle_image.conf') and \ - not os.path.exists('bundle_image.conf'): - print >>sys.stderr, 'Could not find bundle_image.conf' - raise Exception('Could not find bundle_image.conf') - imageBundleParser = ConfigParser() - imageBundleParser.read(['/etc/sfa/bundle_image.conf', 'bundle_image.conf']) + # Create image bundles + images = getEucaConnection().get_all_images() + cloud['images'] = images cloud['imageBundles'] = {} - for bundle in imageBundleParser.sections(): - info = dict(imageBundleParser.items(bundle)) - cloud['imageBundles'][bundle] = info + for i in images: + if i.type != 'machine' or i.kernel_id is None: continue + name = os.path.dirname(i.location) + detail = {'imageID' : i.id, 'kernelID' : i.kernel_id, 'ramdiskID' : i.ramdisk_id} + cloud['imageBundles'][name] = detail # Initialize sqlite3 database. dbPath = '/etc/sfa/db' @@ -296,8 +294,6 @@ class EucaRSpecBuilder(object): xml << eucaInst['state'] with xml.public_dns: xml << eucaInst['public_dns'] - with xml.keypair: - xml << eucaInst['key'] def __imageBundleXML(self, bundles): xml = self.eucaRSpec @@ -306,8 +302,7 @@ class EucaRSpecBuilder(object): print >>sys.stderr, 'bundle: %r' % bundle sys.stderr.flush() with xml.bundle(id=bundle): - with xml.description: - xml << bundles[bundle]['description'] + xml << '' ## # Creates the Images stanza. @@ -354,8 +349,8 @@ class EucaRSpecBuilder(object): with xml.cloud(id=cloud['name']): with xml.ipv4: xml << cloud['ip'] - self.__keyPairsXML(cloud['keypairs']) - self.__imagesXML(cloud['images']) + #self.__keyPairsXML(cloud['keypairs']) + #self.__imagesXML(cloud['images']) self.__imageBundleXML(cloud['imageBundles']) self.__clustersXML(cloud['clusters']) return str(xml) @@ -427,6 +422,12 @@ def get_rspec(api, creds, options): # Images images = conn.get_all_images() cloud['images'] = images + cloud['imageBundles'] = {} + for i in images: + if i.type != 'machine' or i.kernel_id is None: continue + name = os.path.dirname(i.location) + detail = {'imageID' : i.id, 'kernelID' : i.kernel_id, 'ramdiskID' : i.ramdisk_id} + cloud['imageBundles'][name] = detail # Key Pairs keyPairs = conn.get_all_key_pairs() @@ -534,21 +535,20 @@ def create_slice(api, xrn, creds, xml, users): if requests: # Get all the public keys associate with slice. pubKeys = getKeysForSlice(s.slice_hrn) - print sys.stderr, "Passing the following keys to the instance:\n%s" % pubKeys + print >>sys.stderr, "Passing the following keys to the instance:\n%s" % pubKeys for req in requests: vmTypeElement = req.getparent() instType = vmTypeElement.get('name') numInst = int(req.find('instances').text) - instKernel = req.find('kernel_image').get('id') - instDiskImg = req.find('disk_image').get('id') - instKey = req.find('keypair').text - ramDiskElement = req.find('ramdisk') - ramDiskAttr = ramDiskElement.attrib - if 'id' in ramDiskAttr: - instRamDisk = ramDiskAttr['id'] - else: - instRamDisk = None + bundleName = req.find('bundle').text + if not cloud['imageBundles'][bundleName]: + print >>sys.stderr, 'Cannot find bundle %s' % bundleName + bundleInfo = cloud['imageBundles'][bundleName] + instKernel = bundleInfo['kernelID'] + instDiskImg = bundleInfo['imageID'] + instRamDisk = bundleInfo['ramdiskID'] + instKey = None # Create the instances for i in range(0, numInst): diff --git a/sfa/managers/eucalyptus/eucalyptus.rnc b/sfa/managers/eucalyptus/eucalyptus.rnc index 271ca812..49c1f339 100644 --- a/sfa/managers/eucalyptus/eucalyptus.rnc +++ b/sfa/managers/eucalyptus/eucalyptus.rnc @@ -1,20 +1,32 @@ start = RSpec RSpec = element RSpec { - attribute type { xsd:NMTOKEN }, - cloud + attribute type { xsd:NMTOKEN }, + cloud } cloud = element cloud { - attribute id { xsd:NMTOKEN }, - user_info?, - ipv4, - keypairs, - images, - cluster+ + attribute id { xsd:NMTOKEN }, + user_info?, + ipv4, + bundles, + #keypairs, + #images, + cluster+ } + user_info = element user_info { - credential + element credential { text } } + keypairs = element keypairs { keypair+ } +keypair = element keypair { text } + +bundles = element bundles { + element bundle { + attribute id { xsd:ID }, + empty + }+ +} + images = element images { image+ } image = element image { attribute id { xsd:ID }, @@ -39,13 +51,22 @@ vm_type = element vm_type { request?, euca_instances? } + request = element request { + instances, + element bundle { + xsd:IDREF + } +} + +oldrequest = element oldrequest { instances, kernel_image, ramdisk, disk_image, keypair } + euca_instances = element euca_instances { euca_instance+ } @@ -55,9 +76,7 @@ euca_instance = element euca_instance { public_dns, keypair } -credential = element credential { text } ipv4 = element ipv4 { text } -keypair = element keypair { text } type = element type { text } arch = element arch { text } state = element state { text } diff --git a/sfa/managers/eucalyptus/eucalyptus.rng b/sfa/managers/eucalyptus/eucalyptus.rng index 43c3f9a7..ec91e05b 100644 --- a/sfa/managers/eucalyptus/eucalyptus.rng +++ b/sfa/managers/eucalyptus/eucalyptus.rng @@ -20,16 +20,21 @@ - - + + - + + + @@ -39,6 +44,23 @@ + + + + + + + + + + + + + + + + + @@ -93,6 +115,14 @@ + + + + + + + + @@ -117,21 +147,11 @@ - - - - - - - - - - -- 2.47.0