~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/boto/boto/ec2/reservedinstance.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2006-2009 Mitch Garnaat http://garnaat.org/
 
2
#
 
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-
 
9
# lowing conditions:
 
10
#
 
11
# The above copyright notice and this permission notice shall be included
 
12
# in all copies or substantial portions of the Software.
 
13
#
 
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
 
20
# IN THE SOFTWARE.
 
21
 
 
22
from boto.ec2.ec2object import EC2Object
 
23
 
 
24
class ReservedInstancesOffering(EC2Object):
 
25
    
 
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)
 
30
        self.id = id
 
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
 
37
 
 
38
    def __repr__(self):
 
39
        return 'ReservedInstanceOffering:%s' % self.id
 
40
 
 
41
    def startElement(self, name, attrs, connection):
 
42
        return None
 
43
 
 
44
    def endElement(self, name, value, connection):
 
45
        if name == 'reservedInstancesOfferingId':
 
46
            self.id = value
 
47
        elif name == 'instanceType':
 
48
            self.instance_type = value
 
49
        elif name == 'availabilityZone':
 
50
            self.availability_zone = value
 
51
        elif name == 'duration':
 
52
            self.duration = value
 
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
 
59
        else:
 
60
            setattr(self, name, value)
 
61
 
 
62
    def describe(self):
 
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
 
70
 
 
71
    def purchase(self, instance_count=1):
 
72
        return self.connection.purchase_reserved_instance_offering(self.id, instance_count)
 
73
 
 
74
class ReservedInstance(ReservedInstancesOffering):
 
75
 
 
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
 
84
        self.state = state
 
85
 
 
86
    def __repr__(self):
 
87
        return 'ReservedInstance:%s' % self.id
 
88
 
 
89
    def endElement(self, name, value, connection):
 
90
        if name == 'reservedInstancesId':
 
91
            self.id = value
 
92
        if name == 'instanceCount':
 
93
            self.instance_count = int(value)
 
94
        elif name == 'state':
 
95
            self.state = value
 
96
        else:
 
97
            ReservedInstancesOffering.endElement(self, name, value, connection)