~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/ec2/connection.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2013-05-10 23:38:14 UTC
  • mfrom: (1.1.10) (14.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130510233814-701dvlop7xfh88i7
Tags: 2.9.2-1
New upstream release (Closes: #700743).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/
 
1
# Copyright (c) 2006-2012 Mitch Garnaat http://garnaat.org/
2
2
# Copyright (c) 2010, Eucalyptus Systems, Inc.
 
3
# Copyright (c) 2013 Amazon.com, Inc. or its affiliates.  All Rights Reserved
3
4
#
4
5
# Permission is hereby granted, free of charge, to any person obtaining a
5
6
# copy of this software and associated documentation files (the
28
29
import warnings
29
30
from datetime import datetime
30
31
from datetime import timedelta
 
32
 
31
33
import boto
32
34
from boto.connection import AWSQueryConnection
33
35
from boto.resultset import ResultSet
34
 
from boto.ec2.image import Image, ImageAttribute
 
36
from boto.ec2.image import Image, ImageAttribute, CopyImage
35
37
from boto.ec2.instance import Reservation, Instance
36
38
from boto.ec2.instance import ConsoleOutput, InstanceAttribute
37
39
from boto.ec2.keypair import KeyPair
45
47
from boto.ec2.instanceinfo import InstanceInfo
46
48
from boto.ec2.reservedinstance import ReservedInstancesOffering
47
49
from boto.ec2.reservedinstance import ReservedInstance
 
50
from boto.ec2.reservedinstance import ReservedInstanceListing
48
51
from boto.ec2.spotinstancerequest import SpotInstanceRequest
49
52
from boto.ec2.spotpricehistory import SpotPriceHistory
50
53
from boto.ec2.spotdatafeedsubscription import SpotDatafeedSubscription
51
54
from boto.ec2.bundleinstance import BundleInstanceTask
52
55
from boto.ec2.placementgroup import PlacementGroup
53
56
from boto.ec2.tag import Tag
 
57
from boto.ec2.vmtype import VmType
54
58
from boto.ec2.instancestatus import InstanceStatusSet
55
59
from boto.ec2.volumestatus import VolumeStatusSet
56
60
from boto.ec2.networkinterface import NetworkInterface
 
61
from boto.ec2.attributes import AccountAttribute, VPCAttribute
57
62
from boto.exception import EC2ResponseError
58
63
 
59
64
#boto.set_stream_logger('ec2')
60
65
 
 
66
 
61
67
class EC2Connection(AWSQueryConnection):
62
68
 
63
 
    APIVersion = boto.config.get('Boto', 'ec2_version', '2012-03-01')
 
69
    APIVersion = boto.config.get('Boto', 'ec2_version', '2013-02-01')
64
70
    DefaultRegionName = boto.config.get('Boto', 'ec2_region_name', 'us-east-1')
65
71
    DefaultRegionEndpoint = boto.config.get('Boto', 'ec2_region_endpoint',
66
72
                                            'ec2.us-east-1.amazonaws.com')
71
77
                 proxy=None, proxy_port=None,
72
78
                 proxy_user=None, proxy_pass=None, debug=0,
73
79
                 https_connection_factory=None, region=None, path='/',
74
 
                 api_version=None, security_token=None):
 
80
                 api_version=None, security_token=None,
 
81
                 validate_certs=True):
75
82
        """
76
83
        Init method to create a new connection to EC2.
77
84
        """
85
92
                                    proxy_user, proxy_pass,
86
93
                                    self.region.endpoint, debug,
87
94
                                    https_connection_factory, path,
88
 
                                    security_token)
 
95
                                    security_token,
 
96
                                    validate_certs=validate_certs)
89
97
        if api_version:
90
98
            self.APIVersion = api_version
91
99
 
118
126
                value = [value]
119
127
            j = 1
120
128
            for v in value:
121
 
                params['Filter.%d.Value.%d' % (i,j)] = v
 
129
                params['Filter.%d.Value.%d' % (i, j)] = v
122
130
                j += 1
123
131
            i += 1
124
132
 
140
148
                              user ID has explicit launch permissions
141
149
 
142
150
        :type filters: dict
143
 
        :param filters: Optional filters that can be used to limit
144
 
                        the results returned.  Filters are provided
145
 
                        in the form of a dictionary consisting of
146
 
                        filter names as the key and filter values
147
 
                        as the value.  The set of allowable filter
148
 
                        names/values is dependent on the request
149
 
                        being performed.  Check the EC2 API guide
150
 
                        for details.
 
151
        :param filters: Optional filters that can be used to limit the
 
152
            results returned.  Filters are provided in the form of a
 
153
            dictionary consisting of filter names as the key and
 
154
            filter values as the value.  The set of allowable filter
 
155
            names/values is dependent on the request being performed.
 
156
            Check the EC2 API guide for details.
151
157
 
152
158
        :rtype: list
153
159
        :return: A list of :class:`boto.ec2.image.Image`
183
189
            self.build_list_params(params, kernel_ids, 'ImageId')
184
190
        if owners:
185
191
            self.build_list_params(params, owners, 'Owner')
186
 
        filter = {'image-type' : 'kernel'}
 
192
        filter = {'image-type': 'kernel'}
187
193
        self.build_filter_params(params, filter)
188
194
        return self.get_list('DescribeImages', params,
189
195
                             [('item', Image)], verb='POST')
207
213
            self.build_list_params(params, ramdisk_ids, 'ImageId')
208
214
        if owners:
209
215
            self.build_list_params(params, owners, 'Owner')
210
 
        filter = {'image-type' : 'ramdisk'}
 
216
        filter = {'image-type': 'ramdisk'}
211
217
        self.build_filter_params(params, filter)
212
218
        return self.get_list('DescribeImages', params,
213
219
                             [('item', Image)], verb='POST')
224
230
        """
225
231
        try:
226
232
            return self.get_all_images(image_ids=[image_id])[0]
227
 
        except IndexError: # None of those images available
 
233
        except IndexError:  # None of those images available
228
234
            return None
229
235
 
230
236
    def register_image(self, name=None, description=None, image_location=None,
241
247
 
242
248
        :type image_location: string
243
249
        :param image_location: Full path to your AMI manifest in
244
 
                               Amazon S3 storage.
245
 
                               Only used for S3-based AMI's.
 
250
            Amazon S3 storage.  Only used for S3-based AMI's.
246
251
 
247
252
        :type architecture: string
248
253
        :param architecture: The architecture of the AMI.  Valid choices are:
249
 
                             i386 | x86_64
 
254
            * i386
 
255
            * x86_64
250
256
 
251
257
        :type kernel_id: string
252
258
        :param kernel_id: The ID of the kernel with which to launch
253
 
                          the instances
 
259
            the instances
254
260
 
255
261
        :type root_device_name: string
256
262
        :param root_device_name: The root device name (e.g. /dev/sdh)
257
263
 
258
264
        :type block_device_map: :class:`boto.ec2.blockdevicemapping.BlockDeviceMapping`
259
265
        :param block_device_map: A BlockDeviceMapping data structure
260
 
                                 describing the EBS volumes associated
261
 
                                 with the Image.
 
266
            describing the EBS volumes associated with the Image.
262
267
 
263
268
        :rtype: string
264
269
        :return: The new image id
293
298
 
294
299
        :type delete_snapshot: bool
295
300
        :param delete_snapshot: Set to True if we should delete the
296
 
                                snapshot associated with an EBS volume
297
 
                                mounted at /dev/sda1
 
301
            snapshot associated with an EBS volume mounted at /dev/sda1
298
302
 
299
303
        :rtype: bool
300
304
        :return: True if successful
327
331
 
328
332
        :type description: string
329
333
        :param description: An optional human-readable string describing
330
 
                            the contents and purpose of the AMI.
 
334
            the contents and purpose of the AMI.
331
335
 
332
336
        :type no_reboot: bool
333
 
        :param no_reboot: An optional flag indicating that the bundling process
334
 
                          should not attempt to shutdown the instance before
335
 
                          bundling.  If this flag is True, the responsibility
336
 
                          of maintaining file system integrity is left to the
337
 
                          owner of the instance.
 
337
        :param no_reboot: An optional flag indicating that the
 
338
            bundling process should not attempt to shutdown the
 
339
            instance before bundling.  If this flag is True, the
 
340
            responsibility of maintaining file system integrity is
 
341
            left to the owner of the instance.
338
342
 
339
343
        :rtype: string
340
344
        :return: The new image id
341
345
        """
342
 
        params = {'InstanceId' : instance_id,
343
 
                  'Name' : name}
 
346
        params = {'InstanceId': instance_id,
 
347
                  'Name': name}
344
348
        if description:
345
349
            params['Description'] = description
346
350
        if no_reboot:
359
363
 
360
364
        :type attribute: string
361
365
        :param attribute: The attribute you need information about.
362
 
                          Valid choices are:
363
 
                          * launchPermission
364
 
                          * productCodes
365
 
                          * blockDeviceMapping
 
366
            Valid choices are:
 
367
            * launchPermission
 
368
            * productCodes
 
369
            * blockDeviceMapping
366
370
 
367
371
        :rtype: :class:`boto.ec2.image.ImageAttribute`
368
372
        :return: An ImageAttribute object representing the value of the
369
373
                 attribute requested
370
374
        """
371
 
        params = {'ImageId' : image_id,
372
 
                  'Attribute' : attribute}
 
375
        params = {'ImageId': image_id,
 
376
                  'Attribute': attribute}
373
377
        return self.get_object('DescribeImageAttribute', params,
374
378
                               ImageAttribute, verb='POST')
375
379
 
387
391
 
388
392
        :type operation: string
389
393
        :param operation: Either add or remove (this is required for changing
390
 
                          launchPermissions)
 
394
            launchPermissions)
391
395
 
392
396
        :type user_ids: list
393
397
        :param user_ids: The Amazon IDs of users to add/remove attributes
397
401
 
398
402
        :type product_codes: list
399
403
        :param product_codes: Amazon DevPay product code. Currently only one
400
 
                              product code can be associated with an AMI. Once
401
 
                              set, the product code cannot be changed or reset.
 
404
            product code can be associated with an AMI. Once
 
405
            set, the product code cannot be changed or reset.
402
406
        """
403
 
        params = {'ImageId' : image_id,
404
 
                  'Attribute' : attribute,
405
 
                  'OperationType' : operation}
 
407
        params = {'ImageId': image_id,
 
408
                  'Attribute': attribute,
 
409
                  'OperationType': operation}
406
410
        if user_ids:
407
411
            self.build_list_params(params, user_ids, 'UserId')
408
412
        if groups:
424
428
        :rtype: bool
425
429
        :return: Whether the operation succeeded or not
426
430
        """
427
 
        params = {'ImageId' : image_id,
428
 
                  'Attribute' : attribute}
 
431
        params = {'ImageId': image_id,
 
432
                  'Attribute': attribute}
429
433
        return self.get_status('ResetImageAttribute', params, verb='POST')
430
434
 
431
435
    # Instance methods
438
442
        :param instance_ids: A list of strings of instance IDs
439
443
 
440
444
        :type filters: dict
441
 
        :param filters: Optional filters that can be used to limit
442
 
                        the results returned.  Filters are provided
443
 
                        in the form of a dictionary consisting of
444
 
                        filter names as the key and filter values
445
 
                        as the value.  The set of allowable filter
446
 
                        names/values is dependent on the request
447
 
                        being performed.  Check the EC2 API guide
448
 
                        for details.
 
445
        :param filters: Optional filters that can be used to limit the
 
446
            results returned.  Filters are provided in the form of a
 
447
            dictionary consisting of filter names as the key and
 
448
            filter values as the value.  The set of allowable filter
 
449
            names/values is dependent on the request being performed.
 
450
            Check the EC2 API guide for details.
449
451
 
450
452
        :rtype: list
451
453
        :return: A list of  :class:`boto.ec2.instance.Reservation`
519
521
                      instance_initiated_shutdown_behavior=None,
520
522
                      private_ip_address=None,
521
523
                      placement_group=None, client_token=None,
522
 
                      security_group_ids=None):
 
524
                      security_group_ids=None,
 
525
                      additional_info=None, instance_profile_name=None,
 
526
                      instance_profile_arn=None, tenancy=None,
 
527
                      ebs_optimized=False, network_interfaces=None):
523
528
        """
524
529
        Runs an image on EC2.
525
530
 
526
531
        :type image_id: string
527
 
        :param image_id: The ID of the image to run
 
532
        :param image_id: The ID of the image to run.
528
533
 
529
534
        :type min_count: int
530
 
        :param min_count: The minimum number of instances to launch
 
535
        :param min_count: The minimum number of instances to launch.
531
536
 
532
537
        :type max_count: int
533
 
        :param max_count: The maximum number of instances to launch
 
538
        :param max_count: The maximum number of instances to launch.
534
539
 
535
540
        :type key_name: string
536
 
        :param key_name: The name of the key pair with which to launch instances
 
541
        :param key_name: The name of the key pair with which to
 
542
            launch instances.
537
543
 
538
544
        :type security_groups: list of strings
539
545
        :param security_groups: The names of the security groups with which to
540
 
                                associate instances
 
546
            associate instances
541
547
 
542
548
        :type user_data: string
543
549
        :param user_data: The user data passed to the launched instances
545
551
        :type instance_type: string
546
552
        :param instance_type: The type of instance to run:
547
553
 
548
 
                              * m1.small
549
 
                              * m1.large
550
 
                              * m1.xlarge
551
 
                              * c1.medium
552
 
                              * c1.xlarge
553
 
                              * m2.xlarge
554
 
                              * m2.2xlarge
555
 
                              * m2.4xlarge
556
 
                              * cc1.4xlarge
557
 
                              * t1.micro
 
554
            * t1.micro
 
555
            * m1.small
 
556
            * m1.medium
 
557
            * m1.large
 
558
            * m1.xlarge
 
559
            * c1.medium
 
560
            * c1.xlarge
 
561
            * m2.xlarge
 
562
            * m2.2xlarge
 
563
            * m2.4xlarge
 
564
            * cc1.4xlarge
 
565
            * cg1.4xlarge
 
566
            * cc2.8xlarge
558
567
 
559
568
        :type placement: string
560
 
        :param placement: The availability zone in which to launch the instances
 
569
        :param placement: The availability zone in which to launch
 
570
            the instances.
561
571
 
562
572
        :type kernel_id: string
563
573
        :param kernel_id: The ID of the kernel with which to launch the
564
 
                          instances
 
574
            instances.
565
575
 
566
576
        :type ramdisk_id: string
567
577
        :param ramdisk_id: The ID of the RAM disk with which to launch the
568
 
                           instances
 
578
            instances.
569
579
 
570
580
        :type monitoring_enabled: bool
571
 
        :param monitoring_enabled: Enable CloudWatch monitoring on the instance.
 
581
        :param monitoring_enabled: Enable CloudWatch monitoring on
 
582
            the instance.
572
583
 
573
584
        :type subnet_id: string
574
585
        :param subnet_id: The subnet ID within which to launch the instances
575
 
                          for VPC.
 
586
            for VPC.
576
587
 
577
588
        :type private_ip_address: string
578
 
        :param private_ip_address: If you're using VPC, you can optionally use
579
 
                                   this parameter to assign the instance a
580
 
                                   specific available IP address from the
581
 
                                   subnet (e.g., 10.0.0.25).
 
589
        :param private_ip_address: If you're using VPC, you can
 
590
            optionally use this parameter to assign the instance a
 
591
            specific available IP address from the subnet (e.g.,
 
592
            10.0.0.25).
582
593
 
583
594
        :type block_device_map: :class:`boto.ec2.blockdevicemapping.BlockDeviceMapping`
584
595
        :param block_device_map: A BlockDeviceMapping data structure
585
 
                                 describing the EBS volumes associated
586
 
                                 with the Image.
 
596
            describing the EBS volumes associated  with the Image.
587
597
 
588
598
        :type disable_api_termination: bool
589
599
        :param disable_api_termination: If True, the instances will be locked
590
 
                                        and will not be able to be terminated
591
 
                                        via the API.
 
600
            and will not be able to be terminated via the API.
592
601
 
593
602
        :type instance_initiated_shutdown_behavior: string
594
603
        :param instance_initiated_shutdown_behavior: Specifies whether the
595
 
                                                     instance stops or
596
 
                                                     terminates on
597
 
                                                     instance-initiated
598
 
                                                     shutdown.
599
 
                                                     Valid values are:
 
604
            instance stops or terminates on instance-initiated shutdown.
 
605
            Valid values are:
600
606
 
601
 
                                                     * stop
602
 
                                                     * terminate
 
607
            * stop
 
608
            * terminate
603
609
 
604
610
        :type placement_group: string
605
611
        :param placement_group: If specified, this is the name of the placement
606
 
                                group in which the instance(s) will be launched.
 
612
            group in which the instance(s) will be launched.
607
613
 
608
614
        :type client_token: string
609
615
        :param client_token: Unique, case-sensitive identifier you provide
610
 
                             to ensure idempotency of the request.
611
 
                             Maximum 64 ASCII characters
 
616
            to ensure idempotency of the request.  Maximum 64 ASCII characters.
 
617
 
 
618
        :type security_group_ids: list of strings
 
619
        :param security_group_ids: The ID of the VPC security groups with
 
620
            which to associate instances.
 
621
 
 
622
        :type additional_info: string
 
623
        :param additional_info: Specifies additional information to make
 
624
            available to the instance(s).
 
625
 
 
626
        :type tenancy: string
 
627
        :param tenancy: The tenancy of the instance you want to
 
628
            launch. An instance with a tenancy of 'dedicated' runs on
 
629
            single-tenant hardware and can only be launched into a
 
630
            VPC. Valid values are:"default" or "dedicated".
 
631
            NOTE: To use dedicated tenancy you MUST specify a VPC
 
632
            subnet-ID as well.
 
633
 
 
634
        :type instance_profile_arn: string
 
635
        :param instance_profile_arn: The Amazon resource name (ARN) of
 
636
            the IAM Instance Profile (IIP) to associate with the instances.
 
637
 
 
638
        :type instance_profile_name: string
 
639
        :param instance_profile_name: The name of
 
640
            the IAM Instance Profile (IIP) to associate with the instances.
 
641
 
 
642
        :type ebs_optimized: bool
 
643
        :param ebs_optimized: Whether the instance is optimized for
 
644
            EBS I/O.  This optimization provides dedicated throughput
 
645
            to Amazon EBS and an optimized configuration stack to
 
646
            provide optimal EBS I/O performance.  This optimization
 
647
            isn't available with all instance types.
 
648
 
 
649
        :type network_interfaces: list
 
650
        :param network_interfaces: A list of
 
651
            :class:`boto.ec2.networkinterface.NetworkInterfaceSpecification`
612
652
 
613
653
        :rtype: Reservation
614
654
        :return: The :class:`boto.ec2.instance.Reservation` associated with
615
655
                 the request for machines
616
 
 
617
 
        :type security_group_ids: list of strings
618
 
        :param security_group_ids: The ID of the VPC security groups with
619
 
                                   which to associate instances
620
656
        """
621
 
        params = {'ImageId':image_id,
622
 
                  'MinCount':min_count,
 
657
        params = {'ImageId': image_id,
 
658
                  'MinCount': min_count,
623
659
                  'MaxCount': max_count}
624
660
        if key_name:
625
661
            params['KeyName'] = key_name
649
685
            params['Placement.AvailabilityZone'] = placement
650
686
        if placement_group:
651
687
            params['Placement.GroupName'] = placement_group
 
688
        if tenancy:
 
689
            params['Placement.Tenancy'] = tenancy
652
690
        if kernel_id:
653
691
            params['KernelId'] = kernel_id
654
692
        if ramdisk_id:
668
706
            params['InstanceInitiatedShutdownBehavior'] = val
669
707
        if client_token:
670
708
            params['ClientToken'] = client_token
671
 
        return self.get_object('RunInstances', params, Reservation, verb='POST')
 
709
        if additional_info:
 
710
            params['AdditionalInfo'] = additional_info
 
711
        if instance_profile_name:
 
712
            params['IamInstanceProfile.Name'] = instance_profile_name
 
713
        if instance_profile_arn:
 
714
            params['IamInstanceProfile.Arn'] = instance_profile_arn
 
715
        if ebs_optimized:
 
716
            params['EbsOptimized'] = 'true'
 
717
        if network_interfaces:
 
718
            network_interfaces.build_list_params(params)
 
719
        return self.get_object('RunInstances', params, Reservation,
 
720
                               verb='POST')
672
721
 
673
722
    def terminate_instances(self, instance_ids=None):
674
723
        """
751
800
        return self.get_status('RebootInstances', params)
752
801
 
753
802
    def confirm_product_instance(self, product_code, instance_id):
754
 
        params = {'ProductCode' : product_code,
755
 
                  'InstanceId' : instance_id}
 
803
        params = {'ProductCode': product_code,
 
804
                  'InstanceId': instance_id}
756
805
        rs = self.get_object('ConfirmProductInstance', params,
757
806
                             ResultSet, verb='POST')
758
807
        return (rs.status, rs.ownerId)
768
817
 
769
818
        :type attribute: string
770
819
        :param attribute: The attribute you need information about
771
 
                          Valid choices are:
 
820
            Valid choices are:
772
821
 
773
 
                          * instanceType|kernel|ramdisk|userData|
774
 
                          * disableApiTermination|
775
 
                          * instanceInitiatedShutdownBehavior|
776
 
                          * rootDeviceName|blockDeviceMapping
 
822
            * instanceType
 
823
            * kernel
 
824
            * ramdisk
 
825
            * userData
 
826
            * disableApiTermination
 
827
            * instanceInitiatedShutdownBehavior
 
828
            * rootDeviceName
 
829
            * blockDeviceMapping
 
830
            * productCodes
 
831
            * sourceDestCheck
 
832
            * groupSet
 
833
            * ebsOptimized
777
834
 
778
835
        :rtype: :class:`boto.ec2.image.InstanceAttribute`
779
836
        :return: An InstanceAttribute object representing the value of the
780
837
                 attribute requested
781
838
        """
782
 
        params = {'InstanceId' : instance_id}
 
839
        params = {'InstanceId': instance_id}
783
840
        if attribute:
784
841
            params['Attribute'] = attribute
785
842
        return self.get_object('DescribeInstanceAttribute', params,
795
852
        :type attribute: string
796
853
        :param attribute: The attribute you wish to change.
797
854
 
798
 
                          * AttributeName - Expected value (default)
799
 
                          * instanceType - A valid instance type (m1.small)
800
 
                          * kernel - Kernel ID (None)
801
 
                          * ramdisk - Ramdisk ID (None)
802
 
                          * userData - Base64 encoded String (None)
803
 
                          * disableApiTermination - Boolean (true)
804
 
                          * instanceInitiatedShutdownBehavior - stop|terminate
805
 
                          * rootDeviceName - device name (None)
 
855
            * instanceType - A valid instance type (m1.small)
 
856
            * kernel - Kernel ID (None)
 
857
            * ramdisk - Ramdisk ID (None)
 
858
            * userData - Base64 encoded String (None)
 
859
            * disableApiTermination - Boolean (true)
 
860
            * instanceInitiatedShutdownBehavior - stop|terminate
 
861
            * blockDeviceMapping - List of strings - ie: ['/dev/sda=false']
 
862
            * sourceDestCheck - Boolean (true)
 
863
            * groupSet - Set of Security Groups or IDs
 
864
            * ebsOptimized - Boolean (false)
806
865
 
807
866
        :type value: string
808
867
        :param value: The new value for the attribute
811
870
        :return: Whether the operation succeeded or not
812
871
        """
813
872
        # Allow a bool to be passed in for value of disableApiTermination
814
 
        if attribute == 'disableApiTermination':
 
873
        bool_reqs = ('disableapitermination',
 
874
                     'sourcedestcheck',
 
875
                     'ebsoptimized')
 
876
        if attribute.lower() in bool_reqs:
815
877
            if isinstance(value, bool):
816
878
                if value:
817
879
                    value = 'true'
818
880
                else:
819
881
                    value = 'false'
820
 
        params = {'InstanceId' : instance_id,
821
 
                  'Attribute' : attribute,
822
 
                  'Value' : value}
 
882
 
 
883
        params = {'InstanceId': instance_id}
 
884
 
 
885
        # groupSet is handled differently from other arguments
 
886
        if attribute.lower() == 'groupset':
 
887
            for idx, sg in enumerate(value):
 
888
                if isinstance(sg, SecurityGroup):
 
889
                    sg = sg.id
 
890
                params['GroupId.%s' % (idx + 1)] = sg
 
891
        elif attribute.lower() == 'blockdevicemapping':
 
892
            for idx, kv in enumerate(value):
 
893
                dev_name, _, flag = kv.partition('=')
 
894
                pre = 'BlockDeviceMapping.%d' % (idx + 1)
 
895
                params['%s.DeviceName' % pre] = dev_name
 
896
                params['%s.Ebs.DeleteOnTermination' % pre] = flag or 'true'
 
897
        else:
 
898
            # for backwards compatibility handle lowercase first letter
 
899
            attribute = attribute[0].upper() + attribute[1:]
 
900
            params['%s.Value' % attribute] = value
 
901
 
823
902
        return self.get_status('ModifyInstanceAttribute', params, verb='POST')
824
903
 
825
904
    def reset_instance_attribute(self, instance_id, attribute):
836
915
        :rtype: bool
837
916
        :return: Whether the operation succeeded or not
838
917
        """
839
 
        params = {'InstanceId' : instance_id,
840
 
                  'Attribute' : attribute}
 
918
        params = {'InstanceId': instance_id,
 
919
                  'Attribute': attribute}
841
920
        return self.get_status('ResetInstanceAttribute', params, verb='POST')
842
921
 
843
922
    # Spot Instances
851
930
        :param request_ids: A list of strings of spot instance request IDs
852
931
 
853
932
        :type filters: dict
854
 
        :param filters: Optional filters that can be used to limit
855
 
                        the results returned.  Filters are provided
856
 
                        in the form of a dictionary consisting of
857
 
                        filter names as the key and filter values
858
 
                        as the value.  The set of allowable filter
859
 
                        names/values is dependent on the request
860
 
                        being performed.  Check the EC2 API guide
861
 
                        for details.
 
933
        :param filters: Optional filters that can be used to limit the
 
934
            results returned.  Filters are provided in the form of a
 
935
            dictionary consisting of filter names as the key and
 
936
            filter values as the value.  The set of allowable filter
 
937
            names/values is dependent on the request being performed.
 
938
            Check the EC2 API guide for details.
862
939
 
863
940
        :rtype: list
864
941
        :return: A list of
888
965
 
889
966
        :type start_time: str
890
967
        :param start_time: An indication of how far back to provide price
891
 
                           changes for. An ISO8601 DateTime string.
 
968
            changes for. An ISO8601 DateTime string.
892
969
 
893
970
        :type end_time: str
894
971
        :param end_time: An indication of how far forward to provide price
895
 
                         changes for.  An ISO8601 DateTime string.
 
972
            changes for.  An ISO8601 DateTime string.
896
973
 
897
974
        :type instance_type: str
898
975
        :param instance_type: Filter responses to a particular instance type.
899
976
 
900
977
        :type product_description: str
901
978
        :param product_description: Filter responses to a particular platform.
902
 
                                    Valid values are currently: "Linux/UNIX",
903
 
                                    "SUSE Linux", and "Windows"
 
979
            Valid values are currently:
 
980
 
 
981
            * Linux/UNIX
 
982
            * SUSE Linux
 
983
            * Windows
 
984
            * Linux/UNIX (Amazon VPC)
 
985
            * SUSE Linux (Amazon VPC)
 
986
            * Windows (Amazon VPC)
904
987
 
905
988
        :type availability_zone: str
906
989
        :param availability_zone: The availability zone for which prices
907
 
                                  should be returned
 
990
            should be returned.  If not specified, data for all
 
991
            availability zones will be returned.
908
992
 
909
993
        :rtype: list
910
994
        :return: A list tuples containing price and timestamp.
932
1016
                               kernel_id=None, ramdisk_id=None,
933
1017
                               monitoring_enabled=False, subnet_id=None,
934
1018
                               placement_group=None,
935
 
                               block_device_map=None):
 
1019
                               block_device_map=None,
 
1020
                               instance_profile_arn=None,
 
1021
                               instance_profile_name=None,
 
1022
                               security_group_ids=None,
 
1023
                               ebs_optimized=False,
 
1024
                               network_interfaces=None):
936
1025
        """
937
1026
        Request instances on the spot market at a particular price.
938
1027
 
957
1046
 
958
1047
        :type launch_group: str
959
1048
        :param launch_group: If supplied, all requests will be fulfilled
960
 
                             as a group.
 
1049
            as a group.
961
1050
 
962
1051
        :type availability_zone_group: str
963
1052
        :param availability_zone_group: If supplied, all requests will be
964
 
                                        fulfilled within a single
965
 
                                        availability zone.
 
1053
            fulfilled within a single availability zone.
966
1054
 
967
1055
        :type key_name: string
968
 
        :param key_name: The name of the key pair with which to launch instances
 
1056
        :param key_name: The name of the key pair with which to
 
1057
            launch instances
969
1058
 
970
1059
        :type security_groups: list of strings
971
1060
        :param security_groups: The names of the security groups with which to
972
 
                                associate instances
 
1061
            associate instances
973
1062
 
974
1063
        :type user_data: string
975
1064
        :param user_data: The user data passed to the launched instances
977
1066
        :type instance_type: string
978
1067
        :param instance_type: The type of instance to run:
979
1068
 
980
 
                              * m1.small
981
 
                              * m1.large
982
 
                              * m1.xlarge
983
 
                              * c1.medium
984
 
                              * c1.xlarge
985
 
                              * m2.xlarge
986
 
                              * m2.2xlarge
987
 
                              * m2.4xlarge
988
 
                              * cc1.4xlarge
989
 
                              * t1.micro
 
1069
            * m1.small
 
1070
            * m1.large
 
1071
            * m1.xlarge
 
1072
            * c1.medium
 
1073
            * c1.xlarge
 
1074
            * m2.xlarge
 
1075
            * m2.2xlarge
 
1076
            * m2.4xlarge
 
1077
            * cc1.4xlarge
 
1078
            * t1.micro
990
1079
 
991
1080
        :type placement: string
992
 
        :param placement: The availability zone in which to launch the instances
 
1081
        :param placement: The availability zone in which to launch
 
1082
            the instances
993
1083
 
994
1084
        :type kernel_id: string
995
1085
        :param kernel_id: The ID of the kernel with which to launch the
996
 
                          instances
 
1086
            instances
997
1087
 
998
1088
        :type ramdisk_id: string
999
1089
        :param ramdisk_id: The ID of the RAM disk with which to launch the
1000
 
                           instances
 
1090
            instances
1001
1091
 
1002
1092
        :type monitoring_enabled: bool
1003
 
        :param monitoring_enabled: Enable CloudWatch monitoring on the instance.
 
1093
        :param monitoring_enabled: Enable CloudWatch monitoring on
 
1094
            the instance.
1004
1095
 
1005
1096
        :type subnet_id: string
1006
1097
        :param subnet_id: The subnet ID within which to launch the instances
1007
 
                          for VPC.
 
1098
            for VPC.
1008
1099
 
1009
1100
        :type placement_group: string
1010
1101
        :param placement_group: If specified, this is the name of the placement
1011
 
                                group in which the instance(s) will be launched.
 
1102
            group in which the instance(s) will be launched.
1012
1103
 
1013
1104
        :type block_device_map: :class:`boto.ec2.blockdevicemapping.BlockDeviceMapping`
1014
1105
        :param block_device_map: A BlockDeviceMapping data structure
1015
 
                                 describing the EBS volumes associated
1016
 
                                 with the Image.
 
1106
            describing the EBS volumes associated with the Image.
 
1107
 
 
1108
        :type security_group_ids: list of strings
 
1109
        :param security_group_ids: The ID of the VPC security groups with
 
1110
            which to associate instances.
 
1111
 
 
1112
        :type instance_profile_arn: string
 
1113
        :param instance_profile_arn: The Amazon resource name (ARN) of
 
1114
            the IAM Instance Profile (IIP) to associate with the instances.
 
1115
 
 
1116
        :type instance_profile_name: string
 
1117
        :param instance_profile_name: The name of
 
1118
            the IAM Instance Profile (IIP) to associate with the instances.
 
1119
 
 
1120
        :type ebs_optimized: bool
 
1121
        :param ebs_optimized: Whether the instance is optimized for
 
1122
            EBS I/O.  This optimization provides dedicated throughput
 
1123
            to Amazon EBS and an optimized configuration stack to
 
1124
            provide optimal EBS I/O performance.  This optimization
 
1125
            isn't available with all instance types.
 
1126
 
 
1127
        :type network_interfaces: list
 
1128
        :param network_interfaces: A list of
 
1129
            :class:`boto.ec2.networkinterface.NetworkInterfaceSpecification`
1017
1130
 
1018
1131
        :rtype: Reservation
1019
1132
        :return: The :class:`boto.ec2.spotinstancerequest.SpotInstanceRequest`
1020
1133
                 associated with the request for machines
1021
1134
        """
1022
 
        params = {'LaunchSpecification.ImageId':image_id,
1023
 
                  'Type' : type,
1024
 
                  'SpotPrice' : price}
 
1135
        ls = 'LaunchSpecification'
 
1136
        params = {'%s.ImageId' % ls: image_id,
 
1137
                  'Type': type,
 
1138
                  'SpotPrice': price}
1025
1139
        if count:
1026
1140
            params['InstanceCount'] = count
1027
1141
        if valid_from:
1033
1147
        if availability_zone_group:
1034
1148
            params['AvailabilityZoneGroup'] = availability_zone_group
1035
1149
        if key_name:
1036
 
            params['LaunchSpecification.KeyName'] = key_name
1037
 
        if security_groups:
 
1150
            params['%s.KeyName' % ls] = key_name
 
1151
        if security_group_ids:
1038
1152
            l = []
1039
 
            for group in security_groups:
 
1153
            for group in security_group_ids:
1040
1154
                if isinstance(group, SecurityGroup):
1041
 
                    l.append(group.name)
 
1155
                    l.append(group.id)
1042
1156
                else:
1043
1157
                    l.append(group)
1044
1158
            self.build_list_params(params, l,
1045
 
                                   'LaunchSpecification.SecurityGroup')
 
1159
                                   '%s.SecurityGroupId' % ls)
 
1160
        if security_groups:
 
1161
            l = []
 
1162
            for group in security_groups:
 
1163
                if isinstance(group, SecurityGroup):
 
1164
                    l.append(group.name)
 
1165
                else:
 
1166
                    l.append(group)
 
1167
            self.build_list_params(params, l, '%s.SecurityGroup' % ls)
1046
1168
        if user_data:
1047
 
            params['LaunchSpecification.UserData'] = base64.b64encode(user_data)
 
1169
            params['%s.UserData' % ls] = base64.b64encode(user_data)
1048
1170
        if addressing_type:
1049
 
            params['LaunchSpecification.AddressingType'] = addressing_type
 
1171
            params['%s.AddressingType' % ls] = addressing_type
1050
1172
        if instance_type:
1051
 
            params['LaunchSpecification.InstanceType'] = instance_type
 
1173
            params['%s.InstanceType' % ls] = instance_type
1052
1174
        if placement:
1053
 
            params['LaunchSpecification.Placement.AvailabilityZone'] = placement
 
1175
            params['%s.Placement.AvailabilityZone' % ls] = placement
1054
1176
        if kernel_id:
1055
 
            params['LaunchSpecification.KernelId'] = kernel_id
 
1177
            params['%s.KernelId' % ls] = kernel_id
1056
1178
        if ramdisk_id:
1057
 
            params['LaunchSpecification.RamdiskId'] = ramdisk_id
 
1179
            params['%s.RamdiskId' % ls] = ramdisk_id
1058
1180
        if monitoring_enabled:
1059
 
            params['LaunchSpecification.Monitoring.Enabled'] = 'true'
 
1181
            params['%s.Monitoring.Enabled' % ls] = 'true'
1060
1182
        if subnet_id:
1061
 
            params['LaunchSpecification.SubnetId'] = subnet_id
 
1183
            params['%s.SubnetId' % ls] = subnet_id
1062
1184
        if placement_group:
1063
 
            params['LaunchSpecification.Placement.GroupName'] = placement_group
 
1185
            params['%s.Placement.GroupName' % ls] = placement_group
1064
1186
        if block_device_map:
1065
 
            block_device_map.build_list_params(params, 'LaunchSpecification.')
 
1187
            block_device_map.build_list_params(params, '%s.' % ls)
 
1188
        if instance_profile_name:
 
1189
            params['%s.IamInstanceProfile.Name' % ls] = instance_profile_name
 
1190
        if instance_profile_arn:
 
1191
            params['%s.IamInstanceProfile.Arn' % ls] = instance_profile_arn
 
1192
        if ebs_optimized:
 
1193
            params['%s.EbsOptimized' % ls] = 'true'
 
1194
        if network_interfaces:
 
1195
            network_interfaces.build_list_params(params, prefix=ls + '.')
1066
1196
        return self.get_list('RequestSpotInstances', params,
1067
1197
                             [('item', SpotInstanceRequest)],
1068
1198
                             verb='POST')
1111
1241
        :rtype: :class:`boto.ec2.spotdatafeedsubscription.SpotDatafeedSubscription`
1112
1242
        :return: The datafeed subscription object or None
1113
1243
        """
1114
 
        params = {'Bucket' : bucket}
 
1244
        params = {'Bucket': bucket}
1115
1245
        if prefix:
1116
1246
            params['Prefix'] = prefix
1117
1247
        return self.get_object('CreateSpotDatafeedSubscription',
1202
1332
        """
1203
1333
        Allocate a new Elastic IP address and associate it with your account.
1204
1334
 
 
1335
        :type domain: string
 
1336
        :param domain: Optional string. If domain is set to "vpc" the address
 
1337
            will be allocated to VPC . Will return address object with
 
1338
            allocation_id.
 
1339
 
1205
1340
        :rtype: :class:`boto.ec2.address.Address`
1206
1341
        :return: The newly allocated Address
1207
1342
        """
1212
1347
 
1213
1348
        return self.get_object('AllocateAddress', params, Address, verb='POST')
1214
1349
 
1215
 
    def associate_address(self, instance_id, public_ip=None, allocation_id=None):
 
1350
    def assign_private_ip_addresses(self, network_interface_id=None,
 
1351
                                    private_ip_addresses=None,
 
1352
                                    secondary_private_ip_address_count=None,
 
1353
                                    allow_reassignment=False):
 
1354
        """
 
1355
        Assigns one or more secondary private IP addresses to a network
 
1356
        interface in Amazon VPC.
 
1357
 
 
1358
        :type network_interface_id: string
 
1359
        :param network_interface_id: The network interface to which the IP
 
1360
            address will be assigned.
 
1361
 
 
1362
        :type private_ip_addresses: list
 
1363
        :param private_ip_addresses: Assigns the specified IP addresses as
 
1364
            secondary IP addresses to the network interface.
 
1365
 
 
1366
        :type secondary_private_ip_address_count: int
 
1367
        :param secondary_private_ip_address_count: The number of secondary IP
 
1368
            addresses to assign to the network interface. You cannot specify
 
1369
            this parameter when also specifying private_ip_addresses.
 
1370
 
 
1371
        :type allow_reassignment: bool
 
1372
        :param allow_reassignment: Specifies whether to allow an IP address
 
1373
            that is already assigned to another network interface or instance
 
1374
            to be reassigned to the specified network interface.
 
1375
 
 
1376
        :rtype: bool
 
1377
        :return: True if successful
 
1378
        """
 
1379
        params = {}
 
1380
 
 
1381
        if network_interface_id is not None:
 
1382
            params['NetworkInterfaceId'] = network_interface_id
 
1383
 
 
1384
        if private_ip_addresses is not None:
 
1385
            self.build_list_params(params, private_ip_addresses,
 
1386
                                   'PrivateIpAddress')
 
1387
        elif secondary_private_ip_address_count is not None:
 
1388
            params['SecondaryPrivateIpAddressCount'] = \
 
1389
                secondary_private_ip_address_count
 
1390
 
 
1391
        if allow_reassignment:
 
1392
            params['AllowReassignment'] = 'true'
 
1393
 
 
1394
        return self.get_status('AssignPrivateIpAddresses', params, verb='POST')
 
1395
 
 
1396
    def associate_address(self, instance_id=None, public_ip=None,
 
1397
                          allocation_id=None, network_interface_id=None,
 
1398
                          private_ip_address=None, allow_reassociation=False):
1216
1399
        """
1217
1400
        Associate an Elastic IP address with a currently running instance.
1218
1401
        This requires one of ``public_ip`` or ``allocation_id`` depending
1219
1402
        on if you're associating a VPC address or a plain EC2 address.
1220
1403
 
 
1404
        When using an Allocation ID, make sure to pass ``None`` for ``public_ip``
 
1405
        as EC2 expects a single parameter and if ``public_ip`` is passed boto
 
1406
        will preference that instead of ``allocation_id``.
 
1407
 
1221
1408
        :type instance_id: string
1222
1409
        :param instance_id: The ID of the instance
1223
1410
 
1227
1414
        :type allocation_id: string
1228
1415
        :param allocation_id: The allocation ID for a VPC-based elastic IP.
1229
1416
 
 
1417
        :type network_interface_id: string
 
1418
        :param network_interface_id: The network interface ID to which
 
1419
            elastic IP is to be assigned to
 
1420
 
 
1421
        :type private_ip_address: string
 
1422
        :param private_ip_address: The primary or secondary private IP address
 
1423
            to associate with the Elastic IP address.
 
1424
 
 
1425
        :type allow_reassociation: bool
 
1426
        :param allow_reassociation: Specify this option to allow an Elastic IP
 
1427
            address that is already associated with another network interface
 
1428
            or instance to be re-associated with the specified instance or
 
1429
            interface.
 
1430
 
1230
1431
        :rtype: bool
1231
1432
        :return: True if successful
1232
1433
        """
1233
 
        params = { 'InstanceId' : instance_id }
 
1434
        params = {}
 
1435
        if instance_id is not None:
 
1436
                params['InstanceId'] = instance_id
 
1437
        elif network_interface_id is not None:
 
1438
                params['NetworkInterfaceId'] = network_interface_id
1234
1439
 
1235
1440
        if public_ip is not None:
1236
1441
            params['PublicIp'] = public_ip
1237
1442
        elif allocation_id is not None:
1238
1443
            params['AllocationId'] = allocation_id
1239
1444
 
 
1445
        if private_ip_address is not None:
 
1446
            params['PrivateIpAddress'] = private_ip_address
 
1447
 
 
1448
        if allow_reassociation:
 
1449
            params['AllowReassociation'] = 'true'
 
1450
 
1240
1451
        return self.get_status('AssociateAddress', params, verb='POST')
1241
1452
 
1242
1453
    def disassociate_address(self, public_ip=None, association_id=None):
1263
1474
 
1264
1475
    def release_address(self, public_ip=None, allocation_id=None):
1265
1476
        """
1266
 
        Free up an Elastic IP address.
 
1477
        Free up an Elastic IP address.  Pass a public IP address to
 
1478
        release an EC2 Elastic IP address and an AllocationId to
 
1479
        release a VPC Elastic IP address.  You should only pass
 
1480
        one value.
 
1481
 
 
1482
        This requires one of ``public_ip`` or ``allocation_id`` depending
 
1483
        on if you're associating a VPC address or a plain EC2 address.
 
1484
 
 
1485
        When using an Allocation ID, make sure to pass ``None`` for ``public_ip``
 
1486
        as EC2 expects a single parameter and if ``public_ip`` is passed boto
 
1487
        will preference that instead of ``allocation_id``.
1267
1488
 
1268
1489
        :type public_ip: string
1269
1490
        :param public_ip: The public IP address for EC2 elastic IPs.
1270
1491
 
1271
1492
        :type allocation_id: string
1272
 
        :param allocation_id: The ID for VPC elastic IPs.
 
1493
        :param allocation_id: The Allocation ID for VPC elastic IPs.
1273
1494
 
1274
1495
        :rtype: bool
1275
1496
        :return: True if successful
1283
1504
 
1284
1505
        return self.get_status('ReleaseAddress', params, verb='POST')
1285
1506
 
 
1507
    def unassign_private_ip_addresses(self, network_interface_id=None,
 
1508
                                      private_ip_addresses=None):
 
1509
        """
 
1510
        Unassigns one or more secondary private IP addresses from a network
 
1511
        interface in Amazon VPC.
 
1512
 
 
1513
        :type network_interface_id: string
 
1514
        :param network_interface_id: The network interface from which the
 
1515
            secondary private IP address will be unassigned.
 
1516
 
 
1517
        :type private_ip_addresses: list
 
1518
        :param private_ip_addresses: Specifies the secondary private IP
 
1519
            addresses that you want to unassign from the network interface.
 
1520
 
 
1521
        :rtype: bool
 
1522
        :return: True if successful
 
1523
        """
 
1524
        params = {}
 
1525
 
 
1526
        if network_interface_id is not None:
 
1527
            params['NetworkInterfaceId'] = network_interface_id
 
1528
 
 
1529
        if private_ip_addresses is not None:
 
1530
            self.build_list_params(params, private_ip_addresses,
 
1531
                                   'PrivateIpAddress')
 
1532
 
 
1533
        return self.get_status('UnassignPrivateIpAddresses', params,
 
1534
                               verb='POST')
 
1535
 
1286
1536
    # Volume methods
1287
1537
 
1288
1538
    def get_all_volumes(self, volume_ids=None, filters=None):
1387
1637
        :rtype: list of :class:`boto.ec2.volume.VolumeAttribute`
1388
1638
        :return: The requested Volume attribute
1389
1639
        """
1390
 
        params = {'VolumeId': volume_id, 'Attribute' : attribute}
 
1640
        params = {'VolumeId': volume_id, 'Attribute': attribute}
1391
1641
        return self.get_object('DescribeVolumeAttribute', params,
1392
1642
                               VolumeAttribute, verb='POST')
1393
1643
 
1410
1660
            params['AutoEnableIO.Value'] = new_value
1411
1661
        return self.get_status('ModifyVolumeAttribute', params, verb='POST')
1412
1662
 
1413
 
    def create_volume(self, size, zone, snapshot=None):
 
1663
    def create_volume(self, size, zone, snapshot=None,
 
1664
                      volume_type=None, iops=None):
1414
1665
        """
1415
1666
        Create a new EBS Volume.
1416
1667
 
1421
1672
        :param zone: The availability zone in which the Volume will be created.
1422
1673
 
1423
1674
        :type snapshot: string or :class:`boto.ec2.snapshot.Snapshot`
1424
 
        :param snapshot: The snapshot from which the new Volume will be created.
 
1675
        :param snapshot: The snapshot from which the new Volume will be
 
1676
            created.
 
1677
 
 
1678
        :type volume_type: string
 
1679
        :param volume_type: The type of the volume. (optional).  Valid
 
1680
            values are: standard | io1.
 
1681
 
 
1682
        :type iops: int
 
1683
        :param iops: The provisioned IOPs you want to associate with
 
1684
            this volume. (optional)
1425
1685
        """
1426
1686
        if isinstance(zone, Zone):
1427
1687
            zone = zone.name
1428
 
        params = {'AvailabilityZone' : zone}
 
1688
        params = {'AvailabilityZone': zone}
1429
1689
        if size:
1430
1690
            params['Size'] = size
1431
1691
        if snapshot:
1432
1692
            if isinstance(snapshot, Snapshot):
1433
1693
                snapshot = snapshot.id
1434
1694
            params['SnapshotId'] = snapshot
 
1695
        if volume_type:
 
1696
            params['VolumeType'] = volume_type
 
1697
        if iops:
 
1698
            params['Iops'] = str(iops)
1435
1699
        return self.get_object('CreateVolume', params, Volume, verb='POST')
1436
1700
 
1437
1701
    def delete_volume(self, volume_id):
1465
1729
        :rtype: bool
1466
1730
        :return: True if successful
1467
1731
        """
1468
 
        params = {'InstanceId' : instance_id,
1469
 
                  'VolumeId' : volume_id,
1470
 
                  'Device' : device}
 
1732
        params = {'InstanceId': instance_id,
 
1733
                  'VolumeId': volume_id,
 
1734
                  'Device': device}
1471
1735
        return self.get_status('AttachVolume', params, verb='POST')
1472
1736
 
1473
1737
    def detach_volume(self, volume_id, instance_id=None,
1480
1744
 
1481
1745
        :type instance_id: str
1482
1746
        :param instance_id: The ID of the EC2 instance from which it will
1483
 
                            be detached.
 
1747
            be detached.
1484
1748
 
1485
1749
        :type device: str
1486
1750
        :param device: The device on the instance through which the
1487
 
                       volume is exposted (e.g. /dev/sdh)
 
1751
            volume is exposted (e.g. /dev/sdh)
1488
1752
 
1489
1753
        :type force: bool
1490
 
        :param force: Forces detachment if the previous detachment attempt did
1491
 
                      not occur cleanly.  This option can lead to data loss or
1492
 
                      a corrupted file system. Use this option only as a last
1493
 
                      resort to detach a volume from a failed instance. The
1494
 
                      instance will not have an opportunity to flush file system
1495
 
                      caches nor file system meta data. If you use this option,
1496
 
                      you must perform file system check and repair procedures.
 
1754
        :param force: Forces detachment if the previous detachment
 
1755
            attempt did not occur cleanly.  This option can lead to
 
1756
            data loss or a corrupted file system. Use this option only
 
1757
            as a last resort to detach a volume from a failed
 
1758
            instance. The instance will not have an opportunity to
 
1759
            flush file system caches nor file system meta data. If you
 
1760
            use this option, you must perform file system check and
 
1761
            repair procedures.
1497
1762
 
1498
1763
        :rtype: bool
1499
1764
        :return: True if successful
1500
1765
        """
1501
 
        params = {'VolumeId' : volume_id}
 
1766
        params = {'VolumeId': volume_id}
1502
1767
        if instance_id:
1503
1768
            params['InstanceId'] = instance_id
1504
1769
        if device:
1568
1833
        :param description: A description of the snapshot.
1569
1834
                            Limited to 255 characters.
1570
1835
 
1571
 
        :rtype: bool
1572
 
        :return: True if successful
 
1836
        :rtype: :class:`boto.ec2.snapshot.Snapshot`
 
1837
        :return: The created Snapshot object
1573
1838
        """
1574
 
        params = {'VolumeId' : volume_id}
 
1839
        params = {'VolumeId': volume_id}
1575
1840
        if description:
1576
1841
            params['Description'] = description[0:255]
1577
1842
        snapshot = self.get_object('CreateSnapshot', params,
1586
1851
        params = {'SnapshotId': snapshot_id}
1587
1852
        return self.get_status('DeleteSnapshot', params, verb='POST')
1588
1853
 
1589
 
    def trim_snapshots(self, hourly_backups = 8, daily_backups = 7,
1590
 
                       weekly_backups = 4):
 
1854
    def copy_snapshot(self, source_region, source_snapshot_id,
 
1855
                      description=None):
 
1856
        """
 
1857
        Copies a point-in-time snapshot of an Amazon Elastic Block Store
 
1858
        (Amazon EBS) volume and stores it in Amazon Simple Storage Service
 
1859
        (Amazon S3). You can copy the snapshot within the same region or from
 
1860
        one region to another. You can use the snapshot to create new Amazon
 
1861
        EBS volumes or Amazon Machine Images (AMIs).
 
1862
 
 
1863
 
 
1864
        :type source_region: str
 
1865
        :param source_region: The ID of the AWS region that contains the
 
1866
            snapshot to be copied (e.g 'us-east-1', 'us-west-2', etc.).
 
1867
 
 
1868
        :type source_snapshot_id: str
 
1869
        :param source_snapshot_id: The ID of the Amazon EBS snapshot to copy
 
1870
 
 
1871
        :type description: str
 
1872
        :param description: A description of the new Amazon EBS snapshot.
 
1873
 
 
1874
        :rtype: str
 
1875
        :return: The snapshot ID
 
1876
 
 
1877
        """
 
1878
        params = {
 
1879
            'SourceRegion': source_region,
 
1880
            'SourceSnapshotId': source_snapshot_id,
 
1881
        }
 
1882
        if description is not None:
 
1883
            params['Description'] = description
 
1884
        snapshot = self.get_object('CopySnapshot', params, Snapshot,
 
1885
                                   verb='POST')
 
1886
        return snapshot.id
 
1887
 
 
1888
    def trim_snapshots(self, hourly_backups=8, daily_backups=7,
 
1889
                       weekly_backups=4):
1591
1890
        """
1592
1891
        Trim excess snapshots, based on when they were taken. More current
1593
1892
        snapshots are retained, with the number retained decreasing as you
1667
1966
            if temp.__contains__(t) == False:
1668
1967
                temp.append(t)
1669
1968
 
1670
 
        target_backup_times = temp
1671
 
        # make the oldeest dates first, and make sure the month start
 
1969
        # sort to make the oldest dates first, and make sure the month start
1672
1970
        # and last four week's start are in the proper order
1673
 
        target_backup_times.sort()
 
1971
        target_backup_times = sorted(temp)
1674
1972
 
1675
1973
        # get all the snapshots, sort them by date and time, and
1676
1974
        # organize them into one array for each volume:
1733
2031
                        time_period_number += 1
1734
2032
                        snap_found_for_this_time_period = False
1735
2033
 
1736
 
 
1737
2034
    def get_snapshot_attribute(self, snapshot_id,
1738
2035
                               attribute='createVolumePermission'):
1739
2036
        """
1751
2048
        :rtype: list of :class:`boto.ec2.snapshotattribute.SnapshotAttribute`
1752
2049
        :return: The requested Snapshot attribute
1753
2050
        """
1754
 
        params = {'Attribute' : attribute}
 
2051
        params = {'Attribute': attribute}
1755
2052
        if snapshot_id:
1756
2053
            params['SnapshotId'] = snapshot_id
1757
2054
        return self.get_object('DescribeSnapshotAttribute', params,
1768
2065
 
1769
2066
        :type attribute: string
1770
2067
        :param attribute: The attribute you wish to change.  Valid values are:
1771
 
                          createVolumePermission
 
2068
            createVolumePermission
1772
2069
 
1773
2070
        :type operation: string
1774
2071
        :param operation: Either add or remove (this is required for changing
1775
 
                          snapshot ermissions)
 
2072
            snapshot ermissions)
1776
2073
 
1777
2074
        :type user_ids: list
1778
2075
        :param user_ids: The Amazon IDs of users to add/remove attributes
1779
2076
 
1780
2077
        :type groups: list
1781
2078
        :param groups: The groups to add/remove attributes.  The only valid
1782
 
                       value at this time is 'all'.
 
2079
            value at this time is 'all'.
1783
2080
 
1784
2081
        """
1785
 
        params = {'SnapshotId' : snapshot_id,
1786
 
                  'Attribute' : attribute,
1787
 
                  'OperationType' : operation}
 
2082
        params = {'SnapshotId': snapshot_id,
 
2083
                  'Attribute': attribute,
 
2084
                  'OperationType': operation}
1788
2085
        if user_ids:
1789
2086
            self.build_list_params(params, user_ids, 'UserId')
1790
2087
        if groups:
1805
2102
        :rtype: bool
1806
2103
        :return: Whether the operation succeeded or not
1807
2104
        """
1808
 
        params = {'SnapshotId' : snapshot_id,
1809
 
                  'Attribute' : attribute}
 
2105
        params = {'SnapshotId': snapshot_id,
 
2106
                  'Attribute': attribute}
1810
2107
        return self.get_status('ResetSnapshotAttribute', params, verb='POST')
1811
2108
 
1812
2109
    # Keypair methods
1817
2114
 
1818
2115
        :type keynames: list
1819
2116
        :param keynames: A list of the names of keypairs to retrieve.
1820
 
                         If not provided, all key pairs will be returned.
 
2117
            If not provided, all key pairs will be returned.
1821
2118
 
1822
2119
        :type filters: dict
1823
 
        :param filters: Optional filters that can be used to limit
1824
 
                        the results returned.  Filters are provided
1825
 
                        in the form of a dictionary consisting of
1826
 
                        filter names as the key and filter values
1827
 
                        as the value.  The set of allowable filter
1828
 
                        names/values is dependent on the request
1829
 
                        being performed.  Check the EC2 API guide
1830
 
                        for details.
 
2120
        :param filters: Optional filters that can be used to limit the
 
2121
            results returned.  Filters are provided in the form of a
 
2122
            dictionary consisting of filter names as the key and
 
2123
            filter values as the value.  The set of allowable filter
 
2124
            names/values is dependent on the request being performed.
 
2125
            Check the EC2 API guide for details.
1831
2126
 
1832
2127
        :rtype: list
1833
2128
        :return: A list of :class:`boto.ec2.keypair.KeyPair`
1872
2167
                 The material attribute of the new KeyPair object
1873
2168
                 will contain the the unencrypted PEM encoded RSA private key.
1874
2169
        """
1875
 
        params = {'KeyName':key_name}
 
2170
        params = {'KeyName': key_name}
1876
2171
        return self.get_object('CreateKeyPair', params, KeyPair, verb='POST')
1877
2172
 
1878
2173
    def delete_key_pair(self, key_name):
1882
2177
        :type key_name: string
1883
2178
        :param key_name: The name of the keypair to delete
1884
2179
        """
1885
 
        params = {'KeyName':key_name}
 
2180
        params = {'KeyName': key_name}
1886
2181
        return self.get_status('DeleteKeyPair', params, verb='POST')
1887
2182
 
1888
2183
    def import_key_pair(self, key_name, public_key_material):
1913
2208
                                    it to AWS.
1914
2209
 
1915
2210
        :rtype: :class:`boto.ec2.keypair.KeyPair`
1916
 
        :return: The newly created :class:`boto.ec2.keypair.KeyPair`.
1917
 
                 The material attribute of the new KeyPair object
1918
 
                 will contain the the unencrypted PEM encoded RSA private key.
 
2211
        :return: A :class:`boto.ec2.keypair.KeyPair` object representing
 
2212
            the newly imported key pair.  This object will contain only
 
2213
            the key name and the fingerprint.
1919
2214
        """
1920
2215
        public_key_material = base64.b64encode(public_key_material)
1921
 
        params = {'KeyName' : key_name,
1922
 
                  'PublicKeyMaterial' : public_key_material}
 
2216
        params = {'KeyName': key_name,
 
2217
                  'PublicKeyMaterial': public_key_material}
1923
2218
        return self.get_object('ImportKeyPair', params, KeyPair, verb='POST')
1924
2219
 
1925
2220
    # SecurityGroup methods
1979
2274
                       if any.
1980
2275
 
1981
2276
        :rtype: :class:`boto.ec2.securitygroup.SecurityGroup`
1982
 
        :return: The newly created :class:`boto.ec2.keypair.KeyPair`.
 
2277
        :return: The newly created :class:`boto.ec2.securitygroup.SecurityGroup`.
1983
2278
        """
1984
 
        params = {
1985
 
            'GroupName': name,
1986
 
            'GroupDescription': description
1987
 
        }
 
2279
        params = {'GroupName': name,
 
2280
                  'GroupDescription': description}
1988
2281
 
1989
2282
        if vpc_id is not None:
1990
2283
            params['VpcId'] = vpc_id
1993
2286
                                SecurityGroup, verb='POST')
1994
2287
        group.name = name
1995
2288
        group.description = description
 
2289
        if vpc_id is not None:
 
2290
            group.vpc_id = vpc_id
1996
2291
        return group
1997
2292
 
1998
2293
    def delete_security_group(self, name=None, group_id=None):
2031
2326
 
2032
2327
        :type group_name: string
2033
2328
        :param group_name: The name of the security group you are adding
2034
 
                           the rule to.
 
2329
            the rule to.
2035
2330
 
2036
2331
        :type src_security_group_name: string
2037
2332
        :param src_security_group_name: The name of the security group you are
2038
 
                                        granting access to.
 
2333
            granting access to.
2039
2334
 
2040
2335
        :type src_security_group_owner_id: string
2041
2336
        :param src_security_group_owner_id: The ID of the owner of the security
2042
 
                                            group you are granting access to.
 
2337
            group you are granting access to.
2043
2338
 
2044
2339
        :type ip_protocol: string
2045
2340
        :param ip_protocol: Either tcp | udp | icmp
2052
2347
 
2053
2348
        :type to_port: string
2054
2349
        :param to_port: The CIDR block you are providing access to.
2055
 
                        See http://goo.gl/Yj5QC
 
2350
            See http://goo.gl/Yj5QC
2056
2351
 
2057
2352
        :rtype: bool
2058
2353
        :return: True if successful.
2075
2370
    def authorize_security_group(self, group_name=None,
2076
2371
                                 src_security_group_name=None,
2077
2372
                                 src_security_group_owner_id=None,
2078
 
                                 ip_protocol=None, from_port=None, to_port=None,
 
2373
                                 ip_protocol=None,
 
2374
                                 from_port=None, to_port=None,
2079
2375
                                 cidr_ip=None, group_id=None,
2080
2376
                                 src_security_group_group_id=None):
2081
2377
        """
2087
2383
 
2088
2384
        :type group_name: string
2089
2385
        :param group_name: The name of the security group you are adding
2090
 
                           the rule to.
 
2386
            the rule to.
2091
2387
 
2092
2388
        :type src_security_group_name: string
2093
2389
        :param src_security_group_name: The name of the security group you are
2094
 
                                        granting access to.
 
2390
            granting access to.
2095
2391
 
2096
2392
        :type src_security_group_owner_id: string
2097
2393
        :param src_security_group_owner_id: The ID of the owner of the security
2098
 
                                            group you are granting access to.
 
2394
            group you are granting access to.
2099
2395
 
2100
2396
        :type ip_protocol: string
2101
2397
        :param ip_protocol: Either tcp | udp | icmp
2108
2404
 
2109
2405
        :type cidr_ip: string or list of strings
2110
2406
        :param cidr_ip: The CIDR block you are providing access to.
2111
 
                        See http://goo.gl/Yj5QC
2112
 
 
2113
 
        :type group_id: string
2114
 
        :param group_id: ID of the EC2 or VPC security group to modify.
2115
 
                         This is required for VPC security groups and
2116
 
                         can be used instead of group_name for EC2
2117
 
                         security groups.
2118
 
 
2119
 
        :type group_id: string
2120
 
        :param group_id: ID of the EC2 or VPC source security group.
2121
 
                         This is required for VPC security groups and
2122
 
                         can be used instead of group_name for EC2
2123
 
                         security groups.
 
2407
            See http://goo.gl/Yj5QC
 
2408
 
 
2409
        :type group_id: string
 
2410
        :param group_id: ID of the EC2 or VPC security group to
 
2411
            modify.  This is required for VPC security groups and can
 
2412
            be used instead of group_name for EC2 security groups.
 
2413
 
 
2414
        :type src_security_group_group_id: string
 
2415
        :param src_security_group_group_id: The ID of the security
 
2416
            group you are granting access to.  Can be used instead of
 
2417
            src_security_group_name
2124
2418
 
2125
2419
        :rtype: bool
2126
2420
        :return: True if successful.
2153
2447
        if to_port is not None:
2154
2448
            params['IpPermissions.1.ToPort'] = to_port
2155
2449
        if cidr_ip:
2156
 
            if type(cidr_ip) != list:
 
2450
            if not isinstance(cidr_ip, list):
2157
2451
                cidr_ip = [cidr_ip]
2158
2452
            for i, single_cidr_ip in enumerate(cidr_ip):
2159
2453
                params['IpPermissions.1.IpRanges.%d.CidrIp' % (i+1)] = \
2235
2529
        :param to_port: The CIDR block you are revoking access to.
2236
2530
                        http://goo.gl/Yj5QC
2237
2531
 
2238
 
        :type group_id: string
2239
 
        :param group_id: ID of the EC2 or VPC security group to modify.
2240
 
                         This is required for VPC security groups and
2241
 
                         can be used instead of group_name for EC2
2242
 
                         security groups.
2243
 
 
2244
 
        :type group_id: string
2245
 
        :param group_id: ID of the EC2 or VPC source security group.
2246
 
                         This is required for VPC security groups and
2247
 
                         can be used instead of group_name for EC2
2248
 
                         security groups.
2249
 
 
2250
2532
        :rtype: bool
2251
2533
        :return: True if successful.
2252
2534
        """
2265
2547
            params['CidrIp'] = cidr_ip
2266
2548
        return self.get_status('RevokeSecurityGroupIngress', params)
2267
2549
 
2268
 
    def revoke_security_group(self, group_name=None, src_security_group_name=None,
 
2550
    def revoke_security_group(self, group_name=None,
 
2551
                              src_security_group_name=None,
2269
2552
                              src_security_group_owner_id=None,
2270
2553
                              ip_protocol=None, from_port=None, to_port=None,
2271
2554
                              cidr_ip=None, group_id=None,
2279
2562
 
2280
2563
        :type group_name: string
2281
2564
        :param group_name: The name of the security group you are removing
2282
 
                           the rule from.
 
2565
            the rule from.
2283
2566
 
2284
2567
        :type src_security_group_name: string
2285
2568
        :param src_security_group_name: The name of the security group you are
2286
 
                                        revoking access to.
 
2569
            revoking access to.
2287
2570
 
2288
2571
        :type src_security_group_owner_id: string
2289
2572
        :param src_security_group_owner_id: The ID of the owner of the security
2290
 
                                            group you are revoking access to.
 
2573
            group you are revoking access to.
2291
2574
 
2292
2575
        :type ip_protocol: string
2293
2576
        :param ip_protocol: Either tcp | udp | icmp
2300
2583
 
2301
2584
        :type cidr_ip: string
2302
2585
        :param cidr_ip: The CIDR block you are revoking access to.
2303
 
                        See http://goo.gl/Yj5QC
 
2586
            See http://goo.gl/Yj5QC
 
2587
 
 
2588
        :type group_id: string
 
2589
        :param group_id: ID of the EC2 or VPC security group to
 
2590
            modify.  This is required for VPC security groups and can
 
2591
            be used instead of group_name for EC2 security groups.
 
2592
 
 
2593
        :type src_security_group_group_id: string
 
2594
        :param src_security_group_group_id: The ID of the security group
 
2595
            for which you are revoking access.  Can be used instead
 
2596
            of src_security_group_name
2304
2597
 
2305
2598
        :rtype: bool
2306
2599
        :return: True if successful.
2343
2636
                                     src_group_id=None,
2344
2637
                                     cidr_ip=None):
2345
2638
        """
2346
 
        Remove an existing egress rule from an existing VPC security group.
2347
 
        You need to pass in an ip_protocol, from_port and to_port range only
2348
 
        if the protocol you are using is port-based. You also need to pass in either
2349
 
        a src_group_id or cidr_ip.
 
2639
        Remove an existing egress rule from an existing VPC security
 
2640
        group.  You need to pass in an ip_protocol, from_port and
 
2641
        to_port range only if the protocol you are using is
 
2642
        port-based. You also need to pass in either a src_group_id or
 
2643
        cidr_ip.
2350
2644
 
2351
2645
        :type group_name: string
2352
2646
        :param group_id:  The name of the security group you are removing
2353
 
                           the rule from.
 
2647
            the rule from.
2354
2648
 
2355
2649
        :type ip_protocol: string
2356
2650
        :param ip_protocol: Either tcp | udp | icmp | -1
2362
2656
        :param to_port: The ending port number you are disabling
2363
2657
 
2364
2658
        :type src_group_id: src_group_id
2365
 
        :param src_group_id: The source security group you are revoking access to.
 
2659
        :param src_group_id: The source security group you are
 
2660
            revoking access to.
2366
2661
 
2367
2662
        :type cidr_ip: string
2368
2663
        :param cidr_ip: The CIDR block you are revoking access to.
2369
 
                        See http://goo.gl/Yj5QC
 
2664
            See http://goo.gl/Yj5QC
2370
2665
 
2371
2666
        :rtype: bool
2372
2667
        :return: True if successful.
2417
2712
            self.build_list_params(params, region_names, 'RegionName')
2418
2713
        if filters:
2419
2714
            self.build_filter_params(params, filters)
2420
 
        regions =  self.get_list('DescribeRegions', params,
 
2715
        regions = self.get_list('DescribeRegions', params,
2421
2716
                                 [('item', RegionInfo)], verb='POST')
2422
2717
        for region in regions:
2423
2718
            region.connection_cls = EC2Connection
2427
2722
    # Reservation methods
2428
2723
    #
2429
2724
 
2430
 
    def get_all_reserved_instances_offerings(self, reserved_instances_id=None,
 
2725
    def get_all_reserved_instances_offerings(self,
 
2726
                                             reserved_instances_offering_ids=None,
2431
2727
                                             instance_type=None,
2432
2728
                                             availability_zone=None,
2433
2729
                                             product_description=None,
2434
 
                                             filters=None):
 
2730
                                             filters=None,
 
2731
                                             instance_tenancy=None,
 
2732
                                             offering_type=None,
 
2733
                                             include_marketplace=None,
 
2734
                                             min_duration=None,
 
2735
                                             max_duration=None,
 
2736
                                             max_instance_count=None,
 
2737
                                             next_token=None,
 
2738
                                             max_results=None):
2435
2739
        """
2436
2740
        Describes Reserved Instance offerings that are available for purchase.
2437
2741
 
2438
 
        :type reserved_instances_id: str
2439
 
        :param reserved_instances_id: Displays Reserved Instances with the
2440
 
                                      specified offering IDs.
 
2742
        :type reserved_instances_offering_ids: list
 
2743
        :param reserved_instances_id: One or more Reserved Instances
 
2744
            offering IDs.
2441
2745
 
2442
2746
        :type instance_type: str
2443
2747
        :param instance_type: Displays Reserved Instances of the specified
2461
2765
                        being performed.  Check the EC2 API guide
2462
2766
                        for details.
2463
2767
 
 
2768
        :type instance_tenancy: string
 
2769
        :param instance_tenancy: The tenancy of the Reserved Instance offering.
 
2770
            A Reserved Instance with tenancy of dedicated will run on
 
2771
            single-tenant hardware and can only be launched within a VPC.
 
2772
 
 
2773
        :type offering_type: string
 
2774
        :param offering_type: The Reserved Instance offering type.  Valid
 
2775
            Values: `"Heavy Utilization" | "Medium Utilization" | "Light
 
2776
            Utilization"`
 
2777
 
 
2778
        :type include_marketplace: bool
 
2779
        :param include_marketplace: Include Marketplace offerings in the
 
2780
            response.
 
2781
 
 
2782
        :type min_duration: int :param min_duration: Minimum duration (in
 
2783
            seconds) to filter when searching for offerings.
 
2784
 
 
2785
        :type max_duration: int
 
2786
        :param max_duration: Maximum duration (in seconds) to filter when
 
2787
            searching for offerings.
 
2788
 
 
2789
        :type max_instance_count: int
 
2790
        :param max_instance_count: Maximum number of instances to filter when
 
2791
            searching for offerings.
 
2792
 
 
2793
        :type next_token: string
 
2794
        :param next_token: Token to use when requesting the next paginated set
 
2795
            of offerings.
 
2796
 
 
2797
        :type max_results: int
 
2798
        :param max_results: Maximum number of offerings to return per call.
 
2799
 
2464
2800
        :rtype: list
2465
 
        :return: A list of :class:`boto.ec2.reservedinstance.ReservedInstancesOffering`
 
2801
        :return: A list of
 
2802
            :class:`boto.ec2.reservedinstance.ReservedInstancesOffering`.
 
2803
 
2466
2804
        """
2467
2805
        params = {}
2468
 
        if reserved_instances_id:
2469
 
            params['ReservedInstancesId'] = reserved_instances_id
 
2806
        if reserved_instances_offering_ids is not None:
 
2807
            self.build_list_params(params, reserved_instances_offering_ids,
 
2808
                                   'ReservedInstancesOfferingId')
2470
2809
        if instance_type:
2471
2810
            params['InstanceType'] = instance_type
2472
2811
        if availability_zone:
2475
2814
            params['ProductDescription'] = product_description
2476
2815
        if filters:
2477
2816
            self.build_filter_params(params, filters)
 
2817
        if instance_tenancy is not None:
 
2818
            params['InstanceTenancy'] = instance_tenancy
 
2819
        if offering_type is not None:
 
2820
            params['OfferingType'] = offering_type
 
2821
        if include_marketplace is not None:
 
2822
            if include_marketplace:
 
2823
                params['IncludeMarketplace'] = 'true'
 
2824
            else:
 
2825
                params['IncludeMarketplace'] = 'false'
 
2826
        if min_duration is not None:
 
2827
            params['MinDuration'] = str(min_duration)
 
2828
        if max_duration is not None:
 
2829
            params['MaxDuration'] = str(max_duration)
 
2830
        if max_instance_count is not None:
 
2831
            params['MaxInstanceCount'] = str(max_instance_count)
 
2832
        if next_token is not None:
 
2833
            params['NextToken'] = next_token
 
2834
        if max_results is not None:
 
2835
            params['MaxResults'] = str(max_results)
2478
2836
 
2479
2837
        return self.get_list('DescribeReservedInstancesOfferings',
2480
2838
                             params, [('item', ReservedInstancesOffering)],
2483
2841
    def get_all_reserved_instances(self, reserved_instances_id=None,
2484
2842
                                   filters=None):
2485
2843
        """
2486
 
        Describes Reserved Instance offerings that are available for purchase.
 
2844
        Describes one or more of the Reserved Instances that you purchased.
2487
2845
 
2488
2846
        :type reserved_instance_ids: list
2489
2847
        :param reserved_instance_ids: A list of the reserved instance ids that
2490
 
                                      will be returned. If not provided, all
2491
 
                                      reserved instances will be returned.
 
2848
            will be returned. If not provided, all reserved instances
 
2849
            will be returned.
2492
2850
 
2493
2851
        :type filters: dict
2494
 
        :param filters: Optional filters that can be used to limit
2495
 
                        the results returned.  Filters are provided
2496
 
                        in the form of a dictionary consisting of
2497
 
                        filter names as the key and filter values
2498
 
                        as the value.  The set of allowable filter
2499
 
                        names/values is dependent on the request
2500
 
                        being performed.  Check the EC2 API guide
2501
 
                        for details.
 
2852
        :param filters: Optional filters that can be used to limit the
 
2853
            results returned.  Filters are provided in the form of a
 
2854
            dictionary consisting of filter names as the key and
 
2855
            filter values as the value.  The set of allowable filter
 
2856
            names/values is dependent on the request being performed.
 
2857
            Check the EC2 API guide for details.
2502
2858
 
2503
2859
        :rtype: list
2504
2860
        :return: A list of :class:`boto.ec2.reservedinstance.ReservedInstance`
2514
2870
 
2515
2871
    def purchase_reserved_instance_offering(self,
2516
2872
                                            reserved_instances_offering_id,
2517
 
                                            instance_count=1):
 
2873
                                            instance_count=1, limit_price=None):
2518
2874
        """
2519
2875
        Purchase a Reserved Instance for use with your account.
2520
2876
        ** CAUTION **
2523
2879
 
2524
2880
        :type reserved_instances_offering_id: string
2525
2881
        :param reserved_instances_offering_id: The offering ID of the Reserved
2526
 
                                               Instance to purchase
 
2882
            Instance to purchase
2527
2883
 
2528
2884
        :type instance_count: int
2529
2885
        :param instance_count: The number of Reserved Instances to purchase.
2530
 
                               Default value is 1.
 
2886
            Default value is 1.
 
2887
 
 
2888
        :type limit_price: tuple
 
2889
        :param instance_count: Limit the price on the total order.
 
2890
            Must be a tuple of (amount, currency_code), for example:
 
2891
            (100.0, 'USD').
2531
2892
 
2532
2893
        :rtype: :class:`boto.ec2.reservedinstance.ReservedInstance`
2533
2894
        :return: The newly created Reserved Instance
2534
2895
        """
2535
2896
        params = {
2536
 
            'ReservedInstancesOfferingId' : reserved_instances_offering_id,
2537
 
            'InstanceCount' : instance_count}
 
2897
            'ReservedInstancesOfferingId': reserved_instances_offering_id,
 
2898
            'InstanceCount': instance_count}
 
2899
        if limit_price is not None:
 
2900
            params['LimitPrice.Amount'] = str(limit_price[0])
 
2901
            params['LimitPrice.CurrencyCode'] = str(limit_price[1])
2538
2902
        return self.get_object('PurchaseReservedInstancesOffering', params,
2539
2903
                               ReservedInstance, verb='POST')
2540
2904
 
 
2905
    def create_reserved_instances_listing(self, reserved_instances_id, instance_count,
 
2906
                                          price_schedules, client_token):
 
2907
        """Creates a new listing for Reserved Instances.
 
2908
 
 
2909
        Creates a new listing for Amazon EC2 Reserved Instances that will be
 
2910
        sold in the Reserved Instance Marketplace. You can submit one Reserved
 
2911
        Instance listing at a time.
 
2912
 
 
2913
        The Reserved Instance Marketplace matches sellers who want to resell
 
2914
        Reserved Instance capacity that they no longer need with buyers who
 
2915
        want to purchase additional capacity. Reserved Instances bought and
 
2916
        sold through the Reserved Instance Marketplace work like any other
 
2917
        Reserved Instances.
 
2918
 
 
2919
        If you want to sell your Reserved Instances, you must first register as
 
2920
        a Seller in the Reserved Instance Marketplace. After completing the
 
2921
        registration process, you can create a Reserved Instance Marketplace
 
2922
        listing of some or all of your Reserved Instances, and specify the
 
2923
        upfront price you want to receive for them. Your Reserved Instance
 
2924
        listings then become available for purchase.
 
2925
 
 
2926
        :type reserved_instances_id: string
 
2927
        :param reserved_instances_id: The ID of the Reserved Instance that
 
2928
            will be listed.
 
2929
 
 
2930
        :type instance_count: int
 
2931
        :param instance_count: The number of instances that are a part of a
 
2932
            Reserved Instance account that will be listed in the Reserved
 
2933
            Instance Marketplace. This number should be less than or equal to
 
2934
            the instance count associated with the Reserved Instance ID
 
2935
            specified in this call.
 
2936
 
 
2937
        :type price_schedules: List of tuples
 
2938
        :param price_schedules: A list specifying the price of the Reserved
 
2939
            Instance for each month remaining in the Reserved Instance term.
 
2940
            Each tuple contains two elements, the price and the term.  For
 
2941
            example, for an instance that 11 months remaining in its term,
 
2942
            we can have a price schedule with an upfront price of $2.50.
 
2943
            At 8 months remaining we can drop the price down to $2.00.
 
2944
            This would be expressed as::
 
2945
 
 
2946
                price_schedules=[('2.50', 11), ('2.00', 8)]
 
2947
 
 
2948
        :type client_token: string
 
2949
        :param client_token: Unique, case-sensitive identifier you provide
 
2950
            to ensure idempotency of the request.  Maximum 64 ASCII characters.
 
2951
 
 
2952
        :rtype: list
 
2953
        :return: A list of
 
2954
            :class:`boto.ec2.reservedinstance.ReservedInstanceListing`
 
2955
 
 
2956
        """
 
2957
        params = {
 
2958
            'ReservedInstancesId': reserved_instances_id,
 
2959
            'InstanceCount': str(instance_count),
 
2960
            'ClientToken': client_token,
 
2961
        }
 
2962
        for i, schedule in enumerate(price_schedules):
 
2963
            price, term = schedule
 
2964
            params['PriceSchedules.%s.Price' % i] = str(price)
 
2965
            params['PriceSchedules.%s.Term' % i] = str(term)
 
2966
        return self.get_list('CreateReservedInstancesListing',
 
2967
                             params, [('item', ReservedInstanceListing)], verb='POST')
 
2968
 
 
2969
    def cancel_reserved_instances_listing(
 
2970
            self, reserved_instances_listing_ids=None):
 
2971
        """Cancels the specified Reserved Instance listing.
 
2972
 
 
2973
        :type reserved_instances_listing_ids: List of strings
 
2974
        :param reserved_instances_listing_ids: The ID of the
 
2975
            Reserved Instance listing to be cancelled.
 
2976
 
 
2977
        :rtype: list
 
2978
        :return: A list of
 
2979
            :class:`boto.ec2.reservedinstance.ReservedInstanceListing`
 
2980
 
 
2981
        """
 
2982
        params = {}
 
2983
        if reserved_instances_listing_ids is not None:
 
2984
            self.build_list_params(params, reserved_instances_listing_ids,
 
2985
                                   'ReservedInstancesListingId')
 
2986
        return self.get_list('CancelReservedInstancesListing',
 
2987
                             params, [('item', ReservedInstanceListing)], verb='POST')
 
2988
 
2541
2989
    #
2542
2990
    # Monitoring
2543
2991
    #
2624
3072
                                 user's image into Amazon S3.
2625
3073
        """
2626
3074
 
2627
 
        params = {'InstanceId' : instance_id,
2628
 
                  'Storage.S3.Bucket' : s3_bucket,
2629
 
                  'Storage.S3.Prefix' : s3_prefix,
2630
 
                  'Storage.S3.UploadPolicy' : s3_upload_policy}
 
3075
        params = {'InstanceId': instance_id,
 
3076
                  'Storage.S3.Bucket': s3_bucket,
 
3077
                  'Storage.S3.Prefix': s3_prefix,
 
3078
                  'Storage.S3.UploadPolicy': s3_upload_policy}
2631
3079
        s3auth = boto.auth.get_auth_handler(None, boto.config,
2632
3080
                                            self.provider, ['s3'])
2633
3081
        params['Storage.S3.AWSAccessKeyId'] = self.aws_access_key_id
2673
3121
        :param bundle_id: The identifier of the bundle task to cancel.
2674
3122
        """
2675
3123
 
2676
 
        params = {'BundleId' : bundle_id}
 
3124
        params = {'BundleId': bundle_id}
2677
3125
        return self.get_object('CancelBundleTask', params,
2678
3126
                               BundleInstanceTask, verb='POST')
2679
3127
 
2686
3134
                            password for.
2687
3135
        """
2688
3136
 
2689
 
        params = {'InstanceId' : instance_id}
 
3137
        params = {'InstanceId': instance_id}
2690
3138
        rs = self.get_object('GetPasswordData', params, ResultSet, verb='POST')
2691
3139
        return rs.passwordData
2692
3140
 
2757
3205
    # Tag methods
2758
3206
 
2759
3207
    def build_tag_param_list(self, params, tags):
2760
 
        keys = tags.keys()
2761
 
        keys.sort()
 
3208
        keys = sorted(tags.keys())
2762
3209
        i = 1
2763
3210
        for key in keys:
2764
3211
            value = tags[key]
2884
3331
        :rtype: :class:`boto.ec2.networkinterface.NetworkInterface`
2885
3332
        :return: The newly created network interface.
2886
3333
        """
2887
 
        params = {'SubnetId' : subnet_id}
 
3334
        params = {'SubnetId': subnet_id}
2888
3335
        if private_ip_address:
2889
3336
            params['PrivateIpAddress'] = private_ip_address
2890
3337
        if description:
2916
3363
        :param device_index: The index of the device for the network
2917
3364
            interface attachment on the instance.
2918
3365
        """
2919
 
        params = {'NetworkInterfaceId' : network_interface_id,
2920
 
                  'InstanceId' : instance_id,
2921
 
                  'Deviceindex' : device_index}
 
3366
        params = {'NetworkInterfaceId': network_interface_id,
 
3367
                  'InstanceId': instance_id,
 
3368
                  'DeviceIndex': device_index}
2922
3369
        return self.get_status('AttachNetworkInterface', params, verb='POST')
2923
3370
 
2924
 
    def detach_network_interface(self, network_interface_id, force=False):
 
3371
    def detach_network_interface(self, attachment_id, force=False):
2925
3372
        """
2926
3373
        Detaches a network interface from an instance.
2927
3374
 
2928
 
        :type network_interface_id: str
2929
 
        :param network_interface_id: The ID of the network interface to detach.
 
3375
        :type attachment_id: str
 
3376
        :param attachment_id: The ID of the attachment.
2930
3377
 
2931
3378
        :type force: bool
2932
3379
        :param force: Set to true to force a detachment.
2933
3380
 
2934
3381
        """
2935
 
        params = {'NetworkInterfaceId' : network_interface_id}
 
3382
        params = {'AttachmentId': attachment_id}
2936
3383
        if force:
2937
3384
            params['Force'] = 'true'
2938
3385
        return self.get_status('DetachNetworkInterface', params, verb='POST')
2945
3392
        :param network_interface_id: The ID of the network interface to delete.
2946
3393
 
2947
3394
        """
2948
 
        params = {'NetworkInterfaceId' : network_interface_id}
 
3395
        params = {'NetworkInterfaceId': network_interface_id}
2949
3396
        return self.get_status('DeleteNetworkInterface', params, verb='POST')
 
3397
 
 
3398
    def get_all_vmtypes(self):
 
3399
        """
 
3400
        Get all vmtypes available on this cloud (eucalyptus specific)
 
3401
 
 
3402
        :rtype: list of :class:`boto.ec2.vmtype.VmType`
 
3403
        :return: The requested VmType objects
 
3404
        """
 
3405
        params = {}
 
3406
        return self.get_list('DescribeVmTypes', params, [('euca:item', VmType)], verb='POST')
 
3407
 
 
3408
    def copy_image(self, source_region, source_image_id, name,
 
3409
                   description=None, client_token=None):
 
3410
        params = {
 
3411
            'SourceRegion': source_region,
 
3412
            'SourceImageId': source_image_id,
 
3413
            'Name': name
 
3414
        }
 
3415
        if description is not None:
 
3416
            params['Description'] = description
 
3417
        if client_token is not None:
 
3418
            params['ClientToken'] = client_token
 
3419
        image = self.get_object('CopyImage', params, CopyImage,
 
3420
                                 verb='POST')
 
3421
        return image
 
3422
 
 
3423
    def describe_account_attributes(self, attribute_names=None):
 
3424
        params = {}
 
3425
        if attribute_names is not None:
 
3426
            self.build_list_params(params, attribute_names, 'AttributeName')
 
3427
        return self.get_list('DescribeAccountAttributes', params,
 
3428
                             [('item', AccountAttribute)], verb='POST')
 
3429
 
 
3430
    def describe_vpc_attribute(self, vpc_id, attribute=None):
 
3431
        params = {
 
3432
            'VpcId': vpc_id
 
3433
        }
 
3434
        if attribute is not None:
 
3435
            params['Attribute'] = attribute
 
3436
        attr = self.get_object('DescribeVpcAttribute', params,
 
3437
                               VPCAttribute, verb='POST')
 
3438
        return attr
 
3439
 
 
3440
    def modify_vpc_attribute(self, vpc_id, enable_dns_support=None,
 
3441
                             enable_dns_hostnames=None):
 
3442
        params = {
 
3443
            'VpcId': vpc_id
 
3444
        }
 
3445
        if enable_dns_support is not None:
 
3446
            params['EnableDnsSupport.Value'] = (
 
3447
                'true' if enable_dns_support else 'false')
 
3448
        if enable_dns_hostnames is not None:
 
3449
            params['EnableDnsHostnames.Value'] = (
 
3450
                'true' if enable_dns_hostnames else 'false')
 
3451
        result = self.get_status('ModifyVpcAttribute', params, verb='POST')
 
3452
        return result