LEFT | RIGHT |
1 # Copyright (C) 2009 Robert Collins <robertc@robertcollins.net> | 1 # Copyright (C) 2009 Robert Collins <robertc@robertcollins.net> |
2 # Copyright (C) 2009 Canonical Ltd | 2 # Copyright (C) 2009 Canonical Ltd |
3 # Copyright (C) 2009 Duncan McGreggor <oubiwann@adytum.us> | 3 # Copyright (C) 2009 Duncan McGreggor <oubiwann@adytum.us> |
4 # Licenced under the txaws licence available at /LICENSE in the txaws source. | 4 # Licenced under the txaws licence available at /LICENSE in the txaws source. |
5 | 5 |
6 """EC2 client support.""" | 6 """EC2 client support.""" |
7 | 7 |
8 from datetime import datetime | 8 from datetime import datetime |
9 from urllib import quote | 9 from urllib import quote |
10 from base64 import b64encode | 10 from base64 import b64encode |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 group_names = {} | 103 group_names = {} |
104 if names: | 104 if names: |
105 group_names = dict([("GroupName.%d" % (i + 1), name) | 105 group_names = dict([("GroupName.%d" % (i + 1), name) |
106 for i, name in enumerate(names)]) | 106 for i, name in enumerate(names)]) |
107 query = self.query_factory( | 107 query = self.query_factory( |
108 action="DescribeSecurityGroups", creds=self.creds, | 108 action="DescribeSecurityGroups", creds=self.creds, |
109 endpoint=self.endpoint, other_params=group_names) | 109 endpoint=self.endpoint, other_params=group_names) |
110 d = query.submit() | 110 d = query.submit() |
111 return d.addCallback(self.parser.describe_security_groups) | 111 return d.addCallback(self.parser.describe_security_groups) |
112 | 112 |
113 def create_security_group(self, name, description): | 113 def create_security_group(self, name, description, vpc_id=None): |
114 """Create security group. | 114 """Create security group. |
115 | 115 |
116 @param name: Name of the new security group. | 116 @param name: Name of the new security group. |
117 @param description: Description of the new security group. | 117 @param description: Description of the new security group. |
| 118 @param vpc_id: ID of the VPC to which the security group will belong. |
118 @return: A C{Deferred} that will fire with a truth value for the | 119 @return: A C{Deferred} that will fire with a truth value for the |
119 success of the operation. | 120 success of the operation. |
120 """ | 121 """ |
121 parameters = {"GroupName": name, "GroupDescription": description} | 122 parameters = {"GroupName": name, "GroupDescription": description} |
| 123 if vpc_id: |
| 124 parameters["VpcId"] = vpc_id |
122 query = self.query_factory( | 125 query = self.query_factory( |
123 action="CreateSecurityGroup", creds=self.creds, | 126 action="CreateSecurityGroup", creds=self.creds, |
124 endpoint=self.endpoint, other_params=parameters) | 127 endpoint=self.endpoint, other_params=parameters) |
125 d = query.submit() | 128 d = query.submit() |
126 return d.addCallback(self.parser.truth_return) | 129 return d.addCallback(self.parser.create_security_group) |
127 | 130 |
128 def delete_security_group(self, name=None, id=None): | 131 def delete_security_group(self, name=None, id=None): |
129 """ | 132 """ |
130 @param name: Name of the new security group. | 133 @param name: Name of the security group. |
| 134 @param id: Id of the security group. |
131 @return: A C{Deferred} that will fire with a truth value for the | 135 @return: A C{Deferred} that will fire with a truth value for the |
132 success of the operation. | 136 success of the operation. |
133 """ | 137 """ |
134 if name: | 138 if name: |
135 parameter = {"GroupName": name} | 139 parameter = {"GroupName": name} |
136 elif id: | 140 elif id: |
137 parameter = {"GroupId": id} | 141 parameter = {"GroupId": id} |
138 else: | 142 else: |
139 raise ValueError("You must provide either the security group name or
id") | 143 raise ValueError("You must provide either the security group name or
id") |
140 query = self.query_factory( | 144 query = self.query_factory( |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 | 717 |
714 allowed_groups = [model.UserIDGroupPair(user_id, group_name) | 718 allowed_groups = [model.UserIDGroupPair(user_id, group_name) |
715 for user_id, group_name in allowed_groups] | 719 for user_id, group_name in allowed_groups] |
716 | 720 |
717 security_group = model.SecurityGroup( | 721 security_group = model.SecurityGroup( |
718 id, name, description, owner_id=owner_id, | 722 id, name, description, owner_id=owner_id, |
719 groups=allowed_groups, ips=allowed_ips) | 723 groups=allowed_groups, ips=allowed_ips) |
720 result.append(security_group) | 724 result.append(security_group) |
721 return result | 725 return result |
722 | 726 |
| 727 def create_security_group(self, xml_bytes): |
| 728 root = XML(xml_bytes) |
| 729 return root.findtext("groupId") |
| 730 |
723 def truth_return(self, xml_bytes): | 731 def truth_return(self, xml_bytes): |
724 """Parse the XML for a truth value. | 732 """Parse the XML for a truth value. |
725 | 733 |
726 @param xml_bytes: XML bytes. | 734 @param xml_bytes: XML bytes. |
727 @return: True if the node contains "return" otherwise False. | 735 @return: True if the node contains "return" otherwise False. |
728 """ | 736 """ |
729 root = XML(xml_bytes) | 737 root = XML(xml_bytes) |
730 return root.findtext("return") == "true" | 738 return root.findtext("return") == "true" |
731 | 739 |
732 def describe_volumes(self, xml_bytes): | 740 def describe_volumes(self, xml_bytes): |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 See the AWS dev reference page 186 (2009-11-30 version). | 1080 See the AWS dev reference page 186 (2009-11-30 version). |
1073 @return: a_string encoded. | 1081 @return: a_string encoded. |
1074 """ | 1082 """ |
1075 if isinstance(string, unicode): | 1083 if isinstance(string, unicode): |
1076 string = string.encode("utf-8") | 1084 string = string.encode("utf-8") |
1077 return quote(string, safe="~") | 1085 return quote(string, safe="~") |
1078 | 1086 |
1079 def sorted_params(self): | 1087 def sorted_params(self): |
1080 """Return the query parameters sorted appropriately for signing.""" | 1088 """Return the query parameters sorted appropriately for signing.""" |
1081 return sorted(self.params.items()) | 1089 return sorted(self.params.items()) |
LEFT | RIGHT |