Merge branch 'master' of ssh://git.planet-lab.org/git/sfa
authorMarco Yuen <marcoy@gmail.com>
Thu, 3 Feb 2011 14:55:18 +0000 (09:55 -0500)
committerMarco Yuen <marcoy@gmail.com>
Thu, 3 Feb 2011 14:55:18 +0000 (09:55 -0500)
sfa/managers/aggregate_manager_eucalyptus.py
sfa/managers/eucalyptus/eucalyptus.rnc
sfa/managers/eucalyptus/eucalyptus.rng

index 09715cc..021e7d5 100644 (file)
@@ -112,6 +112,16 @@ def init_server():
         cloudURL = cloudURL.replace('http://', '')
     (cloud['ip'], parts) = cloudURL.split(':')
 
+    # Create image bundles
+    images = getEucaConnection().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
+
     # Initialize sqlite3 database.
     dbPath = '/etc/sfa/db'
     dbName = 'euca_aggregate.db'
@@ -275,8 +285,6 @@ class EucaRSpecBuilder(object):
                                 xml << str(inst[4])
                             with xml.disk_space(unit='GB'):
                                 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:
@@ -286,8 +294,13 @@ 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
+        with xml.bundles:
+            for bundle in bundles.keys():
+                with xml.bundle(id=bundle):
+                    xml << ''
 
     ##
     # Creates the Images stanza.
@@ -334,8 +347,9 @@ 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)
 
@@ -406,6 +420,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()
@@ -437,7 +457,7 @@ def get_rspec(api, creds, options):
                 for instance in reservation.instances:
                     instances.append(instance)
 
-            # Construct a dictory for the EucaRSpecBuilder
+            # Construct a dictionary for the EucaRSpecBuilder
             instancesDict = {}
             for instance in instances:
                 instList = instancesDict.setdefault(instance.instance_type, [])
@@ -513,21 +533,21 @@ 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
+        sys.stderr.flush()
     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):
index 271ca81..49c1f33 100644 (file)
@@ -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 }
index 43c3f9a..ec91e05 100644 (file)
         <ref name="user_info"/>
       </optional>
       <ref name="ipv4"/>
-      <ref name="keypairs"/>
-      <ref name="images"/>
+      <ref name="bundles"/>
       <oneOrMore>
+        <!--
+          keypairs,
+          images,
+        -->
         <ref name="cluster"/>
       </oneOrMore>
     </element>
   </define>
   <define name="user_info">
     <element name="user_info">
-      <ref name="credential"/>
+      <element name="credential">
+        <text/>
+      </element>
     </element>
   </define>
   <define name="keypairs">
       </oneOrMore>
     </element>
   </define>
+  <define name="keypair">
+    <element name="keypair">
+      <text/>
+    </element>
+  </define>
+  <define name="bundles">
+    <element name="bundles">
+      <oneOrMore>
+        <element name="bundle">
+          <attribute name="id">
+            <data type="ID"/>
+          </attribute>
+          <empty/>
+        </element>
+      </oneOrMore>
+    </element>
+  </define>
   <define name="images">
     <element name="images">
       <oneOrMore>
   </define>
   <define name="request">
     <element name="request">
+      <ref name="instances"/>
+      <element name="bundle">
+        <data type="IDREF"/>
+      </element>
+    </element>
+  </define>
+  <define name="oldrequest">
+    <element name="oldrequest">
       <ref name="instances"/>
       <ref name="kernel_image"/>
       <ref name="ramdisk"/>
       <ref name="keypair"/>
     </element>
   </define>
-  <define name="credential">
-    <element name="credential">
-      <text/>
-    </element>
-  </define>
   <define name="ipv4">
     <element name="ipv4">
       <text/>
     </element>
   </define>
-  <define name="keypair">
-    <element name="keypair">
-      <text/>
-    </element>
-  </define>
   <define name="type">
     <element name="type">
       <text/>