libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [6/8] libcloud git commit: Aliyun ecs: Add support for creating security group
Date Fri, 24 Jun 2016 03:54:24 GMT
Aliyun ecs: Add support for creating security group


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/1e5c631b
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/1e5c631b
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/1e5c631b

Branch: refs/heads/trunk
Commit: 1e5c631bd60eaeaa4314286669c25ba409d95c70
Parents: 8b8e133
Author: netgenius <wuheng09@otcaix.iscas.ac.cn>
Authored: Sat Jun 11 00:15:58 2016 +0800
Committer: Anthony Shaw <anthonyshaw@apache.org>
Committed: Fri Jun 24 13:50:17 2016 +1000

----------------------------------------------------------------------
 example_aliyun_ecs.py           | 10 ++++++++--
 libcloud/compute/drivers/ecs.py | 21 +++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e5c631b/example_aliyun_ecs.py
----------------------------------------------------------------------
diff --git a/example_aliyun_ecs.py b/example_aliyun_ecs.py
index bbaaf00..5c223c6 100644
--- a/example_aliyun_ecs.py
+++ b/example_aliyun_ecs.py
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import sys
+
 from libcloud.compute.types import Provider
 from libcloud.compute.providers import get_driver
 from libcloud.compute.base import NodeAuthPassword
@@ -51,8 +53,12 @@ print('Use image %s' % image)
 
 sgs = ecs.ex_list_security_groups()
 print('Found %d security groups' % len(sgs))
-sg = sgs[0]
-print('Use security group %s' % sg)
+if len(sgs) == 0:
+    sg = ecs.ex_create_security_groups(ex_description='test')
+    print('Create security group %s' % sg)
+else:
+    sg = sgs[0]
+    print('Use security group %s' % sg)
 
 nodes = ecs.list_nodes()
 print('Found %d nodes' % len(nodes))

http://git-wip-us.apache.org/repos/asf/libcloud/blob/1e5c631b/libcloud/compute/drivers/ecs.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/ecs.py b/libcloud/compute/drivers/ecs.py
index 2ac8afa..787df7f 100644
--- a/libcloud/compute/drivers/ecs.py
+++ b/libcloud/compute/drivers/ecs.py
@@ -768,6 +768,27 @@ class ECSDriver(NodeDriver):
         return resp.success() and \
             self._wait_until_state([node], NodeState.STOPPED)
 
+    def ex_create_security_groups(self, ex_description=None,
+                                  ex_client_token=None):
+        """
+        Create a new security groups.
+
+        :keyword ex_description: volume description
+        :type ex_description: ``unicode``
+
+        :keyword ex_client_token: a token generated by client to identify
+                                  each request.
+        :type ex_client_token: ``str``
+        """
+        params = {'Action': 'CreateSecurityGroup',
+                  'RegionId': self.region}
+
+        if ex_description:
+            params['Description'] = ex_description
+        if ex_client_token:
+            params['ClientToken'] = ex_client_token
+        return self.connection.request(self.path, params).object
+
     def ex_list_security_groups(self, ex_filters=None):
         """
         List security groups in the current region.


Mime
View raw message