OLD | NEW |
1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/ |
2 # Copyright (c) 2010, Eucalyptus Systems, Inc. | 2 # Copyright (c) 2010, Eucalyptus Systems, Inc. |
3 # | 3 # |
4 # Permission is hereby granted, free of charge, to any person obtaining a | 4 # Permission is hereby granted, free of charge, to any person obtaining a |
5 # copy of this software and associated documentation files (the | 5 # copy of this software and associated documentation files (the |
6 # "Software"), to deal in the Software without restriction, including | 6 # "Software"), to deal in the Software without restriction, including |
7 # without limitation the rights to use, copy, modify, merge, publish, dis- | 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
8 # tribute, sublicense, and/or sell copies of the Software, and to permit | 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
9 # persons to whom the Software is furnished to do so, subject to the fol- | 9 # persons to whom the Software is furnished to do so, subject to the fol- |
10 # lowing conditions: | 10 # lowing conditions: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 from boto.ec2.spotdatafeedsubscription import SpotDatafeedSubscription | 50 from boto.ec2.spotdatafeedsubscription import SpotDatafeedSubscription |
51 from boto.ec2.bundleinstance import BundleInstanceTask | 51 from boto.ec2.bundleinstance import BundleInstanceTask |
52 from boto.ec2.placementgroup import PlacementGroup | 52 from boto.ec2.placementgroup import PlacementGroup |
53 from boto.ec2.tag import Tag | 53 from boto.ec2.tag import Tag |
54 from boto.exception import EC2ResponseError | 54 from boto.exception import EC2ResponseError |
55 | 55 |
56 #boto.set_stream_logger('ec2') | 56 #boto.set_stream_logger('ec2') |
57 | 57 |
58 class EC2Connection(AWSQueryConnection): | 58 class EC2Connection(AWSQueryConnection): |
59 | 59 |
60 APIVersion = boto.config.get('Boto', 'ec2_version', '2011-01-01') | 60 APIVersion = boto.config.get('Boto', 'ec2_version', '2011-11-01') |
61 DefaultRegionName = boto.config.get('Boto', 'ec2_region_name', 'us-east-1') | 61 DefaultRegionName = boto.config.get('Boto', 'ec2_region_name', 'us-east-1') |
62 DefaultRegionEndpoint = boto.config.get('Boto', 'ec2_region_endpoint', | 62 DefaultRegionEndpoint = boto.config.get('Boto', 'ec2_region_endpoint', |
63 'ec2.amazonaws.com') | 63 'ec2.amazonaws.com') |
64 ResponseError = EC2ResponseError | 64 ResponseError = EC2ResponseError |
65 | 65 |
66 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, | 66 def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, |
67 is_secure=True, host=None, port=None, | 67 is_secure=True, host=None, port=None, |
68 proxy=None, proxy_port=None, | 68 proxy=None, proxy_port=None, |
69 proxy_user=None, proxy_pass=None, debug=0, | 69 proxy_user=None, proxy_pass=None, debug=0, |
70 https_connection_factory=None, region=None, path='/', | 70 https_connection_factory=None, region=None, path='/', |
71 api_version=None, security_token=None): | 71 api_version=None, security_token=None): |
72 """ | 72 """ |
73 Init method to create a new connection to EC2. | 73 Init method to create a new connection to EC2. |
74 | |
75 B{Note:} The host argument is overridden by the host specified in the | |
76 boto configuration file. | |
77 """ | 74 """ |
78 if not region: | 75 if not region: |
79 region = RegionInfo(self, self.DefaultRegionName, | 76 region = RegionInfo(self, self.DefaultRegionName, |
80 self.DefaultRegionEndpoint) | 77 self.DefaultRegionEndpoint) |
81 self.region = region | 78 self.region = region |
82 AWSQueryConnection.__init__(self, aws_access_key_id, | 79 AWSQueryConnection.__init__(self, aws_access_key_id, |
83 aws_secret_access_key, | 80 aws_secret_access_key, |
84 is_secure, port, proxy, proxy_port, | 81 is_secure, port, proxy, proxy_port, |
85 proxy_user, proxy_pass, | 82 proxy_user, proxy_pass, |
86 self.region.endpoint, debug, | 83 self.region.endpoint, debug, |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 for details. | 445 for details. |
449 | 446 |
450 :rtype: list | 447 :rtype: list |
451 :return: A list of :class:`boto.ec2.instance.Reservation` | 448 :return: A list of :class:`boto.ec2.instance.Reservation` |
452 """ | 449 """ |
453 params = {} | 450 params = {} |
454 if instance_ids: | 451 if instance_ids: |
455 self.build_list_params(params, instance_ids, 'InstanceId') | 452 self.build_list_params(params, instance_ids, 'InstanceId') |
456 if filters: | 453 if filters: |
457 if 'group-id' in filters: | 454 if 'group-id' in filters: |
458 warnings.warn("The group-id filter now requires a security " | 455 gid = filters.get('group-id') |
459 "group identifier (sg-*) instead of a group " | 456 if not gid.startswith('sg-') or len(gid) != 11: |
460 "name. To filter by group name use the " | 457 warnings.warn( |
461 "'group-name' filter instead.", UserWarning) | 458 "The group-id filter now requires a security group " |
| 459 "identifier (sg-*) instead of a group name. To filter " |
| 460 "by group name use the 'group-name' filter instead.", |
| 461 UserWarning) |
462 self.build_filter_params(params, filters) | 462 self.build_filter_params(params, filters) |
463 return self.get_list('DescribeInstances', params, | 463 return self.get_list('DescribeInstances', params, |
464 [('item', Reservation)], verb='POST') | 464 [('item', Reservation)], verb='POST') |
465 | 465 |
466 def run_instances(self, image_id, min_count=1, max_count=1, | 466 def run_instances(self, image_id, min_count=1, max_count=1, |
467 key_name=None, security_groups=None, | 467 key_name=None, security_groups=None, |
468 user_data=None, addressing_type=None, | 468 user_data=None, addressing_type=None, |
469 instance_type='m1.small', placement=None, | 469 instance_type='m1.small', placement=None, |
470 kernel_id=None, ramdisk_id=None, | 470 kernel_id=None, ramdisk_id=None, |
471 monitoring_enabled=False, subnet_id=None, | 471 monitoring_enabled=False, subnet_id=None, |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 817 |
818 :rtype: list | 818 :rtype: list |
819 :return: A list of | 819 :return: A list of |
820 :class:`boto.ec2.spotinstancerequest.SpotInstanceRequest` | 820 :class:`boto.ec2.spotinstancerequest.SpotInstanceRequest` |
821 """ | 821 """ |
822 params = {} | 822 params = {} |
823 if request_ids: | 823 if request_ids: |
824 self.build_list_params(params, request_ids, 'SpotInstanceRequestId') | 824 self.build_list_params(params, request_ids, 'SpotInstanceRequestId') |
825 if filters: | 825 if filters: |
826 if 'launch.group-id' in filters: | 826 if 'launch.group-id' in filters: |
827 warnings.warn("The 'launch.group-id' filter now requires a " | 827 lgid = filters.get('launch.group-id') |
828 "security group id (sg-*) and no longer supports " | 828 if not lgid.startswith('sg-') or len(lgid) != 11: |
829 "filtering by group name. Please update your " | 829 warnings.warn( |
830 "filters accordingly.", UserWarning) | 830 "The 'launch.group-id' filter now requires a security " |
| 831 "group id (sg-*) and no longer supports filtering by " |
| 832 "group name. Please update your filters accordingly.", |
| 833 UserWarning) |
831 self.build_filter_params(params, filters) | 834 self.build_filter_params(params, filters) |
832 return self.get_list('DescribeSpotInstanceRequests', params, | 835 return self.get_list('DescribeSpotInstanceRequests', params, |
833 [('item', SpotInstanceRequest)], verb='POST') | 836 [('item', SpotInstanceRequest)], verb='POST') |
834 | 837 |
835 def get_spot_price_history(self, start_time=None, end_time=None, | 838 def get_spot_price_history(self, start_time=None, end_time=None, |
836 instance_type=None, product_description=None, | 839 instance_type=None, product_description=None, |
837 availability_zone=None): | 840 availability_zone=None): |
838 """ | 841 """ |
839 Retrieve the recent history of spot instances pricing. | 842 Retrieve the recent history of spot instances pricing. |
840 | 843 |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 Convenience method to retrieve a specific keypair (KeyPair). | 1699 Convenience method to retrieve a specific keypair (KeyPair). |
1697 | 1700 |
1698 :type image_id: string | 1701 :type image_id: string |
1699 :param image_id: the ID of the Image to retrieve | 1702 :param image_id: the ID of the Image to retrieve |
1700 | 1703 |
1701 :rtype: :class:`boto.ec2.keypair.KeyPair` | 1704 :rtype: :class:`boto.ec2.keypair.KeyPair` |
1702 :return: The KeyPair specified or None if it is not found | 1705 :return: The KeyPair specified or None if it is not found |
1703 """ | 1706 """ |
1704 try: | 1707 try: |
1705 return self.get_all_key_pairs(keynames=[keyname])[0] | 1708 return self.get_all_key_pairs(keynames=[keyname])[0] |
1706 except IndexError: # None of those key pairs available | 1709 except self.ResponseError, e: |
1707 return None | 1710 if e.code == 'InvalidKeyPair.NotFound': |
| 1711 return None |
| 1712 else: |
| 1713 raise |
1708 | 1714 |
1709 def create_key_pair(self, key_name): | 1715 def create_key_pair(self, key_name): |
1710 """ | 1716 """ |
1711 Create a new key pair for your account. | 1717 Create a new key pair for your account. |
1712 This will create the key pair within the region you | 1718 This will create the key pair within the region you |
1713 are currently connected to. | 1719 are currently connected to. |
1714 | 1720 |
1715 :type key_name: string | 1721 :type key_name: string |
1716 :param key_name: The name of the new keypair | 1722 :param key_name: The name of the new keypair |
1717 | 1723 |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1998 if from_port is not None: | 2004 if from_port is not None: |
1999 params['IpPermissions.1.FromPort'] = from_port | 2005 params['IpPermissions.1.FromPort'] = from_port |
2000 if to_port is not None: | 2006 if to_port is not None: |
2001 params['IpPermissions.1.ToPort'] = to_port | 2007 params['IpPermissions.1.ToPort'] = to_port |
2002 if cidr_ip: | 2008 if cidr_ip: |
2003 params['IpPermissions.1.IpRanges.1.CidrIp'] = cidr_ip | 2009 params['IpPermissions.1.IpRanges.1.CidrIp'] = cidr_ip |
2004 | 2010 |
2005 return self.get_status('AuthorizeSecurityGroupIngress', | 2011 return self.get_status('AuthorizeSecurityGroupIngress', |
2006 params, verb='POST') | 2012 params, verb='POST') |
2007 | 2013 |
2008 def authorize_security_group_egress(group_id, | 2014 def authorize_security_group_egress(self, |
| 2015 group_id, |
2009 ip_protocol, | 2016 ip_protocol, |
2010 from_port=None, | 2017 from_port=None, |
2011 to_port=None, | 2018 to_port=None, |
2012 src_group_id=None, | 2019 src_group_id=None, |
2013 cidr_ip=None): | 2020 cidr_ip=None): |
2014 """ | 2021 """ |
2015 The action adds one or more egress rules to a VPC security | 2022 The action adds one or more egress rules to a VPC security |
2016 group. Specifically, this action permits instances in a | 2023 group. Specifically, this action permits instances in a |
2017 security group to send traffic to one or more destination | 2024 security group to send traffic to one or more destination |
2018 CIDR IP address ranges, or to one or more destination | 2025 CIDR IP address ranges, or to one or more destination |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 if ip_protocol: | 2107 if ip_protocol: |
2101 params['IpProtocol'] = ip_protocol | 2108 params['IpProtocol'] = ip_protocol |
2102 if from_port: | 2109 if from_port: |
2103 params['FromPort'] = from_port | 2110 params['FromPort'] = from_port |
2104 if to_port: | 2111 if to_port: |
2105 params['ToPort'] = to_port | 2112 params['ToPort'] = to_port |
2106 if cidr_ip: | 2113 if cidr_ip: |
2107 params['CidrIp'] = cidr_ip | 2114 params['CidrIp'] = cidr_ip |
2108 return self.get_status('RevokeSecurityGroupIngress', params) | 2115 return self.get_status('RevokeSecurityGroupIngress', params) |
2109 | 2116 |
2110 def revoke_security_group(self, group_name, src_security_group_name=None, | 2117 def revoke_security_group(self, group_name=None, src_security_group_name=Non
e, |
2111 src_security_group_owner_id=None, | 2118 src_security_group_owner_id=None, |
2112 ip_protocol=None, from_port=None, to_port=None, | 2119 ip_protocol=None, from_port=None, to_port=None, |
2113 cidr_ip=None, group_id=None, | 2120 cidr_ip=None, group_id=None, |
2114 src_security_group_group_id=None): | 2121 src_security_group_group_id=None): |
2115 """ | 2122 """ |
2116 Remove an existing rule from an existing security group. | 2123 Remove an existing rule from an existing security group. |
2117 You need to pass in either src_security_group_name and | 2124 You need to pass in either src_security_group_name and |
2118 src_security_group_owner_id OR ip_protocol, from_port, to_port, | 2125 src_security_group_owner_id OR ip_protocol, from_port, to_port, |
2119 and cidr_ip. In other words, either you are revoking another | 2126 and cidr_ip. In other words, either you are revoking another |
2120 group or you are revoking some ip-based rule. | 2127 group or you are revoking some ip-based rule. |
(...skipping 25 matching lines...) Expand all Loading... |
2146 | 2153 |
2147 :rtype: bool | 2154 :rtype: bool |
2148 :return: True if successful. | 2155 :return: True if successful. |
2149 """ | 2156 """ |
2150 if src_security_group_name: | 2157 if src_security_group_name: |
2151 if from_port is None and to_port is None and ip_protocol is None: | 2158 if from_port is None and to_port is None and ip_protocol is None: |
2152 return self.revoke_security_group_deprecated( | 2159 return self.revoke_security_group_deprecated( |
2153 group_name, src_security_group_name, | 2160 group_name, src_security_group_name, |
2154 src_security_group_owner_id) | 2161 src_security_group_owner_id) |
2155 params = {} | 2162 params = {} |
2156 if group_name: | 2163 if group_name is not None: |
2157 params['GroupName'] = group_name | 2164 params['GroupName'] = group_name |
| 2165 if group_id is not None: |
| 2166 params['GroupId'] = group_id |
2158 if src_security_group_name: | 2167 if src_security_group_name: |
2159 param_name = 'IpPermissions.1.Groups.1.GroupName' | 2168 param_name = 'IpPermissions.1.Groups.1.GroupName' |
2160 params[param_name] = src_security_group_name | 2169 params[param_name] = src_security_group_name |
| 2170 if src_security_group_group_id: |
| 2171 param_name = 'IpPermissions.1.Groups.1.GroupId' |
| 2172 params[param_name] = src_security_group_group_id |
2161 if src_security_group_owner_id: | 2173 if src_security_group_owner_id: |
2162 param_name = 'IpPermissions.1.Groups.1.UserId' | 2174 param_name = 'IpPermissions.1.Groups.1.UserId' |
2163 params[param_name] = src_security_group_owner_id | 2175 params[param_name] = src_security_group_owner_id |
2164 if ip_protocol: | 2176 if ip_protocol: |
2165 params['IpPermissions.1.IpProtocol'] = ip_protocol | 2177 params['IpPermissions.1.IpProtocol'] = ip_protocol |
2166 if from_port is not None: | 2178 if from_port is not None: |
2167 params['IpPermissions.1.FromPort'] = from_port | 2179 params['IpPermissions.1.FromPort'] = from_port |
2168 if to_port is not None: | 2180 if to_port is not None: |
2169 params['IpPermissions.1.ToPort'] = to_port | 2181 params['IpPermissions.1.ToPort'] = to_port |
2170 if cidr_ip: | 2182 if cidr_ip: |
2171 params['IpPermissions.1.IpRanges.1.CidrIp'] = cidr_ip | 2183 params['IpPermissions.1.IpRanges.1.CidrIp'] = cidr_ip |
2172 return self.get_status('RevokeSecurityGroupIngress', | 2184 return self.get_status('RevokeSecurityGroupIngress', |
2173 params, verb='POST') | 2185 params, verb='POST') |
2174 | 2186 |
| 2187 def revoke_security_group_egress(self, |
| 2188 group_id, |
| 2189 ip_protocol, |
| 2190 from_port=None, |
| 2191 to_port=None, |
| 2192 src_group_id=None, |
| 2193 cidr_ip=None): |
| 2194 """ |
| 2195 Remove an existing egress rule from an existing VPC security group. |
| 2196 You need to pass in an ip_protocol, from_port and to_port range only |
| 2197 if the protocol you are using is port-based. You also need to pass in ei
ther |
| 2198 a src_group_id or cidr_ip. |
| 2199 |
| 2200 :type group_name: string |
| 2201 :param group_id: The name of the security group you are removing |
| 2202 the rule from. |
| 2203 |
| 2204 :type ip_protocol: string |
| 2205 :param ip_protocol: Either tcp | udp | icmp | -1 |
| 2206 |
| 2207 :type from_port: int |
| 2208 :param from_port: The beginning port number you are disabling |
| 2209 |
| 2210 :type to_port: int |
| 2211 :param to_port: The ending port number you are disabling |
| 2212 |
| 2213 :type src_group_id: src_group_id |
| 2214 :param src_group_id: The source security group you are revoking access t
o. |
| 2215 |
| 2216 :type cidr_ip: string |
| 2217 :param cidr_ip: The CIDR block you are revoking access to. |
| 2218 See http://goo.gl/Yj5QC |
| 2219 |
| 2220 :rtype: bool |
| 2221 :return: True if successful. |
| 2222 """ |
| 2223 |
| 2224 params = {} |
| 2225 if group_id: |
| 2226 params['GroupId'] = group_id |
| 2227 if ip_protocol: |
| 2228 params['IpPermissions.1.IpProtocol'] = ip_protocol |
| 2229 if from_port is not None: |
| 2230 params['IpPermissions.1.FromPort'] = from_port |
| 2231 if to_port is not None: |
| 2232 params['IpPermissions.1.ToPort'] = to_port |
| 2233 if src_group_id is not None: |
| 2234 params['IpPermissions.1.Groups.1.GroupId'] = src_group_id |
| 2235 if cidr_ip: |
| 2236 params['IpPermissions.1.IpRanges.1.CidrIp'] = cidr_ip |
| 2237 return self.get_status('RevokeSecurityGroupEgress', |
| 2238 params, verb='POST') |
| 2239 |
2175 # | 2240 # |
2176 # Regions | 2241 # Regions |
2177 # | 2242 # |
2178 | 2243 |
2179 def get_all_regions(self, region_names=None, filters=None): | 2244 def get_all_regions(self, region_names=None, filters=None): |
2180 """ | 2245 """ |
2181 Get all available regions for the EC2 service. | 2246 Get all available regions for the EC2 service. |
2182 | 2247 |
2183 :type region_names: list of str | 2248 :type region_names: list of str |
2184 :param region_names: Names of regions to limit output | 2249 :param region_names: Names of regions to limit output |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2610 be deleted. | 2675 be deleted. |
2611 | 2676 |
2612 """ | 2677 """ |
2613 if isinstance(tags, list): | 2678 if isinstance(tags, list): |
2614 tags = {}.fromkeys(tags, None) | 2679 tags = {}.fromkeys(tags, None) |
2615 params = {} | 2680 params = {} |
2616 self.build_list_params(params, resource_ids, 'ResourceId') | 2681 self.build_list_params(params, resource_ids, 'ResourceId') |
2617 self.build_tag_param_list(params, tags) | 2682 self.build_tag_param_list(params, tags) |
2618 return self.get_status('DeleteTags', params, verb='POST') | 2683 return self.get_status('DeleteTags', params, verb='POST') |
2619 | 2684 |
OLD | NEW |