diff --git a/libcloud/compute/drivers/ecs.py b/libcloud/compute/drivers/ecs.py
index 250968aacb..a1bf742e74 100644
--- a/libcloud/compute/drivers/ecs.py
+++ b/libcloud/compute/drivers/ecs.py
@@ -1258,18 +1258,21 @@ def _to_node(self, instance):
state = self.NODE_STATE_MAPPING.get(instance_status, NodeState.UNKNOWN)
def _get_ips(ip_address_els):
- return [each.text for each in ip_address_els]
+ return [each.text for each in ip_address_els if each.text]
+
+ public_ips = []
+ for xpath in ("PublicIpAddress/IpAddress", "EipAddress/IpAddress"):
+ public_ip_els = findall(
+ element=instance,
+ xpath=xpath,
+ namespace=self.namespace,
+ )
+ public_ips.extend(_get_ips(public_ip_els))
- public_ip_els = findall(
- element=instance,
- xpath="PublicIpAddress/IpAddress",
- namespace=self.namespace,
- )
- public_ips = _get_ips(public_ip_els)
- private_ip_els = findall(
- element=instance, xpath="InnerIpAddress/IpAddress", namespace=self.namespace
- )
- private_ips = _get_ips(private_ip_els)
+ private_ips = []
+ for xpath in ("InnerIpAddress/IpAddress", "VpcAttributes/PrivateIpAddress/IpAddress"):
+ private_ip_els = findall(element=instance, xpath=xpath, namespace=self.namespace)
+ private_ips.extend(_get_ips(private_ip_els))
# Extra properties
extra = self._get_extra_dict(instance, RESOURCE_EXTRA_ATTRIBUTES_MAP["node"])
diff --git a/libcloud/test/compute/fixtures/ecs/describe_instances.xml b/libcloud/test/compute/fixtures/ecs/describe_instances.xml
index f1c7713601..5bef7a46f8 100644
--- a/libcloud/test/compute/fixtures/ecs/describe_instances.xml
+++ b/libcloud/test/compute/fixtures/ecs/describe_instances.xml
@@ -52,5 +52,50 @@
PostPaid
2999-09-08T16:00Z
+
+ ubuntu1404_64_20G_aliaegis_20150325.vhd
+
+ ecs.t1
+
+ i-28n7dkvov
+
+ 114.215.124.73
+
+
+
+ -1
+ cn-qingdao-b
+ PayByTraffic
+ ca0122d9-374d-4fce-9fc0-71f7c3eaf1c3
+ false
+ 1024
+ 1
+
+
+
+ 10.163.197.74
+
+
+
+
+ 1
+ true
+
+ sg-28ou0f3xa
+
+ iZ28n7dkvovZ
+
+ classic
+
+ iZ28n7dkvovZ
+ ecs.t1.small
+ 2015-12-27T07:35Z
+ Starting
+
+ cn-qingdao
+
+ PostPaid
+ 2999-09-08T16:00Z
+
diff --git a/libcloud/test/compute/test_ecs.py b/libcloud/test/compute/test_ecs.py
index f1ca077962..6de84ec783 100644
--- a/libcloud/test/compute/test_ecs.py
+++ b/libcloud/test/compute/test_ecs.py
@@ -72,49 +72,54 @@ def setUp(self):
self.fake_security_group_id = "fake_security_group_id"
def test_list_nodes(self):
+ # the test describes two nodes:
+ # the first on a classic network and with public ip attached
+ # the second on a vpc with an elastic ip attached
+ vpc_ips = [None, "10.163.197.74"]
+ eips = ["", "114.215.124.73"]
nodes = self.driver.list_nodes()
self.assertIsNotNone(nodes)
- self.assertEqual(1, len(nodes))
- node = nodes[0]
- self.assertEqual("iZ28n7dkvovZ", node.name)
- self.assertEqual("i-28n7dkvov", node.id)
- self.assertEqual(NodeState.PENDING, node.state)
- self.assertEqual(1, len(node.public_ips))
- self.assertEqual("114.215.124.73", node.public_ips[0])
- self.assertEqual(1, len(node.private_ips))
- self.assertEqual("10.163.197.74", node.private_ips[0])
- expected_extra = {
- "image_id": "ubuntu1404_64_20G_aliaegis_20150325.vhd",
- "description": "",
- "instance_type_family": "ecs.t1",
- "zone_id": "cn-qingdao-b",
- "internet_charge_type": "PayByTraffic",
- "serial_number": "ca0122d9-374d-4fce-9fc0-71f7c3eaf1c3",
- "io_optimized": "false",
- "device_available": "true",
- "instance_network_type": "classic",
- "hostname": "iZ28n7dkvovZ",
- "instance_type": "ecs.t1.small",
- "creation_time": "2015-12-27T07:35Z",
- "instance_charge_type": "PostPaid",
- "expired_time": "2999-09-08T16:00Z",
- }
- self._validate_extras(expected_extra, node.extra)
- vpc = {
- "vpc_id": "",
- "vswitch_id": "",
- "private_ip_address": None,
- "nat_ip_address": "",
- }
- self._validate_extras(vpc, node.extra["vpc_attributes"])
- eip_address = {
- "allocation_id": "",
- "ip_address": "",
- "internet_charge_type": "",
- "bandwidth": None,
- }
- self._validate_extras(eip_address, node.extra["eip_address"])
- self.assertIsNone(node.extra["operation_locks"]["lock_reason"])
+ self.assertEqual(2, len(nodes))
+ for node, vpc_ip, eip in zip(nodes, vpc_ips, eips):
+ self.assertEqual("iZ28n7dkvovZ", node.name)
+ self.assertEqual("i-28n7dkvov", node.id)
+ self.assertEqual(NodeState.PENDING, node.state)
+ self.assertEqual(1, len(node.public_ips))
+ self.assertEqual("114.215.124.73", node.public_ips[0])
+ self.assertEqual(1, len(node.private_ips))
+ self.assertEqual("10.163.197.74", node.private_ips[0])
+ expected_extra = {
+ "image_id": "ubuntu1404_64_20G_aliaegis_20150325.vhd",
+ "description": "",
+ "instance_type_family": "ecs.t1",
+ "zone_id": "cn-qingdao-b",
+ "internet_charge_type": "PayByTraffic",
+ "serial_number": "ca0122d9-374d-4fce-9fc0-71f7c3eaf1c3",
+ "io_optimized": "false",
+ "device_available": "true",
+ "instance_network_type": "classic",
+ "hostname": "iZ28n7dkvovZ",
+ "instance_type": "ecs.t1.small",
+ "creation_time": "2015-12-27T07:35Z",
+ "instance_charge_type": "PostPaid",
+ "expired_time": "2999-09-08T16:00Z",
+ }
+ self._validate_extras(expected_extra, node.extra)
+ vpc = {
+ "vpc_id": "",
+ "vswitch_id": "",
+ "private_ip_address": vpc_ip,
+ "nat_ip_address": "",
+ }
+ self._validate_extras(vpc, node.extra["vpc_attributes"])
+ eip_address = {
+ "allocation_id": "",
+ "ip_address": eip,
+ "internet_charge_type": "",
+ "bandwidth": None,
+ }
+ self._validate_extras(eip_address, node.extra["eip_address"])
+ self.assertIsNone(node.extra["operation_locks"]["lock_reason"])
def test_list_nodes_with_ex_node_ids(self):
ECSMockHttp.type = "list_nodes_ex_node_ids"