Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions libcloud/compute/drivers/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
45 changes: 45 additions & 0 deletions libcloud/test/compute/fixtures/ecs/describe_instances.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,50 @@
<InstanceChargeType>PostPaid</InstanceChargeType>
<ExpiredTime>2999-09-08T16:00Z</ExpiredTime>
</Instance>
<Instance>
<ImageId>ubuntu1404_64_20G_aliaegis_20150325.vhd</ImageId>
<InnerIpAddress/>
<InstanceTypeFamily>ecs.t1</InstanceTypeFamily>
<VlanId></VlanId>
<InstanceId>i-28n7dkvov</InstanceId>
<EipAddress>
<IpAddress>114.215.124.73</IpAddress>
<AllocationId></AllocationId>
<InternetChargeType></InternetChargeType>
</EipAddress>
<InternetMaxBandwidthIn>-1</InternetMaxBandwidthIn>
<ZoneId>cn-qingdao-b</ZoneId>
<InternetChargeType>PayByTraffic</InternetChargeType>
<SerialNumber>ca0122d9-374d-4fce-9fc0-71f7c3eaf1c3</SerialNumber>
<IoOptimized>false</IoOptimized>
<Memory>1024</Memory>
<Cpu>1</Cpu>
<VpcAttributes>
<NatIpAddress></NatIpAddress>
<PrivateIpAddress>
<IpAddress>10.163.197.74</IpAddress>
</PrivateIpAddress>
<VSwitchId></VSwitchId>
<VpcId></VpcId>
</VpcAttributes>
<InternetMaxBandwidthOut>1</InternetMaxBandwidthOut>
<DeviceAvailable>true</DeviceAvailable>
<SecurityGroupIds>
<SecurityGroupId>sg-28ou0f3xa</SecurityGroupId>
</SecurityGroupIds>
<InstanceName>iZ28n7dkvovZ</InstanceName>
<Description></Description>
<InstanceNetworkType>classic</InstanceNetworkType>
<PublicIpAddress/>
<HostName>iZ28n7dkvovZ</HostName>
<InstanceType>ecs.t1.small</InstanceType>
<CreationTime>2015-12-27T07:35Z</CreationTime>
<Status>Starting</Status>
<ClusterId></ClusterId>
<RegionId>cn-qingdao</RegionId>
<OperationLocks />
<InstanceChargeType>PostPaid</InstanceChargeType>
<ExpiredTime>2999-09-08T16:00Z</ExpiredTime>
</Instance>
</Instances>
</DescribeInstancesResponse>
87 changes: 46 additions & 41 deletions libcloud/test/compute/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down