1
# Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/
3
# Permission is hereby granted, free of charge, to any person obtaining a
4
# copy of this software and associated documentation files (the
5
# "Software"), to deal in the Software without restriction, including
6
# without limitation the rights to use, copy, modify, merge, publish, dis-
7
# tribute, sublicense, and/or sell copies of the Software, and to permit
8
# persons to whom the Software is furnished to do so, subject to the fol-
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22
from boto.ec2.ec2object import EC2Object
24
class ReservedInstancesOffering(EC2Object):
26
def __init__(self, connection=None, id=None, instance_type=None,
27
availability_zone=None, duration=None, fixed_price=None,
28
usage_price=None, description=None):
29
EC2Object.__init__(self, connection)
31
self.instance_type = instance_type
32
self.availability_zone = availability_zone
33
self.duration = duration
34
self.fixed_price = fixed_price
35
self.usage_price = usage_price
36
self.description = description
39
return 'ReservedInstanceOffering:%s' % self.id
41
def startElement(self, name, attrs, connection):
44
def endElement(self, name, value, connection):
45
if name == 'reservedInstancesOfferingId':
47
elif name == 'instanceType':
48
self.instance_type = value
49
elif name == 'availabilityZone':
50
self.availability_zone = value
51
elif name == 'duration':
53
elif name == 'fixedPrice':
54
self.fixed_price = value
55
elif name == 'usagePrice':
56
self.usage_price = value
57
elif name == 'productDescription':
58
self.description = value
60
setattr(self, name, value)
63
print 'ID=%s' % self.id
64
print '\tInstance Type=%s' % self.instance_type
65
print '\tZone=%s' % self.availability_zone
66
print '\tDuration=%s' % self.duration
67
print '\tFixed Price=%s' % self.fixed_price
68
print '\tUsage Price=%s' % self.usage_price
69
print '\tDescription=%s' % self.description
71
def purchase(self, instance_count=1):
72
return self.connection.purchase_reserved_instance_offering(self.id, instance_count)
74
class ReservedInstance(ReservedInstancesOffering):
76
def __init__(self, connection=None, id=None, instance_type=None,
77
availability_zone=None, duration=None, fixed_price=None,
78
usage_price=None, description=None,
79
instance_count=None, state=None):
80
ReservedInstancesOffering.__init__(self, connection, id, instance_type,
81
availability_zone, duration, fixed_price,
82
usage_price, description)
83
self.instance_count = instance_count
87
return 'ReservedInstance:%s' % self.id
89
def endElement(self, name, value, connection):
90
if name == 'reservedInstancesId':
92
if name == 'instanceCount':
93
self.instance_count = int(value)
97
ReservedInstancesOffering.endElement(self, name, value, connection)