~ubuntu-branches/ubuntu/raring/python-boto/raring-proposed

« back to all changes in this revision

Viewing changes to boto/ec2/image.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Moser
  • Date: 2010-01-05 15:12:37 UTC
  • mfrom: (4.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100105151237-skgxjkyogir1vl0k
Tags: 1.9b-1ubuntu1
* merge Loic's changes made in 1.8d-1ubuntu2
* Rename Vcs-* to XS-Debian-Vcs-*.
* Run testsuite during build but ignore failures since it currently doesn't
  pass.
* Add ${misc:Depends}.
* Add XB-Python-Version: ${python:Versions}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
# IN THE SOFTWARE.
21
21
 
22
22
from boto.ec2.ec2object import EC2Object
23
 
 
 
23
from boto.ec2.blockdevicemapping import BlockDeviceMapping
 
24
 
 
25
class ProductCodes(list):
 
26
 
 
27
    def startElement(self, name, attrs, connection):
 
28
        pass
 
29
 
 
30
    def endElement(self, name, value, connection):
 
31
        if name == 'productCode':
 
32
            self.append(value)
 
33
    
24
34
class Image(EC2Object):
25
35
    """
26
36
    Represents an EC2 Image
32
42
        self.location = None
33
43
        self.state = None
34
44
        self.ownerId = None
 
45
        self.owner_alias = None
35
46
        self.is_public = False
36
47
        self.architecture = None
 
48
        self.platform = None
37
49
        self.type = None
38
50
        self.kernel_id = None
39
51
        self.ramdisk_id = None
40
 
        self.product_codes = []
 
52
        self.name = None
 
53
        self.description = None
 
54
        self.product_codes = ProductCodes()
 
55
        self.block_device_mapping = None
 
56
        self.root_device_type = None
 
57
        self.root_device_name = None
41
58
 
42
59
    def __repr__(self):
43
60
        return 'Image:%s' % self.id
44
61
 
 
62
    def startElement(self, name, attrs, connection):
 
63
        if name == 'blockDeviceMapping':
 
64
            self.block_device_mapping = BlockDeviceMapping()
 
65
            return self.block_device_mapping
 
66
        elif name == 'productCodes':
 
67
            return self.product_codes
 
68
        else:
 
69
            return None
 
70
 
45
71
    def endElement(self, name, value, connection):
46
72
        if name == 'imageId':
47
73
            self.id = value
51
77
            self.state = value
52
78
        elif name == 'imageOwnerId':
53
79
            self.ownerId = value
54
 
        elif name == 'imageType':
55
 
            self.type = value
56
 
        elif name == 'kernelId':
57
 
            self.kernel_id = value
58
 
        elif name == 'ramdiskId':
59
 
            self.ramdisk_id = value
60
80
        elif name == 'isPublic':
61
81
            if value == 'false':
62
82
                self.is_public = False
69
89
                        self.id
70
90
                    )
71
91
                )
72
 
        elif name == 'productCode':
73
 
            self.product_codes.append(value)
 
92
        elif name == 'architecture':
 
93
            self.architecture = value
 
94
        elif name == 'imageType':
 
95
            self.type = value
 
96
        elif name == 'kernelId':
 
97
            self.kernel_id = value
 
98
        elif name == 'ramdiskId':
 
99
            self.ramdisk_id = value
 
100
        elif name == 'imageOwnerAlias':
 
101
            self.owner_alias = value
 
102
        elif name == 'platform':
 
103
            self.platform = value
 
104
        elif name == 'name':
 
105
            self.name = value
 
106
        elif name == 'description':
 
107
            self.description = value
 
108
        elif name == 'rootDeviceType':
 
109
            self.root_device_type = value
 
110
        elif name == 'rootDeviceName':
 
111
            self.root_device_name = value
74
112
        else:
75
113
            setattr(self, name, value)
76
114
 
77
115
    def run(self, min_count=1, max_count=1, key_name=None,
78
116
            security_groups=None, user_data=None,
79
 
            addressing_type=None, instance_type='m1.small', placement=None):
 
117
            addressing_type=None, instance_type='m1.small', placement=None,
 
118
            kernel_id=None, ramdisk_id=None,
 
119
            monitoring_enabled=False, subnet_id=None):
80
120
        """
81
121
        Runs this instance.
82
122
        
83
 
        @type min_count: int
84
 
        @param min_count: The minimum number of instances to start
85
 
        
86
 
        @type max_count: int
87
 
        @param max_count: The maximum number of instances to start
88
 
        
89
 
        @type key_name: string
90
 
        @param key_name: The keypair to run this instance with.
91
 
        
92
 
        @type security_groups: 
93
 
        @param security_groups:
94
 
        
95
 
        @type user_data: 
96
 
        @param user_data:
97
 
        
98
 
        @type addressing_type: 
99
 
        @param daddressing_type:
100
 
        
101
 
        @type instance_type: string
102
 
        @param instance_type: The type of instance to run (m1.small, m1.large, m1.xlarge)
103
 
        
104
 
        @type placement: 
105
 
        @param placement: 
 
123
        :type min_count: int
 
124
        :param min_count: The minimum number of instances to start
 
125
        
 
126
        :type max_count: int
 
127
        :param max_count: The maximum number of instances to start
 
128
        
 
129
        :type key_name: string
 
130
        :param key_name: The keypair to run this instance with.
 
131
        
 
132
        :type security_groups: 
 
133
        :param security_groups:
 
134
        
 
135
        :type user_data: 
 
136
        :param user_data:
 
137
        
 
138
        :type addressing_type: 
 
139
        :param daddressing_type:
 
140
        
 
141
        :type instance_type: string
 
142
        :param instance_type: The type of instance to run (m1.small, m1.large, m1.xlarge)
 
143
        
 
144
        :type placement: 
 
145
        :param placement:
 
146
 
 
147
        :type kernel_id: string
 
148
        :param kernel_id: The ID of the kernel with which to launch the instances
 
149
        
 
150
        :type ramdisk_id: string
 
151
        :param ramdisk_id: The ID of the RAM disk with which to launch the instances
 
152
        
 
153
        :type monitoring_enabled: bool
 
154
        :param monitoring_enabled: Enable CloudWatch monitoring on the instance.
 
155
        
 
156
        :type subnet_id: string
 
157
        :param subnet_id: The subnet ID within which to launch the instances for VPC.
 
158
        
 
159
        :rtype: Reservation
 
160
        :return: The :class:`boto.ec2.instance.Reservation` associated with the request for machines
106
161
        """
107
162
        return self.connection.run_instances(self.id, min_count, max_count,
108
163
                                             key_name, security_groups,
109
164
                                             user_data, addressing_type,
110
 
                                             instance_type, placement)
 
165
                                             instance_type, placement,
 
166
                                             kernel_id, ramdisk_id,
 
167
                                             monitoring_enabled, subnet_id)
111
168
 
112
169
    def deregister(self):
113
170
        return self.connection.deregister_image(self.id)
152
209
        self.attrs = {}
153
210
 
154
211
    def startElement(self, name, attrs, connection):
155
 
        return None
 
212
        if name == 'blockDeviceMapping':
 
213
            self.attrs['block_device_mapping'] = BlockDeviceMapping()
 
214
            return self.attrs['block_device_mapping']
 
215
        else:
 
216
            return None
156
217
 
157
218
    def endElement(self, name, value, connection):
158
219
        if name == 'launchPermission':