libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [1/4] git commit: Add enable_user and disable_user method to Identity API v3 class.
Date Fri, 15 Aug 2014 14:18:20 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 3f8fc51e9 -> 950f972c3


Add enable_user and disable_user method to Identity API v3 class.


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

Branch: refs/heads/trunk
Commit: 7557d7b332dbef6688ea167fde6cd2997f0e2ffa
Parents: 3f8fc51
Author: Tomaz Muraus <tomaz@apache.org>
Authored: Fri Aug 15 15:52:03 2014 +0200
Committer: Tomaz Muraus <tomaz@apache.org>
Committed: Fri Aug 15 15:52:03 2014 +0200

----------------------------------------------------------------------
 libcloud/common/openstack_identity.py           | 46 ++++++++++++++++++++
 libcloud/test/common/test_openstack_identity.py | 18 ++++++++
 2 files changed, 64 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/7557d7b3/libcloud/common/openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/common/openstack_identity.py b/libcloud/common/openstack_identity.py
index a3492f1..3363aac 100644
--- a/libcloud/common/openstack_identity.py
+++ b/libcloud/common/openstack_identity.py
@@ -1248,6 +1248,52 @@ class OpenStackIdentity_3_0_Connection(OpenStackIdentityConnection):
         user = self._to_user(data=response.object['user'])
         return user
 
+    def enable_user(self, user):
+        """
+        Enable user account.
+
+        Note: This operation appears to be idempotent.
+
+        :param user: User to enable.
+        :type user: :class:`.OpenStackIdentityUser`
+
+        :return: User account which has been enabled.
+        :rtype: :class:`.OpenStackIdentityUser`
+        """
+        data = {
+            'enabled': True
+        }
+        data = json.dumps({'user': data})
+        response = self.authenticated_request('/v3/users/%s' % (user.id),
+                                              data=data,
+                                              method='PATCH')
+
+        user = self._to_user(data=response.object['user'])
+        return user
+
+    def disable_user(self, user):
+        """
+        Disable user account.
+
+        Note: This operation appears to be idempotent.
+
+        :param user: User to disable.
+        :type user: :class:`.OpenStackIdentityUser`
+
+        :return: User account which has been disabled.
+        :rtype: :class:`.OpenStackIdentityUser`
+        """
+        data = {
+            'enabled': False
+        }
+        data = json.dumps({'user': data})
+        response = self.authenticated_request('/v3/users/%s' % (user.id),
+                                              data=data,
+                                              method='PATCH')
+
+        user = self._to_user(data=response.object['user'])
+        return user
+
     def _to_domains(self, data):
         result = []
         for item in data:

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7557d7b3/libcloud/test/common/test_openstack_identity.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_openstack_identity.py b/libcloud/test/common/test_openstack_identity.py
index 1c1320e..9ebd599 100644
--- a/libcloud/test/common/test_openstack_identity.py
+++ b/libcloud/test/common/test_openstack_identity.py
@@ -30,6 +30,7 @@ from libcloud.common.openstack_identity import get_class_for_auth_version
 from libcloud.common.openstack_identity import OpenStackIdentity_2_0_Connection
 from libcloud.common.openstack_identity import OpenStackServiceCatalog
 from libcloud.common.openstack_identity import OpenStackIdentity_3_0_Connection
+from libcloud.common.openstack_identity import OpenStackIdentityUser
 from libcloud.compute.drivers.openstack import OpenStack_1_0_NodeDriver
 
 from libcloud.test import unittest
@@ -342,6 +343,16 @@ class OpenStackIdentity_3_0_ConnectionTests(unittest.TestCase):
         self.assertEqual(user.id, 'c')
         self.assertEqual(user.name, 'test2')
 
+    def test_enable_user(self):
+        user = self.auth_instance.list_users()[0]
+        result = self.auth_instance.enable_user(user=user)
+        self.assertTrue(isinstance(result, OpenStackIdentityUser))
+
+    def test_disable_user(self):
+        user = self.auth_instance.list_users()[0]
+        result = self.auth_instance.disable_user(user=user)
+        self.assertTrue(isinstance(result, OpenStackIdentityUser))
+
     def test_grant_domain_role_to_user(self):
         domain = self.auth_instance.list_domains()[0]
         role = self.auth_instance.list_roles()[0]
@@ -543,6 +554,13 @@ class OpenStackIdentity_3_0_MockHttp(MockHttp):
                     httplib.responses[httplib.CREATED])
         raise NotImplementedError()
 
+    def _v3_users_a(self, method, url, body, headers):
+        if method == 'PATCH':
+            # enable / disable user
+            body = self.fixtures.load('v3_users_a.json')
+            return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK])
+        raise NotImplementedError()
+
     def _v3_roles(self, method, url, body, headers):
         if method == 'GET':
             body = self.fixtures.load('v3_roles.json')


Mime
View raw message