2014-08-27 11:17:06 -04:00
|
|
|
from __future__ import unicode_literals
|
2014-09-08 16:50:18 -07:00
|
|
|
from jinja2 import Template
|
|
|
|
|
2013-12-29 08:40:38 -05:00
|
|
|
from moto.core.responses import BaseResponse
|
2014-09-08 16:50:18 -07:00
|
|
|
from moto.ec2.models import ec2_backend
|
2014-09-09 21:14:16 -04:00
|
|
|
from moto.ec2.utils import sequence_from_querystring, filters_from_querystring
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
|
2013-12-29 08:40:38 -05:00
|
|
|
class ElasticNetworkInterfaces(BaseResponse):
|
2013-02-21 23:13:01 -05:00
|
|
|
def create_network_interface(self):
|
2014-09-08 16:50:18 -07:00
|
|
|
subnet_id = self.querystring.get('SubnetId')[0]
|
|
|
|
private_ip_address = self.querystring.get('PrivateIpAddress', [None])[0]
|
|
|
|
groups = sequence_from_querystring('SecurityGroupId', self.querystring)
|
|
|
|
subnet = ec2_backend.get_subnet(subnet_id)
|
|
|
|
eni = ec2_backend.create_network_interface(subnet, private_ip_address, groups)
|
|
|
|
template = Template(CREATE_NETWORK_INTERFACE_RESPONSE)
|
|
|
|
return template.render(eni=eni)
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def delete_network_interface(self):
|
2014-09-08 16:50:18 -07:00
|
|
|
eni_id = self.querystring.get('NetworkInterfaceId')[0]
|
2014-09-09 21:14:16 -04:00
|
|
|
ec2_backend.delete_network_interface(eni_id)
|
2014-09-08 16:50:18 -07:00
|
|
|
template = Template(DELETE_NETWORK_INTERFACE_RESPONSE)
|
|
|
|
return template.render()
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def describe_network_interface_attribute(self):
|
2013-02-22 07:55:48 -05:00
|
|
|
raise NotImplementedError('ElasticNetworkInterfaces(AmazonVPC).describe_network_interface_attribute is not yet implemented')
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def describe_network_interfaces(self):
|
2014-09-08 16:50:18 -07:00
|
|
|
#Partially implemented. Supports only network-interface-id and group-id filters
|
|
|
|
filters = filters_from_querystring(self.querystring)
|
|
|
|
enis = ec2_backend.describe_network_interfaces(filters)
|
|
|
|
template = Template(DESCRIBE_NETWORK_INTERFACES_RESPONSE)
|
|
|
|
return template.render(enis=enis)
|
2013-02-21 23:13:01 -05:00
|
|
|
|
2014-09-12 10:53:37 -07:00
|
|
|
def attach_network_interface(self):
|
|
|
|
eni_id = self.querystring.get('NetworkInterfaceId')[0]
|
|
|
|
instance_id = self.querystring.get('InstanceId')[0]
|
|
|
|
device_index = self.querystring.get('DeviceIndex')[0]
|
|
|
|
attachment_id = ec2_backend.attach_network_interface(eni_id, instance_id, device_index)
|
|
|
|
template = Template(ATTACH_NETWORK_INTERFACE_RESPONSE)
|
|
|
|
return template.render(attachment_id=attachment_id)
|
|
|
|
|
2013-02-21 23:13:01 -05:00
|
|
|
def detach_network_interface(self):
|
2014-09-12 10:53:37 -07:00
|
|
|
attachment_id = self.querystring.get('AttachmentId')[0]
|
|
|
|
ec2_backend.detach_network_interface(attachment_id)
|
|
|
|
template = Template(DETACH_NETWORK_INTERFACE_RESPONSE)
|
|
|
|
return template.render()
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def modify_network_interface_attribute(self):
|
2014-09-08 16:50:18 -07:00
|
|
|
#Currently supports modifying one and only one security group
|
|
|
|
eni_id = self.querystring.get('NetworkInterfaceId')[0]
|
|
|
|
group_id = self.querystring.get('SecurityGroupId.1')[0]
|
|
|
|
ec2_backend.modify_network_interface_attribute(eni_id, group_id)
|
|
|
|
return MODIFY_NETWORK_INTERFACE_ATTRIBUTE_RESPONSE
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def reset_network_interface_attribute(self):
|
2013-02-22 07:55:48 -05:00
|
|
|
raise NotImplementedError('ElasticNetworkInterfaces(AmazonVPC).reset_network_interface_attribute is not yet implemented')
|
2014-09-08 16:50:18 -07:00
|
|
|
|
|
|
|
CREATE_NETWORK_INTERFACE_RESPONSE = """
|
|
|
|
<CreateNetworkInterfaceResponse xmlns="http://ec2.amazonaws.com/doc/2013-07-15/">
|
|
|
|
<requestId>2c6021ec-d705-445a-9780-420d0c7ab793</requestId>
|
|
|
|
<networkInterface>
|
|
|
|
<networkInterfaceId>{{ eni.id }}</networkInterfaceId>
|
|
|
|
<subnetId>{{ eni.subnet.id }}</subnetId>
|
|
|
|
<vpcId>{{ eni.subnet.vpc_id }}</vpcId>
|
|
|
|
<availabilityZone>us-west-2a</availabilityZone>
|
|
|
|
<description/>
|
|
|
|
<ownerId>498654062920</ownerId>
|
|
|
|
<requesterManaged>false</requesterManaged>
|
|
|
|
<status>pending</status>
|
|
|
|
<macAddress>02:07:a9:b6:12:51</macAddress>
|
|
|
|
{% if eni.private_ip_address %}
|
|
|
|
<privateIpAddress>{{ eni.private_ip_address }}</privateIpAddress>
|
|
|
|
{% endif %}
|
|
|
|
<sourceDestCheck>true</sourceDestCheck>
|
|
|
|
<groupSet>
|
|
|
|
{% for group in eni.group_set %}
|
|
|
|
<item>
|
|
|
|
<groupId>{{ group.id }}</groupId>
|
|
|
|
<groupName>{{ group.name }}</groupName>
|
|
|
|
</item>
|
|
|
|
{% endfor %}
|
|
|
|
</groupSet>
|
|
|
|
<tagSet/>
|
|
|
|
{% if eni.private_ip_address %}
|
|
|
|
<privateIpAddressesSet>
|
|
|
|
<item>
|
|
|
|
<privateIpAddress>{{ eni.private_ip_address }}</privateIpAddress>
|
|
|
|
<primary>true</primary>
|
|
|
|
</item>
|
|
|
|
</privateIpAddressesSet>
|
|
|
|
{% else %}
|
|
|
|
<privateIpAddressesSet/>
|
|
|
|
{% endif %}
|
|
|
|
</networkInterface>
|
|
|
|
</CreateNetworkInterfaceResponse>
|
|
|
|
"""
|
|
|
|
|
|
|
|
DESCRIBE_NETWORK_INTERFACES_RESPONSE = """<DescribeNetworkInterfacesResponse xmlns="http://ec2.amazonaws.com/doc/2013-07-15/">
|
|
|
|
<requestId>ddb0aaf1-8b65-4f0a-94fa-654b18b8a204</requestId>
|
|
|
|
<networkInterfaceSet>
|
|
|
|
{% for eni in enis %}
|
|
|
|
<item>
|
|
|
|
<networkInterfaceId>{{ eni.id }}</networkInterfaceId>
|
|
|
|
<subnetId>{{ eni.subnet.id }}</subnetId>
|
2014-09-09 21:14:16 -04:00
|
|
|
<vpcId>{{ eni.subnet.vpc_id }}</vpcId>
|
2014-09-08 16:50:18 -07:00
|
|
|
<availabilityZone>us-west-2a</availabilityZone>
|
|
|
|
<description>Primary network interface</description>
|
|
|
|
<ownerId>190610284047</ownerId>
|
|
|
|
<requesterManaged>false</requesterManaged>
|
|
|
|
<status>in-use</status>
|
|
|
|
<macAddress>0e:a3:a7:7b:95:a7</macAddress>
|
|
|
|
{% if eni.private_ip_address %}
|
|
|
|
<privateIpAddress>{{ eni.private_ip_address }}</privateIpAddress>
|
|
|
|
{% endif %}
|
|
|
|
<privateDnsName>ip-10-0-0-134.us-west-2.compute.internal</privateDnsName>
|
|
|
|
<sourceDestCheck>true</sourceDestCheck>
|
|
|
|
<groupSet>
|
|
|
|
{% for group in eni.group_set %}
|
|
|
|
<item>
|
|
|
|
<groupId>{{ group.id }}</groupId>
|
|
|
|
<groupName>{{ group.name }}</groupName>
|
|
|
|
</item>
|
|
|
|
{% endfor %}
|
|
|
|
</groupSet>
|
2014-09-12 10:53:37 -07:00
|
|
|
{% if eni.instance %}
|
|
|
|
<attachment>
|
|
|
|
<attachmentId>{{ eni.attachment_id }}</attachmentId>
|
|
|
|
<instanceId>{{ eni.instance.id }}</instanceId>
|
|
|
|
<instanceOwnerId>190610284047</instanceOwnerId>
|
|
|
|
<deviceIndex>{{ eni.device_index }}</deviceIndex>
|
|
|
|
<status>attached</status>
|
|
|
|
<attachTime>2013-10-04T17:38:53.000Z</attachTime>
|
|
|
|
<deleteOnTermination>true</deleteOnTermination>
|
|
|
|
</attachment>
|
|
|
|
{% endif %}
|
2014-09-08 16:50:18 -07:00
|
|
|
<association>
|
|
|
|
<publicIp>{{ eni.public_ip }}</publicIp>
|
|
|
|
<publicDnsName>ec2-54-200-86-47.us-west-2.compute.amazonaws.com</publicDnsName>
|
|
|
|
<ipOwnerId>amazon</ipOwnerId>
|
|
|
|
</association>
|
|
|
|
<tagSet/>
|
|
|
|
{% if eni.private_ip_address %}
|
|
|
|
<privateIpAddressesSet>
|
|
|
|
<item>
|
|
|
|
<privateIpAddress>{{ eni.private_ip_address }}</privateIpAddress>
|
|
|
|
<privateDnsName>ip-10-0-0-134.us-west-2.compute.internal</privateDnsName>
|
|
|
|
<primary>true</primary>
|
|
|
|
{% if eni.public_ip %}
|
|
|
|
<association>
|
|
|
|
<publicIp>{{ eni.public_ip }}</publicIp>
|
|
|
|
<publicDnsName>ec2-54-200-86-47.us-west-2.compute.amazonaws.com</publicDnsName>
|
|
|
|
<ipOwnerId>amazon</ipOwnerId>
|
|
|
|
</association>
|
|
|
|
{% endif %}
|
|
|
|
</item>
|
|
|
|
</privateIpAddressesSet>
|
|
|
|
{% else %}
|
|
|
|
<privateIpAddressesSet/>
|
|
|
|
{% endif %}
|
|
|
|
</item>
|
|
|
|
{% endfor %}
|
|
|
|
</networkInterfaceSet>
|
|
|
|
</DescribeNetworkInterfacesResponse>"""
|
|
|
|
|
2014-09-12 10:53:37 -07:00
|
|
|
ATTACH_NETWORK_INTERFACE_RESPONSE = """<AttachNetworkInterfaceResponse xmlns="http://ec2.amazonaws.com/doc/2014-06-15/">
|
|
|
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
|
|
|
<attachmentId>{{ attachment_id }}</attachmentId>
|
|
|
|
</AttachNetworkInterfaceResponse>"""
|
|
|
|
|
|
|
|
DETACH_NETWORK_INTERFACE_RESPONSE = """<DetachNetworkInterfaceResponse xmlns="http://ec2.amazonaws.com/doc/2014-06-15/">
|
|
|
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
|
|
|
<return>true</return>
|
|
|
|
</DetachNetworkInterfaceResponse>"""
|
|
|
|
|
2014-09-08 16:50:18 -07:00
|
|
|
MODIFY_NETWORK_INTERFACE_ATTRIBUTE_RESPONSE = """<ModifyNetworkInterfaceAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
|
|
|
<requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>
|
|
|
|
<return>true</return>
|
|
|
|
</ModifyNetworkInterfaceAttributeResponse>"""
|
|
|
|
|
|
|
|
DELETE_NETWORK_INTERFACE_RESPONSE = """
|
|
|
|
<DeleteNetworkInterfaceResponse xmlns="http://ec2.amazonaws.com/doc/2013-07-15/">
|
|
|
|
<requestId>34b5b3b4-d0c5-49b9-b5e2-a468ef6adcd8</requestId>
|
|
|
|
<return>true</return>
|
|
|
|
</DeleteNetworkInterfaceResponse>"""
|