22
22
from boto.ec2.ec2object import EC2Object
23
from boto.ec2.blockdevicemapping import BlockDeviceMapping
25
class ProductCodes(list):
27
def startElement(self, name, attrs, connection):
30
def endElement(self, name, value, connection):
31
if name == 'productCode':
24
34
class Image(EC2Object):
26
36
Represents an EC2 Image
32
42
self.location = None
34
44
self.ownerId = None
45
self.owner_alias = None
35
46
self.is_public = False
36
47
self.architecture = None
38
50
self.kernel_id = None
39
51
self.ramdisk_id = None
40
self.product_codes = []
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
42
59
def __repr__(self):
43
60
return 'Image:%s' % self.id
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
45
71
def endElement(self, name, value, connection):
46
72
if name == 'imageId':
72
elif name == 'productCode':
73
self.product_codes.append(value)
92
elif name == 'architecture':
93
self.architecture = value
94
elif name == 'imageType':
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
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
75
113
setattr(self, name, value)
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):
81
121
Runs this instance.
84
@param min_count: The minimum number of instances to start
87
@param max_count: The maximum number of instances to start
89
@type key_name: string
90
@param key_name: The keypair to run this instance with.
92
@type security_groups:
93
@param security_groups:
98
@type addressing_type:
99
@param daddressing_type:
101
@type instance_type: string
102
@param instance_type: The type of instance to run (m1.small, m1.large, m1.xlarge)
124
:param min_count: The minimum number of instances to start
127
:param max_count: The maximum number of instances to start
129
:type key_name: string
130
:param key_name: The keypair to run this instance with.
132
:type security_groups:
133
:param security_groups:
138
:type addressing_type:
139
:param daddressing_type:
141
:type instance_type: string
142
:param instance_type: The type of instance to run (m1.small, m1.large, m1.xlarge)
147
:type kernel_id: string
148
:param kernel_id: The ID of the kernel with which to launch the instances
150
:type ramdisk_id: string
151
:param ramdisk_id: The ID of the RAM disk with which to launch the instances
153
:type monitoring_enabled: bool
154
:param monitoring_enabled: Enable CloudWatch monitoring on the instance.
156
:type subnet_id: string
157
:param subnet_id: The subnet ID within which to launch the instances for VPC.
160
:return: The :class:`boto.ec2.instance.Reservation` associated with the request for machines
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)
112
169
def deregister(self):
113
170
return self.connection.deregister_image(self.id)
154
211
def startElement(self, name, attrs, connection):
212
if name == 'blockDeviceMapping':
213
self.attrs['block_device_mapping'] = BlockDeviceMapping()
214
return self.attrs['block_device_mapping']
157
218
def endElement(self, name, value, connection):
158
219
if name == 'launchPermission':