Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/boto/ec2/image.py @ 0:d30785e31577 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
| author | guerler |
|---|---|
| date | Fri, 31 Jul 2020 00:18:57 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d30785e31577 |
|---|---|
| 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ | |
| 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. | |
| 3 # | |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a | |
| 5 # copy of this software and associated documentation files (the | |
| 6 # "Software"), to deal in the Software without restriction, including | |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- | |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit | |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- | |
| 10 # lowing conditions: | |
| 11 # | |
| 12 # The above copyright notice and this permission notice shall be included | |
| 13 # in all copies or substantial portions of the Software. | |
| 14 # | |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
| 21 # IN THE SOFTWARE. | |
| 22 | |
| 23 from boto.ec2.ec2object import EC2Object, TaggedEC2Object | |
| 24 from boto.ec2.blockdevicemapping import BlockDeviceMapping | |
| 25 | |
| 26 | |
| 27 class ProductCodes(list): | |
| 28 def startElement(self, name, attrs, connection): | |
| 29 pass | |
| 30 | |
| 31 def endElement(self, name, value, connection): | |
| 32 if name == 'productCode': | |
| 33 self.append(value) | |
| 34 | |
| 35 | |
| 36 class BillingProducts(list): | |
| 37 def startElement(self, name, attrs, connection): | |
| 38 pass | |
| 39 | |
| 40 def endElement(self, name, value, connection): | |
| 41 if name == 'billingProduct': | |
| 42 self.append(value) | |
| 43 | |
| 44 | |
| 45 class Image(TaggedEC2Object): | |
| 46 """ | |
| 47 Represents an EC2 Image | |
| 48 """ | |
| 49 | |
| 50 def __init__(self, connection=None): | |
| 51 super(Image, self).__init__(connection) | |
| 52 self.id = None | |
| 53 self.location = None | |
| 54 self.state = None | |
| 55 self.ownerId = None # for backwards compatibility | |
| 56 self.owner_id = None | |
| 57 self.owner_alias = None | |
| 58 self.is_public = False | |
| 59 self.architecture = None | |
| 60 self.platform = None | |
| 61 self.type = None | |
| 62 self.kernel_id = None | |
| 63 self.ramdisk_id = None | |
| 64 self.name = None | |
| 65 self.description = None | |
| 66 self.product_codes = ProductCodes() | |
| 67 self.billing_products = BillingProducts() | |
| 68 self.block_device_mapping = None | |
| 69 self.root_device_type = None | |
| 70 self.root_device_name = None | |
| 71 self.virtualization_type = None | |
| 72 self.hypervisor = None | |
| 73 self.instance_lifecycle = None | |
| 74 self.sriov_net_support = None | |
| 75 | |
| 76 def __repr__(self): | |
| 77 return 'Image:%s' % self.id | |
| 78 | |
| 79 def startElement(self, name, attrs, connection): | |
| 80 retval = super(Image, self).startElement(name, attrs, connection) | |
| 81 if retval is not None: | |
| 82 return retval | |
| 83 if name == 'blockDeviceMapping': | |
| 84 self.block_device_mapping = BlockDeviceMapping() | |
| 85 return self.block_device_mapping | |
| 86 elif name == 'productCodes': | |
| 87 return self.product_codes | |
| 88 elif name == 'billingProducts': | |
| 89 return self.billing_products | |
| 90 else: | |
| 91 return None | |
| 92 | |
| 93 def endElement(self, name, value, connection): | |
| 94 if name == 'imageId': | |
| 95 self.id = value | |
| 96 elif name == 'imageLocation': | |
| 97 self.location = value | |
| 98 elif name == 'imageState': | |
| 99 self.state = value | |
| 100 elif name == 'imageOwnerId': | |
| 101 self.ownerId = value # for backwards compatibility | |
| 102 self.owner_id = value | |
| 103 elif name == 'isPublic': | |
| 104 if value == 'false': | |
| 105 self.is_public = False | |
| 106 elif value == 'true': | |
| 107 self.is_public = True | |
| 108 else: | |
| 109 raise Exception( | |
| 110 'Unexpected value of isPublic %s for image %s' % ( | |
| 111 value, | |
| 112 self.id | |
| 113 ) | |
| 114 ) | |
| 115 elif name == 'architecture': | |
| 116 self.architecture = value | |
| 117 elif name == 'imageType': | |
| 118 self.type = value | |
| 119 elif name == 'kernelId': | |
| 120 self.kernel_id = value | |
| 121 elif name == 'ramdiskId': | |
| 122 self.ramdisk_id = value | |
| 123 elif name == 'imageOwnerAlias': | |
| 124 self.owner_alias = value | |
| 125 elif name == 'platform': | |
| 126 self.platform = value | |
| 127 elif name == 'name': | |
| 128 self.name = value | |
| 129 elif name == 'description': | |
| 130 self.description = value | |
| 131 elif name == 'rootDeviceType': | |
| 132 self.root_device_type = value | |
| 133 elif name == 'rootDeviceName': | |
| 134 self.root_device_name = value | |
| 135 elif name == 'virtualizationType': | |
| 136 self.virtualization_type = value | |
| 137 elif name == 'hypervisor': | |
| 138 self.hypervisor = value | |
| 139 elif name == 'instanceLifecycle': | |
| 140 self.instance_lifecycle = value | |
| 141 elif name == 'sriovNetSupport': | |
| 142 self.sriov_net_support = value | |
| 143 else: | |
| 144 setattr(self, name, value) | |
| 145 | |
| 146 def _update(self, updated): | |
| 147 self.__dict__.update(updated.__dict__) | |
| 148 | |
| 149 def update(self, validate=False, dry_run=False): | |
| 150 """ | |
| 151 Update the image's state information by making a call to fetch | |
| 152 the current image attributes from the service. | |
| 153 | |
| 154 :type validate: bool | |
| 155 :param validate: By default, if EC2 returns no data about the | |
| 156 image the update method returns quietly. If | |
| 157 the validate param is True, however, it will | |
| 158 raise a ValueError exception if no data is | |
| 159 returned from EC2. | |
| 160 """ | |
| 161 rs = self.connection.get_all_images([self.id], dry_run=dry_run) | |
| 162 if len(rs) > 0: | |
| 163 img = rs[0] | |
| 164 if img.id == self.id: | |
| 165 self._update(img) | |
| 166 elif validate: | |
| 167 raise ValueError('%s is not a valid Image ID' % self.id) | |
| 168 return self.state | |
| 169 | |
| 170 def run(self, min_count=1, max_count=1, key_name=None, | |
| 171 security_groups=None, user_data=None, | |
| 172 addressing_type=None, instance_type='m1.small', placement=None, | |
| 173 kernel_id=None, ramdisk_id=None, | |
| 174 monitoring_enabled=False, subnet_id=None, | |
| 175 block_device_map=None, | |
| 176 disable_api_termination=False, | |
| 177 instance_initiated_shutdown_behavior=None, | |
| 178 private_ip_address=None, | |
| 179 placement_group=None, security_group_ids=None, | |
| 180 additional_info=None, instance_profile_name=None, | |
| 181 instance_profile_arn=None, tenancy=None, dry_run=False): | |
| 182 | |
| 183 """ | |
| 184 Runs this instance. | |
| 185 | |
| 186 :type min_count: int | |
| 187 :param min_count: The minimum number of instances to start | |
| 188 | |
| 189 :type max_count: int | |
| 190 :param max_count: The maximum number of instances to start | |
| 191 | |
| 192 :type key_name: string | |
| 193 :param key_name: The name of the key pair with which to | |
| 194 launch instances. | |
| 195 | |
| 196 :type security_groups: list of strings | |
| 197 :param security_groups: The names of the security groups with which to | |
| 198 associate instances. | |
| 199 | |
| 200 :type user_data: string | |
| 201 :param user_data: The Base64-encoded MIME user data to be made | |
| 202 available to the instance(s) in this reservation. | |
| 203 | |
| 204 :type instance_type: string | |
| 205 :param instance_type: The type of instance to run: | |
| 206 | |
| 207 * t1.micro | |
| 208 * m1.small | |
| 209 * m1.medium | |
| 210 * m1.large | |
| 211 * m1.xlarge | |
| 212 * m3.medium | |
| 213 * m3.large | |
| 214 * m3.xlarge | |
| 215 * m3.2xlarge | |
| 216 * c1.medium | |
| 217 * c1.xlarge | |
| 218 * m2.xlarge | |
| 219 * m2.2xlarge | |
| 220 * m2.4xlarge | |
| 221 * cr1.8xlarge | |
| 222 * hi1.4xlarge | |
| 223 * hs1.8xlarge | |
| 224 * cc1.4xlarge | |
| 225 * cg1.4xlarge | |
| 226 * cc2.8xlarge | |
| 227 * g2.2xlarge | |
| 228 * c3.large | |
| 229 * c3.xlarge | |
| 230 * c3.2xlarge | |
| 231 * c3.4xlarge | |
| 232 * c3.8xlarge | |
| 233 * c4.large | |
| 234 * c4.xlarge | |
| 235 * c4.2xlarge | |
| 236 * c4.4xlarge | |
| 237 * c4.8xlarge | |
| 238 * i2.xlarge | |
| 239 * i2.2xlarge | |
| 240 * i2.4xlarge | |
| 241 * i2.8xlarge | |
| 242 * t2.micro | |
| 243 * t2.small | |
| 244 * t2.medium | |
| 245 | |
| 246 :type placement: string | |
| 247 :param placement: The Availability Zone to launch the instance into. | |
| 248 | |
| 249 :type kernel_id: string | |
| 250 :param kernel_id: The ID of the kernel with which to launch the | |
| 251 instances. | |
| 252 | |
| 253 :type ramdisk_id: string | |
| 254 :param ramdisk_id: The ID of the RAM disk with which to launch the | |
| 255 instances. | |
| 256 | |
| 257 :type monitoring_enabled: bool | |
| 258 :param monitoring_enabled: Enable CloudWatch monitoring on | |
| 259 the instance. | |
| 260 | |
| 261 :type subnet_id: string | |
| 262 :param subnet_id: The subnet ID within which to launch the instances | |
| 263 for VPC. | |
| 264 | |
| 265 :type private_ip_address: string | |
| 266 :param private_ip_address: If you're using VPC, you can | |
| 267 optionally use this parameter to assign the instance a | |
| 268 specific available IP address from the subnet (e.g., | |
| 269 10.0.0.25). | |
| 270 | |
| 271 :type block_device_map: :class:`boto.ec2.blockdevicemapping.BlockDeviceMapping` | |
| 272 :param block_device_map: A BlockDeviceMapping data structure | |
| 273 describing the EBS volumes associated with the Image. | |
| 274 | |
| 275 :type disable_api_termination: bool | |
| 276 :param disable_api_termination: If True, the instances will be locked | |
| 277 and will not be able to be terminated via the API. | |
| 278 | |
| 279 :type instance_initiated_shutdown_behavior: string | |
| 280 :param instance_initiated_shutdown_behavior: Specifies whether the | |
| 281 instance stops or terminates on instance-initiated shutdown. | |
| 282 Valid values are: | |
| 283 | |
| 284 * stop | |
| 285 * terminate | |
| 286 | |
| 287 :type placement_group: string | |
| 288 :param placement_group: If specified, this is the name of the placement | |
| 289 group in which the instance(s) will be launched. | |
| 290 | |
| 291 :type additional_info: string | |
| 292 :param additional_info: Specifies additional information to make | |
| 293 available to the instance(s). | |
| 294 | |
| 295 :type security_group_ids: list of strings | |
| 296 :param security_group_ids: The ID of the VPC security groups with | |
| 297 which to associate instances. | |
| 298 | |
| 299 :type instance_profile_name: string | |
| 300 :param instance_profile_name: The name of | |
| 301 the IAM Instance Profile (IIP) to associate with the instances. | |
| 302 | |
| 303 :type instance_profile_arn: string | |
| 304 :param instance_profile_arn: The Amazon resource name (ARN) of | |
| 305 the IAM Instance Profile (IIP) to associate with the instances. | |
| 306 | |
| 307 :type tenancy: string | |
| 308 :param tenancy: The tenancy of the instance you want to | |
| 309 launch. An instance with a tenancy of 'dedicated' runs on | |
| 310 single-tenant hardware and can only be launched into a | |
| 311 VPC. Valid values are:"default" or "dedicated". | |
| 312 NOTE: To use dedicated tenancy you MUST specify a VPC | |
| 313 subnet-ID as well. | |
| 314 | |
| 315 :rtype: Reservation | |
| 316 :return: The :class:`boto.ec2.instance.Reservation` associated with | |
| 317 the request for machines | |
| 318 | |
| 319 """ | |
| 320 | |
| 321 return self.connection.run_instances(self.id, min_count, max_count, | |
| 322 key_name, security_groups, | |
| 323 user_data, addressing_type, | |
| 324 instance_type, placement, | |
| 325 kernel_id, ramdisk_id, | |
| 326 monitoring_enabled, subnet_id, | |
| 327 block_device_map, disable_api_termination, | |
| 328 instance_initiated_shutdown_behavior, | |
| 329 private_ip_address, placement_group, | |
| 330 security_group_ids=security_group_ids, | |
| 331 additional_info=additional_info, | |
| 332 instance_profile_name=instance_profile_name, | |
| 333 instance_profile_arn=instance_profile_arn, | |
| 334 tenancy=tenancy, dry_run=dry_run) | |
| 335 | |
| 336 def deregister(self, delete_snapshot=False, dry_run=False): | |
| 337 return self.connection.deregister_image( | |
| 338 self.id, | |
| 339 delete_snapshot, | |
| 340 dry_run=dry_run | |
| 341 ) | |
| 342 | |
| 343 def get_launch_permissions(self, dry_run=False): | |
| 344 img_attrs = self.connection.get_image_attribute( | |
| 345 self.id, | |
| 346 'launchPermission', | |
| 347 dry_run=dry_run | |
| 348 ) | |
| 349 return img_attrs.attrs | |
| 350 | |
| 351 def set_launch_permissions(self, user_ids=None, group_names=None, | |
| 352 dry_run=False): | |
| 353 return self.connection.modify_image_attribute(self.id, | |
| 354 'launchPermission', | |
| 355 'add', | |
| 356 user_ids, | |
| 357 group_names, | |
| 358 dry_run=dry_run) | |
| 359 | |
| 360 def remove_launch_permissions(self, user_ids=None, group_names=None, | |
| 361 dry_run=False): | |
| 362 return self.connection.modify_image_attribute(self.id, | |
| 363 'launchPermission', | |
| 364 'remove', | |
| 365 user_ids, | |
| 366 group_names, | |
| 367 dry_run=dry_run) | |
| 368 | |
| 369 def reset_launch_attributes(self, dry_run=False): | |
| 370 return self.connection.reset_image_attribute( | |
| 371 self.id, | |
| 372 'launchPermission', | |
| 373 dry_run=dry_run | |
| 374 ) | |
| 375 | |
| 376 def get_kernel(self, dry_run=False): | |
| 377 img_attrs = self.connection.get_image_attribute( | |
| 378 self.id, | |
| 379 'kernel', | |
| 380 dry_run=dry_run | |
| 381 ) | |
| 382 return img_attrs.kernel | |
| 383 | |
| 384 def get_ramdisk(self, dry_run=False): | |
| 385 img_attrs = self.connection.get_image_attribute( | |
| 386 self.id, | |
| 387 'ramdisk', | |
| 388 dry_run=dry_run | |
| 389 ) | |
| 390 return img_attrs.ramdisk | |
| 391 | |
| 392 | |
| 393 class ImageAttribute(object): | |
| 394 def __init__(self, parent=None): | |
| 395 self.name = None | |
| 396 self.kernel = None | |
| 397 self.ramdisk = None | |
| 398 self.attrs = {} | |
| 399 | |
| 400 def startElement(self, name, attrs, connection): | |
| 401 if name == 'blockDeviceMapping': | |
| 402 self.attrs['block_device_mapping'] = BlockDeviceMapping() | |
| 403 return self.attrs['block_device_mapping'] | |
| 404 else: | |
| 405 return None | |
| 406 | |
| 407 def endElement(self, name, value, connection): | |
| 408 if name == 'launchPermission': | |
| 409 self.name = 'launch_permission' | |
| 410 elif name == 'group': | |
| 411 if 'groups' in self.attrs: | |
| 412 self.attrs['groups'].append(value) | |
| 413 else: | |
| 414 self.attrs['groups'] = [value] | |
| 415 elif name == 'userId': | |
| 416 if 'user_ids' in self.attrs: | |
| 417 self.attrs['user_ids'].append(value) | |
| 418 else: | |
| 419 self.attrs['user_ids'] = [value] | |
| 420 elif name == 'productCode': | |
| 421 if 'product_codes' in self.attrs: | |
| 422 self.attrs['product_codes'].append(value) | |
| 423 else: | |
| 424 self.attrs['product_codes'] = [value] | |
| 425 elif name == 'imageId': | |
| 426 self.image_id = value | |
| 427 elif name == 'kernel': | |
| 428 self.kernel = value | |
| 429 elif name == 'ramdisk': | |
| 430 self.ramdisk = value | |
| 431 else: | |
| 432 setattr(self, name, value) | |
| 433 | |
| 434 | |
| 435 class CopyImage(object): | |
| 436 def __init__(self, parent=None): | |
| 437 self._parent = parent | |
| 438 self.image_id = None | |
| 439 | |
| 440 def startElement(self, name, attrs, connection): | |
| 441 pass | |
| 442 | |
| 443 def endElement(self, name, value, connection): | |
| 444 if name == 'imageId': | |
| 445 self.image_id = value |
