You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by qu...@apache.org on 2018/01/19 06:31:28 UTC
[1/2] libcloud git commit: ECS Aliyun: support
modify_security_group_attributes
Repository: libcloud
Updated Branches:
refs/heads/trunk 408b5c565 -> f7d527e33
ECS Aliyun: support modify_security_group_attributes
Signed-off-by: Quentin Pradet <qu...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/7818b344
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/7818b344
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/7818b344
Branch: refs/heads/trunk
Commit: 7818b344ecf891b750cc1900a4ab7c5383cc100b
Parents: 408b5c5
Author: Zhang Yiming <zh...@mails.ucas.ac.cn>
Authored: Wed Jan 3 02:20:46 2018 +0000
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Jan 19 10:31:04 2018 +0400
----------------------------------------------------------------------
libcloud/compute/drivers/ecs.py | 29 ++++++++
.../fixtures/ecs/create_security_group.xml | 1 +
.../ecs/delete_security_group_by_id.xml | 2 +-
.../ecs/describe_security_group_attributes.xml | 54 +++++++-------
.../ecs/modify_security_group_by_id.xml | 4 ++
libcloud/test/compute/test_ecs.py | 74 ++++++++++++++++----
6 files changed, 124 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/7818b344/libcloud/compute/drivers/ecs.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ecs.py b/libcloud/compute/drivers/ecs.py
index e92d467..1e2474b 100644
--- a/libcloud/compute/drivers/ecs.py
+++ b/libcloud/compute/drivers/ecs.py
@@ -820,6 +820,35 @@ class ECSDriver(NodeDriver):
resp = self.connection.request(self.path, params)
return resp.success()
+ def ex_modify_security_group_by_id(
+ self,
+ group_id=None,
+ name=None,
+ description=None):
+ """
+ Modify a new security group.
+ :keyword group_id: id of the security group
+ :type group_id: ``str``
+ :keyword name: new name of the security group
+ :type name: ``unicode``
+ :keyword description: new description of the security group
+ :type description: ``unicode``
+ """
+
+ params = {'Action': 'ModifySecurityGroupAttribute',
+ 'RegionId': self.region}
+ if not group_id:
+ raise AttributeError('group_id is required')
+ params["SecurityGroupId"] = group_id
+
+ if name:
+ params["SecurityGroupName"] = name
+ if description:
+ params["Description"] = description
+
+ resp = self.connection.request(self.path, params)
+ return resp.success()
+
def ex_list_security_groups(self, ex_filters=None):
"""
List security groups in the current region.
http://git-wip-us.apache.org/repos/asf/libcloud/blob/7818b344/libcloud/test/compute/fixtures/ecs/create_security_group.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ecs/create_security_group.xml b/libcloud/test/compute/fixtures/ecs/create_security_group.xml
index 3303b7d..27d3a78 100644
--- a/libcloud/test/compute/fixtures/ecs/create_security_group.xml
+++ b/libcloud/test/compute/fixtures/ecs/create_security_group.xml
@@ -1,4 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
+<CreateSecurityGroupResponse>
<RequestId>CEF72CEB-54B6-4AE8-B225-F876FF7BA984</RequestId>
<SecurityGroupId>sg-F876FF7BA</SecurityGroupId>
</CreateSecurityGroupResponse>
http://git-wip-us.apache.org/repos/asf/libcloud/blob/7818b344/libcloud/test/compute/fixtures/ecs/delete_security_group_by_id.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ecs/delete_security_group_by_id.xml b/libcloud/test/compute/fixtures/ecs/delete_security_group_by_id.xml
index e57f7d8..bba024e 100644
--- a/libcloud/test/compute/fixtures/ecs/delete_security_group_by_id.xml
+++ b/libcloud/test/compute/fixtures/ecs/delete_security_group_by_id.xml
@@ -1,4 +1,4 @@
<?xml version='1.0' encoding='UTF-8'?>
<DeleteSecurityGroupResponse>
- <RequestId>CEF72CEB-54B6-4AE8-B225-F876FF7BA984</RquestID>
+ <RequestId>CEF72CEB-54B6-4AE8-B225-F876FF7BA984</RequestId>
</DeleteSecurityGroupResponse>
http://git-wip-us.apache.org/repos/asf/libcloud/blob/7818b344/libcloud/test/compute/fixtures/ecs/describe_security_group_attributes.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ecs/describe_security_group_attributes.xml b/libcloud/test/compute/fixtures/ecs/describe_security_group_attributes.xml
index 3c7815f..04f9dc0 100644
--- a/libcloud/test/compute/fixtures/ecs/describe_security_group_attributes.xml
+++ b/libcloud/test/compute/fixtures/ecs/describe_security_group_attributes.xml
@@ -1,26 +1,30 @@
<?xml version='1.0' encoding='UTF-8'?>
-<DescribeSecurityGroupsResponse>
- <RequestId>94D38899-626D-434A-891F-7E1F77A81525</RequestId>
- <TotalCount>4</TotalCount>
- <PageNumber>1</PageNumber>
- <PageSize>10</PageSize>
- <RegionId>cn-hangzhou </RegionId>
- <SecurityGroups>
- <SecurityGroup>
- <SecurityGroupId>sg-F876FF7BA</SecurityGroupId>
- <Description>Test</Description>
- </SecurityGroup>
- <SecurityGroup>
- <SecurityGroupId>sg-086FFC27A</SecurityGroupId>
- <Description>test00212</Description>
- </SecurityGroup>
- <SecurityGroup>
- <SecurityGroupId>sg-BA4B7975B</SecurityGroupId>
- <Description>cn-hangzhou test group</Description>
- </SecurityGroup>
- <SecurityGroup>
- <SecurityGroupId>sg-35F20777C</SecurityGroupId>
- <Description>cn-hangzhou test group</Description>
- </SecurityGroup>
- </SecurityGroups>
-</DescribeSecurityGroupsResponse>
+<DescribeSecurityGroupAttributeResponse>
+ <SecurityGroupId>sg-m5e5vyj2j0atm2gewww4</SecurityGroupId>
+ <InnerAccessPolicy>Accept</InnerAccessPolicy>
+ <SecurityGroupName>sg-m5e5vyj2j0atm2gewww4</SecurityGroupName>
+ <Description>System created security group.</Description>
+ <RegionId>cn-qingdao</RegionId>
+ <RequestId>8A3E0262-EEA1-4961-A403-3D6E69F3539C</RequestId>
+ <Permissions>
+ <Permission>
+ <SourceCidrIp>121.43.18.0/24</SourceCidrIp>
+ <DestCidrIp></DestCidrIp>
+ <Description></Description>
+ <NicType>internet</NicType>
+ <DestGroupName></DestGroupName>
+ <PortRange>-1/-1</PortRange>
+ <DestGroupId></DestGroupId>
+ <Direction>ingress</Direction>
+ <Priority>1</Priority>
+ <IpProtocol>ALL</IpProtocol>
+ <SourceGroupOwnerAccount></SourceGroupOwnerAccount>
+ <Policy>Accept</Policy>
+ <CreateTime>2017-07-08T06:20:39Z</CreateTime>
+ <SourceGroupId></SourceGroupId>
+ <DestGroupOwnerAccount></DestGroupOwnerAccount>
+ <SourceGroupName></SourceGroupName>
+ </Permission>
+ </Permissions>
+ <VpcId></VpcId>
+</DescribeSecurityGroupAttributeResponse>
http://git-wip-us.apache.org/repos/asf/libcloud/blob/7818b344/libcloud/test/compute/fixtures/ecs/modify_security_group_by_id.xml
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/ecs/modify_security_group_by_id.xml b/libcloud/test/compute/fixtures/ecs/modify_security_group_by_id.xml
new file mode 100644
index 0000000..12fe1ce
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ecs/modify_security_group_by_id.xml
@@ -0,0 +1,4 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<ModifySecurityGroupAttributeResponse>
+ <RequestId>CEF72CEB-54B6-4AE8-B225-F876FF7BA984</RequestId>
+</ModifySecurityGroupAttributeResponse>
http://git-wip-us.apache.org/repos/asf/libcloud/blob/7818b344/libcloud/test/compute/test_ecs.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_ecs.py b/libcloud/test/compute/test_ecs.py
index 348d24b..b51f872 100644
--- a/libcloud/test/compute/test_ecs.py
+++ b/libcloud/test/compute/test_ecs.py
@@ -59,6 +59,7 @@ class ECSDriverTestCase(LibcloudTestCase):
self.fake_location = NodeLocation(id=self.region, name=self.region,
country=None, driver=self.driver)
self.fake_instance_id = 'fake_instance_id'
+ self.fake_security_group_id = 'fake_security_group_id'
def test_list_nodes(self):
nodes = self.driver.list_nodes()
@@ -517,6 +518,13 @@ class ECSDriverTestCase(LibcloudTestCase):
image = self.driver.copy_image(self.region, self.fake_image, None)
self.assertIsNotNone(image)
+ def test_ex_create_security_group(self):
+ self.sg_description = 'description'
+ self.client_token = 'client-token'
+ sg_id = self.driver.ex_create_security_group(
+ description=self.sg_description, client_token=self.client_token)
+ self.assertEqual('sg-F876FF7BA', sg_id)
+
def test_ex_list_security_groups(self):
sgs = self.driver.ex_list_security_groups()
self.assertEqual(1, len(sgs))
@@ -528,15 +536,27 @@ class ECSDriverTestCase(LibcloudTestCase):
self.assertEqual('2015-06-26T08:35:30Z', sg.creation_time)
def test_ex_join_security_group(self):
- ex_security_group_id_value = 'sg-28ou0f3xa'
- result = self.driver.ex_join_security_group(self.fake_node,
- group_id=ex_security_group_id_value)
+ result = self.driver.ex_join_security_group(
+ self.fake_node, group_id=self.fake_security_group_id)
self.assertTrue(result)
def test_ex_leave_security_group(self):
- ex_security_group_id_value = 'sg-28ou0f3xa'
- result = self.driver.ex_leave_security_group(self.fake_node,
- group_id=ex_security_group_id_value)
+ result = self.driver.ex_leave_security_group(
+ self.fake_node, group_id=self.fake_security_group_id)
+ self.assertTrue(result)
+
+ def test_ex_delete_security_group_by_id(self):
+ result = self.driver.ex_delete_security_group_by_id(
+ group_id=self.fake_security_group_id)
+ self.assertTrue(result)
+
+ def test_ex_modify_security_group_by_id(self):
+ self.sg_name = 'name'
+ self.sg_description = 'description'
+ result = self.driver.ex_modify_security_group_by_id(
+ group_id=self.fake_security_group_id,
+ name=self.sg_name,
+ description=self.sg_description)
self.assertTrue(result)
def test_ex_list_security_groups_with_ex_filters(self):
@@ -546,6 +566,17 @@ class ECSDriverTestCase(LibcloudTestCase):
sgs = self.driver.ex_list_security_groups(ex_filters=ex_filters)
self.assertEqual(1, len(sgs))
+ def test_ex_list_security_group_attributes(self):
+ self.sga_nictype = 'internet'
+ sgas = self.driver.ex_list_security_group_attributes(
+ group_id=self.fake_security_group_id, nic_type=self.sga_nictype)
+ self.assertEqual(1, len(sgas))
+ sga = sgas[0]
+ self.assertEqual('ALL', sga.ip_protocol)
+ self.assertEqual('-1/-1', sga.port_range)
+ self.assertEqual('Accept', sga.policy)
+ self.assertEqual('internet', sga.nic_type)
+
def test_ex_list_zones(self):
zones = self.driver.ex_list_zones()
self.assertEqual(1, len(zones))
@@ -915,10 +946,16 @@ class ECSMockHttp(MockHttp):
return (httplib.OK, resp_body, {}, httplib.responses[httplib.OK])
def _JoinSecurityGroup(self, method, url, body, headers):
+ params = {'InstanceId': self.test.fake_node.id,
+ 'SecurityGroupId': self.test.fake_security_group_id}
+ self.assertUrlContainsQueryParams(url, params)
body = self.fixtures.load('join_security_group_by_id.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
def _LeaveSecurityGroup(self, method, url, body, headers):
+ params = {'InstanceId': self.test.fake_node.id,
+ 'SecurityGroupId': self.test.fake_security_group_id}
+ self.assertUrlContainsQueryParams(url, params)
body = self.fixtures.load('leave_security_group_by_id.xml')
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
@@ -928,25 +965,34 @@ class ECSMockHttp(MockHttp):
self.assertUrlContainsQueryParams(url, params)
return self._DescribeSecurityGroups(method, url, body, headers)
- def _create_sg_CreateSecurityGroup(self, method, url, body, headers):
+ def _CreateSecurityGroup(self, method, url, body, headers):
params = {'RegionId': self.test.region,
- 'Description': 'description',
- 'ClientToken': 'clientToken'}
+ 'Description': self.test.sg_description,
+ 'ClientToken': self.test.client_token}
self.assertUrlContainsQueryParams(url, params)
resp_body = self.fixtures.load('create_security_group.xml')
return (httplib.OK, resp_body, {}, httplib.responses[httplib.OK])
- def _delete_sg_by_id_DeleteSecurityGroup(self, method, url, body, headers):
+ def _DeleteSecurityGroup(self, method, url, body, headers):
params = {'RegionId': self.test.region,
- 'SecurityGroupId': 'sg-fakeSecurityGroupId'}
+ 'SecurityGroupId': self.test.fake_security_group_id}
self.assertUrlContainsQueryParams(url, params)
resp_body = self.fixtures.load('delete_security_group_by_id.xml')
return (httplib.OK, resp_body, {}, httplib.responses[httplib.OK])
- def _list_sgas_DescribeSecurityGroupAttributes(self, method, url, body, headers):
+ def _ModifySecurityGroupAttribute(self, method, url, body, headers):
+ params = {'RegionId': self.test.region,
+ 'SecurityGroupId': self.test.fake_security_group_id,
+ 'SecurityGroupName': self.test.sg_name,
+ 'Description': self.test.sg_description}
+ self.assertUrlContainsQueryParams(url, params)
+ resp_body = self.fixtures.load('modify_security_group_by_id.xml')
+ return (httplib.OK, resp_body, {}, httplib.responses[httplib.OK])
+
+ def _DescribeSecurityGroupAttribute(self, method, url, body, headers):
params = {'RegionId': self.test.region,
- 'SecurityGroupId': 'sg-fakeSecurityGroupId',
- 'NicType': 'internet'}
+ 'SecurityGroupId': self.test.fake_security_group_id,
+ 'NicType': self.test.sga_nictype}
self.assertUrlContainsQueryParams(url, params)
resp_body = self.fixtures.load('describe_security_group_attributes.xml')
return (httplib.OK, resp_body, {}, httplib.responses[httplib.OK])
[2/2] libcloud git commit: Add changes for #1157
Posted by qu...@apache.org.
Add changes for #1157
Closes #1157
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/f7d527e3
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/f7d527e3
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/f7d527e3
Branch: refs/heads/trunk
Commit: f7d527e33f4cc80ac910456577c28cdf90c3bae7
Parents: 7818b34
Author: Quentin Pradet <qu...@apache.org>
Authored: Fri Jan 19 10:26:58 2018 +0400
Committer: Quentin Pradet <qu...@apache.org>
Committed: Fri Jan 19 10:31:11 2018 +0400
----------------------------------------------------------------------
CHANGES.rst | 3 +++
1 file changed, 3 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/f7d527e3/CHANGES.rst
----------------------------------------------------------------------
diff --git a/CHANGES.rst b/CHANGES.rst
index be7a163..56f1469 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -120,6 +120,9 @@ Compute
(GITHUB-1156, LIBCLOUD-971)
[Tobias Paepke]
+- [ECS Aliyun] Support modify_security_group_attributes (GITHUB-1157)
+ [Zhang Yiming]
+
Storage
~~~~~~~