Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: boto/ec2/connection.py

Issue 8669001: Pull in upstream boto from github at bcb719937de9ac2851e632d62b777352029a6d55 (Closed) Base URL: svn://svn.chromium.org/boto
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « boto/ec2/cloudwatch/__init__.py ('k') | boto/ec2/elb/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: boto/ec2/connection.py
diff --git a/boto/ec2/connection.py b/boto/ec2/connection.py
index 1e492594d6dd61118c83c27e25d3298a2d22089c..f94f7f2136de9bd57ae13256537d42aa76e0cf65 100644
--- a/boto/ec2/connection.py
+++ b/boto/ec2/connection.py
@@ -57,7 +57,7 @@ from boto.exception import EC2ResponseError
class EC2Connection(AWSQueryConnection):
- APIVersion = boto.config.get('Boto', 'ec2_version', '2011-01-01')
+ APIVersion = boto.config.get('Boto', 'ec2_version', '2011-11-01')
DefaultRegionName = boto.config.get('Boto', 'ec2_region_name', 'us-east-1')
DefaultRegionEndpoint = boto.config.get('Boto', 'ec2_region_endpoint',
'ec2.amazonaws.com')
@@ -71,9 +71,6 @@ class EC2Connection(AWSQueryConnection):
api_version=None, security_token=None):
"""
Init method to create a new connection to EC2.
-
- B{Note:} The host argument is overridden by the host specified in the
- boto configuration file.
"""
if not region:
region = RegionInfo(self, self.DefaultRegionName,
@@ -455,10 +452,13 @@ class EC2Connection(AWSQueryConnection):
self.build_list_params(params, instance_ids, 'InstanceId')
if filters:
if 'group-id' in filters:
- warnings.warn("The group-id filter now requires a security "
- "group identifier (sg-*) instead of a group "
- "name. To filter by group name use the "
- "'group-name' filter instead.", UserWarning)
+ gid = filters.get('group-id')
+ if not gid.startswith('sg-') or len(gid) != 11:
+ warnings.warn(
+ "The group-id filter now requires a security group "
+ "identifier (sg-*) instead of a group name. To filter "
+ "by group name use the 'group-name' filter instead.",
+ UserWarning)
self.build_filter_params(params, filters)
return self.get_list('DescribeInstances', params,
[('item', Reservation)], verb='POST')
@@ -824,10 +824,13 @@ class EC2Connection(AWSQueryConnection):
self.build_list_params(params, request_ids, 'SpotInstanceRequestId')
if filters:
if 'launch.group-id' in filters:
- warnings.warn("The 'launch.group-id' filter now requires a "
- "security group id (sg-*) and no longer supports "
- "filtering by group name. Please update your "
- "filters accordingly.", UserWarning)
+ lgid = filters.get('launch.group-id')
+ if not lgid.startswith('sg-') or len(lgid) != 11:
+ warnings.warn(
+ "The 'launch.group-id' filter now requires a security "
+ "group id (sg-*) and no longer supports filtering by "
+ "group name. Please update your filters accordingly.",
+ UserWarning)
self.build_filter_params(params, filters)
return self.get_list('DescribeSpotInstanceRequests', params,
[('item', SpotInstanceRequest)], verb='POST')
@@ -1703,8 +1706,11 @@ class EC2Connection(AWSQueryConnection):
"""
try:
return self.get_all_key_pairs(keynames=[keyname])[0]
- except IndexError: # None of those key pairs available
- return None
+ except self.ResponseError, e:
+ if e.code == 'InvalidKeyPair.NotFound':
+ return None
+ else:
+ raise
def create_key_pair(self, key_name):
"""
@@ -2005,7 +2011,8 @@ class EC2Connection(AWSQueryConnection):
return self.get_status('AuthorizeSecurityGroupIngress',
params, verb='POST')
- def authorize_security_group_egress(group_id,
+ def authorize_security_group_egress(self,
+ group_id,
ip_protocol,
from_port=None,
to_port=None,
@@ -2107,7 +2114,7 @@ class EC2Connection(AWSQueryConnection):
params['CidrIp'] = cidr_ip
return self.get_status('RevokeSecurityGroupIngress', params)
- def revoke_security_group(self, group_name, src_security_group_name=None,
+ def revoke_security_group(self, group_name=None, src_security_group_name=None,
src_security_group_owner_id=None,
ip_protocol=None, from_port=None, to_port=None,
cidr_ip=None, group_id=None,
@@ -2153,11 +2160,16 @@ class EC2Connection(AWSQueryConnection):
group_name, src_security_group_name,
src_security_group_owner_id)
params = {}
- if group_name:
+ if group_name is not None:
params['GroupName'] = group_name
+ if group_id is not None:
+ params['GroupId'] = group_id
if src_security_group_name:
param_name = 'IpPermissions.1.Groups.1.GroupName'
params[param_name] = src_security_group_name
+ if src_security_group_group_id:
+ param_name = 'IpPermissions.1.Groups.1.GroupId'
+ params[param_name] = src_security_group_group_id
if src_security_group_owner_id:
param_name = 'IpPermissions.1.Groups.1.UserId'
params[param_name] = src_security_group_owner_id
@@ -2172,6 +2184,59 @@ class EC2Connection(AWSQueryConnection):
return self.get_status('RevokeSecurityGroupIngress',
params, verb='POST')
+ def revoke_security_group_egress(self,
+ group_id,
+ ip_protocol,
+ from_port=None,
+ to_port=None,
+ src_group_id=None,
+ cidr_ip=None):
+ """
+ Remove an existing egress rule from an existing VPC security group.
+ You need to pass in an ip_protocol, from_port and to_port range only
+ if the protocol you are using is port-based. You also need to pass in either
+ a src_group_id or cidr_ip.
+
+ :type group_name: string
+ :param group_id: The name of the security group you are removing
+ the rule from.
+
+ :type ip_protocol: string
+ :param ip_protocol: Either tcp | udp | icmp | -1
+
+ :type from_port: int
+ :param from_port: The beginning port number you are disabling
+
+ :type to_port: int
+ :param to_port: The ending port number you are disabling
+
+ :type src_group_id: src_group_id
+ :param src_group_id: The source security group you are revoking access to.
+
+ :type cidr_ip: string
+ :param cidr_ip: The CIDR block you are revoking access to.
+ See http://goo.gl/Yj5QC
+
+ :rtype: bool
+ :return: True if successful.
+ """
+
+ params = {}
+ if group_id:
+ params['GroupId'] = group_id
+ if ip_protocol:
+ params['IpPermissions.1.IpProtocol'] = ip_protocol
+ if from_port is not None:
+ params['IpPermissions.1.FromPort'] = from_port
+ if to_port is not None:
+ params['IpPermissions.1.ToPort'] = to_port
+ if src_group_id is not None:
+ params['IpPermissions.1.Groups.1.GroupId'] = src_group_id
+ if cidr_ip:
+ params['IpPermissions.1.IpRanges.1.CidrIp'] = cidr_ip
+ return self.get_status('RevokeSecurityGroupEgress',
+ params, verb='POST')
+
#
# Regions
#
« no previous file with comments | « boto/ec2/cloudwatch/__init__.py ('k') | boto/ec2/elb/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698