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
59
64
#boto.set_stream_logger('ec2')
61
67
class EC2Connection(AWSQueryConnection):
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')
140
148
user ID has explicit launch permissions
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
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.
153
159
:return: A list of :class:`boto.ec2.image.Image`
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.
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.
340
344
:return: The new image id
342
params = {'InstanceId' : instance_id,
346
params = {'InstanceId': instance_id,
345
349
params['Description'] = description
438
442
:param instance_ids: A list of strings of instance IDs
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
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.
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):
524
529
Runs an image on EC2.
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.
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.
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.
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
538
544
:type security_groups: list of strings
539
545
:param security_groups: The names of the security groups with which to
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:
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
562
572
:type kernel_id: string
563
573
:param kernel_id: The ID of the kernel with which to launch the
566
576
:type ramdisk_id: string
567
577
:param ramdisk_id: The ID of the RAM disk with which to launch the
570
580
:type monitoring_enabled: bool
571
:param monitoring_enabled: Enable CloudWatch monitoring on the instance.
581
:param monitoring_enabled: Enable CloudWatch monitoring on
573
584
:type subnet_id: string
574
585
:param subnet_id: The subnet ID within which to launch the instances
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.,
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
596
describing the EBS volumes associated with the Image.
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
600
and will not be able to be terminated via the API.
593
602
:type instance_initiated_shutdown_behavior: string
594
603
:param instance_initiated_shutdown_behavior: Specifies whether the
604
instance stops or terminates on instance-initiated shutdown.
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.
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.
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.
622
:type additional_info: string
623
:param additional_info: Specifies additional information to make
624
available to the instance(s).
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
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.
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.
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.
649
:type network_interfaces: list
650
:param network_interfaces: A list of
651
:class:`boto.ec2.networkinterface.NetworkInterfaceSpecification`
613
653
:rtype: Reservation
614
654
:return: The :class:`boto.ec2.instance.Reservation` associated with
615
655
the request for machines
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
621
params = {'ImageId':image_id,
622
'MinCount':min_count,
657
params = {'ImageId': image_id,
658
'MinCount': min_count,
623
659
'MaxCount': max_count}
625
661
params['KeyName'] = key_name
795
852
:type attribute: string
796
853
:param attribute: The attribute you wish to change.
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)
807
866
:type value: string
808
867
:param value: The new value for the attribute
811
870
:return: Whether the operation succeeded or not
813
872
# Allow a bool to be passed in for value of disableApiTermination
814
if attribute == 'disableApiTermination':
873
bool_reqs = ('disableapitermination',
876
if attribute.lower() in bool_reqs:
815
877
if isinstance(value, bool):
820
params = {'InstanceId' : instance_id,
821
'Attribute' : attribute,
883
params = {'InstanceId': instance_id}
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):
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'
898
# for backwards compatibility handle lowercase first letter
899
attribute = attribute[0].upper() + attribute[1:]
900
params['%s.Value' % attribute] = value
823
902
return self.get_status('ModifyInstanceAttribute', params, verb='POST')
825
904
def reset_instance_attribute(self, instance_id, attribute):
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.
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.
897
974
:type instance_type: str
898
975
:param instance_type: Filter responses to a particular instance type.
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:
984
* Linux/UNIX (Amazon VPC)
985
* SUSE Linux (Amazon VPC)
986
* Windows (Amazon VPC)
905
988
:type availability_zone: str
906
989
:param availability_zone: The availability zone for which prices
990
should be returned. If not specified, data for all
991
availability zones will be returned.
910
994
:return: A list tuples containing price and timestamp.
977
1066
:type instance_type: string
978
1067
:param instance_type: The type of instance to run:
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
994
1084
:type kernel_id: string
995
1085
:param kernel_id: The ID of the kernel with which to launch the
998
1088
:type ramdisk_id: string
999
1089
:param ramdisk_id: The ID of the RAM disk with which to launch the
1002
1092
:type monitoring_enabled: bool
1003
:param monitoring_enabled: Enable CloudWatch monitoring on the instance.
1093
:param monitoring_enabled: Enable CloudWatch monitoring on
1005
1096
:type subnet_id: string
1006
1097
:param subnet_id: The subnet ID within which to launch the instances
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.
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
1106
describing the EBS volumes associated with the Image.
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.
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.
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.
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.
1127
:type network_interfaces: list
1128
:param network_interfaces: A list of
1129
:class:`boto.ec2.networkinterface.NetworkInterfaceSpecification`
1018
1131
:rtype: Reservation
1019
1132
:return: The :class:`boto.ec2.spotinstancerequest.SpotInstanceRequest`
1020
1133
associated with the request for machines
1022
params = {'LaunchSpecification.ImageId':image_id,
1024
'SpotPrice' : price}
1135
ls = 'LaunchSpecification'
1136
params = {'%s.ImageId' % ls: image_id,
1026
1140
params['InstanceCount'] = count
1033
1147
if availability_zone_group:
1034
1148
params['AvailabilityZoneGroup'] = availability_zone_group
1036
params['LaunchSpecification.KeyName'] = key_name
1150
params['%s.KeyName' % ls] = key_name
1151
if security_group_ids:
1039
for group in security_groups:
1153
for group in security_group_ids:
1040
1154
if isinstance(group, SecurityGroup):
1041
l.append(group.name)
1043
1157
l.append(group)
1044
1158
self.build_list_params(params, l,
1045
'LaunchSpecification.SecurityGroup')
1159
'%s.SecurityGroupId' % ls)
1162
for group in security_groups:
1163
if isinstance(group, SecurityGroup):
1164
l.append(group.name)
1167
self.build_list_params(params, l, '%s.SecurityGroup' % ls)
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
1053
params['LaunchSpecification.Placement.AvailabilityZone'] = placement
1175
params['%s.Placement.AvailabilityZone' % ls] = placement
1055
params['LaunchSpecification.KernelId'] = kernel_id
1177
params['%s.KernelId' % ls] = kernel_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'
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
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)],
1213
1348
return self.get_object('AllocateAddress', params, Address, verb='POST')
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):
1355
Assigns one or more secondary private IP addresses to a network
1356
interface in Amazon VPC.
1358
:type network_interface_id: string
1359
:param network_interface_id: The network interface to which the IP
1360
address will be assigned.
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.
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.
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.
1377
:return: True if successful
1381
if network_interface_id is not None:
1382
params['NetworkInterfaceId'] = network_interface_id
1384
if private_ip_addresses is not None:
1385
self.build_list_params(params, private_ip_addresses,
1387
elif secondary_private_ip_address_count is not None:
1388
params['SecondaryPrivateIpAddressCount'] = \
1389
secondary_private_ip_address_count
1391
if allow_reassignment:
1392
params['AllowReassignment'] = 'true'
1394
return self.get_status('AssignPrivateIpAddresses', params, verb='POST')
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):
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.
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``.
1221
1408
:type instance_id: string
1222
1409
:param instance_id: The ID of the instance
1227
1414
:type allocation_id: string
1228
1415
:param allocation_id: The allocation ID for a VPC-based elastic IP.
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
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.
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
1231
1432
:return: True if successful
1233
params = { 'InstanceId' : instance_id }
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
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
1445
if private_ip_address is not None:
1446
params['PrivateIpAddress'] = private_ip_address
1448
if allow_reassociation:
1449
params['AllowReassociation'] = 'true'
1240
1451
return self.get_status('AssociateAddress', params, verb='POST')
1242
1453
def disassociate_address(self, public_ip=None, association_id=None):
1264
1475
def release_address(self, public_ip=None, allocation_id=None):
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
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.
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``.
1268
1489
:type public_ip: string
1269
1490
:param public_ip: The public IP address for EC2 elastic IPs.
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.
1275
1496
:return: True if successful
1284
1505
return self.get_status('ReleaseAddress', params, verb='POST')
1507
def unassign_private_ip_addresses(self, network_interface_id=None,
1508
private_ip_addresses=None):
1510
Unassigns one or more secondary private IP addresses from a network
1511
interface in Amazon VPC.
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.
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.
1522
:return: True if successful
1526
if network_interface_id is not None:
1527
params['NetworkInterfaceId'] = network_interface_id
1529
if private_ip_addresses is not None:
1530
self.build_list_params(params, private_ip_addresses,
1533
return self.get_status('UnassignPrivateIpAddresses', params,
1286
1536
# Volume methods
1288
1538
def get_all_volumes(self, volume_ids=None, filters=None):
1421
1672
:param zone: The availability zone in which the Volume will be created.
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
1678
:type volume_type: string
1679
:param volume_type: The type of the volume. (optional). Valid
1680
values are: standard | io1.
1683
:param iops: The provisioned IOPs you want to associate with
1684
this volume. (optional)
1426
1686
if isinstance(zone, Zone):
1427
1687
zone = zone.name
1428
params = {'AvailabilityZone' : zone}
1688
params = {'AvailabilityZone': zone}
1430
1690
params['Size'] = size
1432
1692
if isinstance(snapshot, Snapshot):
1433
1693
snapshot = snapshot.id
1434
1694
params['SnapshotId'] = snapshot
1696
params['VolumeType'] = volume_type
1698
params['Iops'] = str(iops)
1435
1699
return self.get_object('CreateVolume', params, Volume, verb='POST')
1437
1701
def delete_volume(self, volume_id):
1481
1745
:type instance_id: str
1482
1746
:param instance_id: The ID of the EC2 instance from which it will
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)
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
1499
1764
:return: True if successful
1501
params = {'VolumeId' : volume_id}
1766
params = {'VolumeId': volume_id}
1502
1767
if instance_id:
1503
1768
params['InstanceId'] = instance_id
1586
1851
params = {'SnapshotId': snapshot_id}
1587
1852
return self.get_status('DeleteSnapshot', params, verb='POST')
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,
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).
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.).
1868
:type source_snapshot_id: str
1869
:param source_snapshot_id: The ID of the Amazon EBS snapshot to copy
1871
:type description: str
1872
:param description: A description of the new Amazon EBS snapshot.
1875
:return: The snapshot ID
1879
'SourceRegion': source_region,
1880
'SourceSnapshotId': source_snapshot_id,
1882
if description is not None:
1883
params['Description'] = description
1884
snapshot = self.get_object('CopySnapshot', params, Snapshot,
1888
def trim_snapshots(self, hourly_backups=8, daily_backups=7,
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
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.
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
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.
1833
2128
:return: A list of :class:`boto.ec2.keypair.KeyPair`
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.
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')
1925
2220
# SecurityGroup methods
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
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
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
2407
See http://goo.gl/Yj5QC
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.
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
2126
2420
:return: True if successful.
2461
2765
being performed. Check the EC2 API guide
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.
2773
:type offering_type: string
2774
:param offering_type: The Reserved Instance offering type. Valid
2775
Values: `"Heavy Utilization" | "Medium Utilization" | "Light
2778
:type include_marketplace: bool
2779
:param include_marketplace: Include Marketplace offerings in the
2782
:type min_duration: int :param min_duration: Minimum duration (in
2783
seconds) to filter when searching for offerings.
2785
:type max_duration: int
2786
:param max_duration: Maximum duration (in seconds) to filter when
2787
searching for offerings.
2789
:type max_instance_count: int
2790
:param max_instance_count: Maximum number of instances to filter when
2791
searching for offerings.
2793
:type next_token: string
2794
:param next_token: Token to use when requesting the next paginated set
2797
:type max_results: int
2798
:param max_results: Maximum number of offerings to return per call.
2465
:return: A list of :class:`boto.ec2.reservedinstance.ReservedInstancesOffering`
2802
:class:`boto.ec2.reservedinstance.ReservedInstancesOffering`.
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
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'
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)
2479
2837
return self.get_list('DescribeReservedInstancesOfferings',
2480
2838
params, [('item', ReservedInstancesOffering)],
2483
2841
def get_all_reserved_instances(self, reserved_instances_id=None,
2486
Describes Reserved Instance offerings that are available for purchase.
2844
Describes one or more of the Reserved Instances that you purchased.
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
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
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.
2504
2860
:return: A list of :class:`boto.ec2.reservedinstance.ReservedInstance`
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
2528
2884
:type instance_count: int
2529
2885
:param instance_count: The number of Reserved Instances to purchase.
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:
2532
2893
:rtype: :class:`boto.ec2.reservedinstance.ReservedInstance`
2533
2894
:return: The newly created Reserved Instance
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')
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.
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.
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
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.
2926
:type reserved_instances_id: string
2927
:param reserved_instances_id: The ID of the Reserved Instance that
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.
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::
2946
price_schedules=[('2.50', 11), ('2.00', 8)]
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.
2954
:class:`boto.ec2.reservedinstance.ReservedInstanceListing`
2958
'ReservedInstancesId': reserved_instances_id,
2959
'InstanceCount': str(instance_count),
2960
'ClientToken': client_token,
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')
2969
def cancel_reserved_instances_listing(
2970
self, reserved_instances_listing_ids=None):
2971
"""Cancels the specified Reserved Instance listing.
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.
2979
:class:`boto.ec2.reservedinstance.ReservedInstanceListing`
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')
2916
3363
:param device_index: The index of the device for the network
2917
3364
interface attachment on the instance.
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')
2924
def detach_network_interface(self, network_interface_id, force=False):
3371
def detach_network_interface(self, attachment_id, force=False):
2926
3373
Detaches a network interface from an instance.
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.
2931
3378
:type force: bool
2932
3379
:param force: Set to true to force a detachment.
2935
params = {'NetworkInterfaceId' : network_interface_id}
3382
params = {'AttachmentId': attachment_id}
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.
2948
params = {'NetworkInterfaceId' : network_interface_id}
3395
params = {'NetworkInterfaceId': network_interface_id}
2949
3396
return self.get_status('DeleteNetworkInterface', params, verb='POST')
3398
def get_all_vmtypes(self):
3400
Get all vmtypes available on this cloud (eucalyptus specific)
3402
:rtype: list of :class:`boto.ec2.vmtype.VmType`
3403
:return: The requested VmType objects
3406
return self.get_list('DescribeVmTypes', params, [('euca:item', VmType)], verb='POST')
3408
def copy_image(self, source_region, source_image_id, name,
3409
description=None, client_token=None):
3411
'SourceRegion': source_region,
3412
'SourceImageId': source_image_id,
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,
3423
def describe_account_attributes(self, attribute_names=None):
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')
3430
def describe_vpc_attribute(self, vpc_id, attribute=None):
3434
if attribute is not None:
3435
params['Attribute'] = attribute
3436
attr = self.get_object('DescribeVpcAttribute', params,
3437
VPCAttribute, verb='POST')
3440
def modify_vpc_attribute(self, vpc_id, enable_dns_support=None,
3441
enable_dns_hostnames=None):
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')