Merge pull request #1120 from JackDanger/jack/rendering-vpc_id-in-ec2-responses

rendering vpc_id in ec2 responses
This commit is contained in:
Jack Danger 2017-09-08 16:38:03 -07:00 committed by GitHub
commit 49035d3477
2 changed files with 35 additions and 26 deletions

View File

@ -255,17 +255,19 @@ EC2_RUN_INSTANCES = """<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc
<monitoring> <monitoring>
<state>enabled</state> <state>enabled</state>
</monitoring> </monitoring>
{% if instance.nics %} {% if instance.subnet_id %}
{% if instance.nics[0].subnet %}
<subnetId>{{ instance.nics[0].subnet.id }}</subnetId>
<vpcId>{{ instance.nics[0].subnet.vpc_id }}</vpcId>
{% endif %}
<privateIpAddress>{{ instance.private_ip }}</privateIpAddress>
{% if instance.public_ip %}
<ipAddress>{{ instance.public_ip }}</ipAddress>
{% endif %}
{% else %}
<subnetId>{{ instance.subnet_id }}</subnetId> <subnetId>{{ instance.subnet_id }}</subnetId>
{% elif instance.nics[0].subnet.id %}
<subnetId>{{ instance.nics[0].subnet.id }}</subnetId>
{% endif %}
{% if instance.vpc_id %}
<vpcId>{{ instance.vpc_id }}</vpcId>
{% elif instance.nics[0].subnet.vpc_id %}
<vpcId>{{ instance.nics[0].subnet.vpc_id }}</vpcId>
{% endif %}
<privateIpAddress>{{ instance.private_ip }}</privateIpAddress>
{% if instance.nics[0].public_ip %}
<ipAddress>{{ instance.nics[0].public_ip }}</ipAddress>
{% endif %} {% endif %}
<sourceDestCheck>{{ instance.source_dest_check }}</sourceDestCheck> <sourceDestCheck>{{ instance.source_dest_check }}</sourceDestCheck>
<groupSet> <groupSet>
@ -396,26 +398,30 @@ EC2_DESCRIBE_INSTANCES = """<DescribeInstancesResponse xmlns="http://ec2.amazona
<monitoring> <monitoring>
<state>disabled</state> <state>disabled</state>
</monitoring> </monitoring>
{% if instance.nics %} {% if instance.subnet_id %}
{% if instance.nics[0].subnet %} <subnetId>{{ instance.subnet_id }}</subnetId>
<subnetId>{{ instance.nics[0].subnet.id }}</subnetId> {% elif instance.nics[0].subnet.id %}
<vpcId>{{ instance.nics[0].subnet.vpc_id }}</vpcId> <subnetId>{{ instance.nics[0].subnet.id }}</subnetId>
{% endif %} {% endif %}
<privateIpAddress>{{ instance.private_ip }}</privateIpAddress> {% if instance.vpc_id %}
{% if instance.nics[0].public_ip %} <vpcId>{{ instance.vpc_id }}</vpcId>
<ipAddress>{{ instance.nics[0].public_ip }}</ipAddress> {% elif instance.nics[0].subnet.vpc_id %}
{% endif %} <vpcId>{{ instance.nics[0].subnet.vpc_id }}</vpcId>
{% endif %}
<privateIpAddress>{{ instance.private_ip }}</privateIpAddress>
{% if instance.nics[0].public_ip %}
<ipAddress>{{ instance.nics[0].public_ip }}</ipAddress>
{% endif %} {% endif %}
<sourceDestCheck>{{ instance.source_dest_check }}</sourceDestCheck> <sourceDestCheck>{{ instance.source_dest_check }}</sourceDestCheck>
<groupSet> <groupSet>
{% for group in instance.dynamic_group_list %} {% for group in instance.dynamic_group_list %}
<item> <item>
{% if group.id %} {% if group.id %}
<groupId>{{ group.id }}</groupId> <groupId>{{ group.id }}</groupId>
<groupName>{{ group.name }}</groupName> <groupName>{{ group.name }}</groupName>
{% else %} {% else %}
<groupId>{{ group }}</groupId> <groupId>{{ group }}</groupId>
{% endif %} {% endif %}
</item> </item>
{% endfor %} {% endfor %}
</groupSet> </groupSet>

View File

@ -378,11 +378,15 @@ def test_get_instances_filtering_by_vpc_id():
reservations1.should.have.length_of(1) reservations1.should.have.length_of(1)
reservations1[0].instances.should.have.length_of(1) reservations1[0].instances.should.have.length_of(1)
reservations1[0].instances[0].id.should.equal(instance1.id) reservations1[0].instances[0].id.should.equal(instance1.id)
reservations1[0].instances[0].vpc_id.should.equal(vpc1.id)
reservations1[0].instances[0].subnet_id.should.equal(subnet1.id)
reservations2 = conn.get_all_instances(filters={'vpc-id': vpc2.id}) reservations2 = conn.get_all_instances(filters={'vpc-id': vpc2.id})
reservations2.should.have.length_of(1) reservations2.should.have.length_of(1)
reservations2[0].instances.should.have.length_of(1) reservations2[0].instances.should.have.length_of(1)
reservations2[0].instances[0].id.should.equal(instance2.id) reservations2[0].instances[0].id.should.equal(instance2.id)
reservations2[0].instances[0].vpc_id.should.equal(vpc2.id)
reservations2[0].instances[0].subnet_id.should.equal(subnet2.id)
@mock_ec2_deprecated @mock_ec2_deprecated
@ -876,7 +880,6 @@ def test_run_instance_with_nic_autocreated():
eni.private_ip_addresses.should.have.length_of(1) eni.private_ip_addresses.should.have.length_of(1)
eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip) eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip)
@mock_ec2_deprecated @mock_ec2_deprecated
def test_run_instance_with_nic_preexisting(): def test_run_instance_with_nic_preexisting():
conn = boto.connect_vpc('the_key', 'the_secret') conn = boto.connect_vpc('the_key', 'the_secret')