Fix ec2 tags in instance create. Closes #938.
This commit is contained in:
parent
0fe824277b
commit
97b920f6cf
4 changed files with 80 additions and 1 deletions
|
|
@ -141,6 +141,10 @@ class TaggedEC2Resource(BaseModel):
|
|||
def add_tag(self, key, value):
|
||||
self.ec2_backend.create_tags([self.id], {key: value})
|
||||
|
||||
def add_tags(self, tag_map):
|
||||
for key, value in tag_map.items():
|
||||
self.ec2_backend.create_tags([self.id], {key: value})
|
||||
|
||||
def get_filter_value(self, filter_name):
|
||||
tags = self.get_tags()
|
||||
|
||||
|
|
@ -638,6 +642,10 @@ class InstanceBackend(object):
|
|||
security_groups.extend(self.get_security_group_from_id(sg_id)
|
||||
for sg_id in kwargs.pop("security_group_ids", []))
|
||||
self.reservations[new_reservation.id] = new_reservation
|
||||
|
||||
tags = kwargs.pop("tags", {})
|
||||
instance_tags = tags.get('instance', {})
|
||||
|
||||
for index in range(count):
|
||||
new_instance = Instance(
|
||||
self,
|
||||
|
|
@ -647,6 +655,7 @@ class InstanceBackend(object):
|
|||
**kwargs
|
||||
)
|
||||
new_reservation.instances.append(new_instance)
|
||||
new_instance.add_tags(instance_tags)
|
||||
new_instance.setup_defaults()
|
||||
return new_reservation
|
||||
|
||||
|
|
|
|||
|
|
@ -47,13 +47,15 @@ class InstanceResponse(BaseResponse):
|
|||
associate_public_ip = self.querystring.get(
|
||||
"AssociatePublicIpAddress", [None])[0]
|
||||
key_name = self.querystring.get("KeyName", [None])[0]
|
||||
tags = self._parse_tag_specification("TagSpecification")
|
||||
|
||||
if self.is_not_dryrun('RunInstance'):
|
||||
new_reservation = self.ec2_backend.add_instances(
|
||||
image_id, min_count, user_data, security_group_names,
|
||||
instance_type=instance_type, placement=placement, subnet_id=subnet_id,
|
||||
key_name=key_name, security_group_ids=security_group_ids,
|
||||
nics=nics, private_ip=private_ip, associate_public_ip=associate_public_ip)
|
||||
nics=nics, private_ip=private_ip, associate_public_ip=associate_public_ip,
|
||||
tags=tags)
|
||||
|
||||
template = self.response_template(EC2_RUN_INSTANCES)
|
||||
return template.render(reservation=new_reservation)
|
||||
|
|
@ -282,6 +284,14 @@ EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc
|
|||
<clientToken/>
|
||||
<hypervisor>xen</hypervisor>
|
||||
<ebsOptimized>false</ebsOptimized>
|
||||
<tagSet>
|
||||
{% for tag in instance.get_tags() %}
|
||||
<item>
|
||||
<key>{{ tag.key }}</key>
|
||||
<value>{{ tag.value }}</value>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</tagSet>
|
||||
<networkInterfaceSet>
|
||||
{% for nic in instance.nics.values() %}
|
||||
<item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue