Skip to content
Closed
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
24 changes: 20 additions & 4 deletions libcloud/compute/drivers/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ class ECSDriver(NodeDriver):
Used for Aliyun ECS service.

TODO:
Create public IP address
Get guest OS root password
Adjust internet bandwidth settings
Manage security groups and rules
Expand Down Expand Up @@ -675,9 +674,9 @@ def create_node(self, name, size, image, auth=None,

if ex_io_optimized is not None:
optimized = ex_io_optimized
if not isinstance(optimized, bool):
optimized = str(optimized).lower() == 'true'
params['IoOptimized'] = 'true' if optimized else 'false'
if isinstance(optimized, bool):
optimized = 'optimized' if optimized else 'none'
params['IoOptimized'] = optimized

if ex_system_disk:
system_disk = self._get_system_disk(ex_system_disk)
Expand Down Expand Up @@ -1273,6 +1272,23 @@ def copy_image(self, source_region, node_image, name, description=None,
image_id = findtext(resp.object, 'ImageId', namespace=self.namespace)
return self.get_image(image_id=image_id)

def create_public_ip(self, instance_id):
"""
Create public ip.

:keyword instance_id: instance id for allocating public ip.
:type instance_id: ``str``

:return public ip
:rtype ``str``
"""
params = {'Action': 'AllocatePublicIpAddress',
'InstanceId': instance_id}

resp = self.connection.request(self.path, params=params)
return findtext(resp.object, 'IpAddress',
namespace=self.namespace)

def _to_nodes(self, object):
"""
Convert response to Node object list
Expand Down
6 changes: 6 additions & 0 deletions libcloud/test/compute/fixtures/ecs/create_public_ip.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<AllocatePublicIpAddressResponse>
<RequestId>F2EF6A3B-E345-46B9-931E-0EA094818567</RequestId>
<IpAddress>10.1.149.159</IpAddress>
</AllocatePublicIpAddressResponse>

12 changes: 11 additions & 1 deletion libcloud/test/compute/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def setUp(self):
driver=self.driver)
self.fake_location = NodeLocation(id=self.region, name=self.region,
country=None, driver=self.driver)
self.fake_instance_id = 'fake_instance_id'

def test_list_nodes(self):
nodes = self.driver.list_nodes()
Expand Down Expand Up @@ -247,6 +248,11 @@ def test_stop_node_with_ex_force_stop(self):
result = self.driver.ex_stop_node(self.fake_node, ex_force_stop=True)
self.assertTrue(result)

def test_create_public_ip(self):
ECSMockHttp.type = 'create_public_ip'
result = self.driver.create_public_ip(self.fake_instance_id)
self.assertTrue(result)

def test_list_volumes(self):
volumes = self.driver.list_volumes()
self.assertEqual(2, len(volumes))
Expand Down Expand Up @@ -579,7 +585,7 @@ def _create_node_CreateInstance(self, method, url, body, headers):
'InternetMaxBandwidthIn': '200',
'HostName': 'hostname',
'Password': 'password',
'IoOptimized': 'true',
'IoOptimized': 'optimized',
'SystemDisk.Category': 'cloud',
'SystemDisk.DiskName': 'root',
'SystemDisk.Description': 'sys',
Expand Down Expand Up @@ -930,6 +936,10 @@ def _DescribeZones(self, method, url, body, headers):
resp_body = self.fixtures.load('describe_zones.xml')
return (httplib.OK, resp_body, {}, httplib.responses[httplib.OK])

def _create_public_ip_AllocatePublicIpAddress(self, method, url, body, headers):
resp_body = self.fixtures.load('create_public_ip.xml')
return (httplib.OK, resp_body, {}, httplib.responses[httplib.OK])


if __name__ == '__main__':
sys.exit(unittest.main())