You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by an...@apache.org on 2016/11/14 23:51:41 UTC
[54/56] [abbrv] libcloud git commit: Implement the method for
creating public ip Closes #943
Implement the method for creating public ip
Closes #943
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c726d1fb
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c726d1fb
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c726d1fb
Branch: refs/heads/trunk
Commit: c726d1fbb04cd924fb36b8982f014566a908e53b
Parents: f646f1c
Author: hequn <he...@hihuron.com>
Authored: Mon Nov 14 10:49:48 2016 +0800
Committer: Anthony Shaw <an...@apache.org>
Committed: Tue Nov 15 10:22:02 2016 +1100
----------------------------------------------------------------------
libcloud/compute/drivers/ecs.py | 18 +++++++++++++++++-
.../compute/fixtures/ecs/create_public_ip.xml | 6 ++++++
libcloud/test/compute/test_ecs.py | 10 ++++++++++
3 files changed, 33 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c726d1fb/libcloud/compute/drivers/ecs.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ecs.py b/libcloud/compute/drivers/ecs.py
index 1dc6cb5..bb34453 100644
--- a/libcloud/compute/drivers/ecs.py
+++ b/libcloud/compute/drivers/ecs.py
@@ -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
@@ -1273,6 +1272,23 @@ class ECSDriver(NodeDriver):
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
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c726d1fb/libcloud/test/compute/fixtures/ecs/create_public_ip.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ecs/create_public_ip.xml b/libcloud/test/compute/fixtures/ecs/create_public_ip.xml
new file mode 100644
index 0000000..e723d7f
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ecs/create_public_ip.xml
@@ -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>
+
http://git-wip-us.apache.org/repos/asf/libcloud/blob/c726d1fb/libcloud/test/compute/test_ecs.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ecs.py b/libcloud/test/compute/test_ecs.py
index d1bbae9..f610da8 100644
--- a/libcloud/test/compute/test_ecs.py
+++ b/libcloud/test/compute/test_ecs.py
@@ -58,6 +58,7 @@ class ECSDriverTestCase(LibcloudTestCase):
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()
@@ -247,6 +248,11 @@ class ECSDriverTestCase(LibcloudTestCase):
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))
@@ -930,6 +936,10 @@ class ECSMockHttp(MockHttpTestCase):
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())