| Index: txaws/ec2/client.py |
| === modified file 'txaws/ec2/client.py' |
| --- txaws/ec2/client.py 2012-05-05 00:17:02 +0000 |
| +++ txaws/ec2/client.py 2012-11-21 11:34:37 +0000 |
| @@ -48,7 +48,7 @@ |
| def run_instances(self, image_id, min_count, max_count, |
| security_groups=None, key_name=None, instance_type=None, |
| user_data=None, availability_zone=None, kernel_id=None, |
| - ramdisk_id=None): |
| + ramdisk_id=None, subnet_id=None, security_group_ids=None): |
| """Run new instances. |
| TODO: blockDeviceMapping, monitoring, subnetId |
| @@ -57,9 +57,21 @@ |
| "MaxCount": str(max_count)} |
| if key_name is not None: |
| params["KeyName"] = key_name |
| - if security_groups is not None: |
| + if subnet_id is not None: |
| + params["SubnetId"] = subnet_id |
| + if security_group_ids is not None: |
| + for i, id in enumerate(security_group_ids): |
| + params["SecurityGroupId.%d" % (i + 1)] = id |
| + else: |
| + msg = "You must specify the security_group_ids with the subnet_id" |
| + raise ValueError(msg) |
| + elif security_groups is not None: |
| for i, name in enumerate(security_groups): |
| params["SecurityGroup.%d" % (i + 1)] = name |
| + else: |
| + msg = ("You must specify either the subnet_id and " |
| + "security_group_ids or security_groups") |
| + raise ValueError(msg) |
| if user_data is not None: |
| params["UserData"] = b64encode(user_data) |
| if instance_type is not None: |
| @@ -547,6 +559,9 @@ |
| ipAddress, stateReason, architecture, rootDeviceName, |
| blockDeviceMapping, instanceLifecycle, spotInstanceRequestId. |
| """ |
| + for group_data in instance_data.find("groupSet"): |
| + group_id = group_data.findtext("groupId") |
| + reservation.groups.append(group_id) |
| instance_id = instance_data.findtext("instanceId") |
| instance_state = instance_data.find( |
| "instanceState").findtext("name") |
| @@ -599,16 +614,10 @@ |
| results = [] |
| # May be a more elegant way to do this: |
| for reservation_data in root.find("reservationSet"): |
| - # Get the security group information. |
| - groups = [] |
| - for group_data in reservation_data.find("groupSet"): |
| - group_id = group_data.findtext("groupId") |
| - groups.append(group_id) |
| # Create a reservation object with the parsed data. |
| reservation = model.Reservation( |
| reservation_id=reservation_data.findtext("reservationId"), |
| - owner_id=reservation_data.findtext("ownerId"), |
| - groups=groups) |
| + owner_id=reservation_data.findtext("ownerId")) |
| # Get the list of instances. |
| instances = self.instances_set( |
| reservation_data, reservation) |