+##
+# A representation of an Eucalyptus instance. This is a support class
+# for instance <-> slice mapping.
+#
+class EucaInstance(SQLObject):
+ instance_id = StringCol(unique=True, default=None)
+ kernel_id = StringCol()
+ image_id = StringCol()
+ ramdisk_id = StringCol()
+ inst_type = StringCol()
+ key_pair = StringCol()
+ slice = ForeignKey('Slice')
+
+ ##
+ # Contacts Eucalyptus and tries to reserve this instance.
+ #
+ # @param botoConn A connection to Eucalyptus.
+ #
+ def reserveInstance(self, botoConn):
+ print >>sys.stderr, 'Reserving an instance. image: %s, kernel: %s, ramdisk: %s, type: %s, key: %s' % \
+ (self.image_id, self.kernel_id, self.ramdisk_id, self.inst_type, self.key_pair)
+
+ try:
+ reservation = botoConn.run_instances(self.image_id,
+ kernel_id = self.kernel_id,
+ ramdisk_id = self.ramdisk_id,
+ instance_type = self.inst_type,
+ key_name = self.key_pair)
+ for instance in reservation.instances:
+ self.instance_id = instance.id
+
+ # If there is an error, destroy itself.
+ except EC2ResponseError, ec2RespErr:
+ errTree = ET.fromstring(ec2RespErr.body)
+ msg = errTree.find('.//Message')
+ print >>sys.stderr, msg.text
+ self.destroySelf()
+
+##
+# A representation of a PlanetLab slice. This is a support class
+# for instance <-> slice mapping.
+#
+class Slice(SQLObject):
+ slice_hrn = StringCol()
+ #slice_index = DatabaseIndex('slice_hrn')
+ instances = MultipleJoin('EucaInstance')
+