- rspecXML = RSpec(xml)
- rspecDict = rspecXML.toDict()
- request = rspecDict['RSpec']['Request']
- for cloudSpec in request:
- cloudSpec = cloudSpec['CloudSpec']
- for cloudReqInfo in cloudSpec:
- for nodeReq in cloudReqInfo['Node']:
- instKernel = nodeReq['Kernel'][0]
- instDiskImg = nodeReq['DiskImage'][0]
- instRamDisk = nodeReq['Ramdisk'][0]
- instKey = nodeReq['Key'][0]
- instType = nodeReq['instanceType']
- numInst = int(nodeReq['number'])
-
- # Ramdisk is optional.
- if isinstance(instRamDisk, dict):
- instRamDisk = None
-
- # Create the instances
- for i in range(0, numInst):
- eucaInst = EucaInstance(slice = s,
- kernel_id = instKernel,
- image_id = instDiskImg,
- ramdisk_id = instRamDisk,
- key_pair = instKey,
- inst_type = instType)
- eucaInst.reserveInstance(conn)
+ requests = rspecXML.findall('.//request')
+ 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
+
+ # Create the instances
+ for i in range(0, numInst):
+ eucaInst = EucaInstance(slice = s,
+ kernel_id = instKernel,
+ image_id = instDiskImg,
+ ramdisk_id = instRamDisk,
+ key_pair = instKey,
+ inst_type = instType)
+ eucaInst.reserveInstance(conn)