Browse Source

Add user quota client API support

    Implements blueprint user-quota-related-client-api

    This patch adds user arguments to the following subcommands:
        * quota-show
        * quota-update
        * quota-delete

Change-Id: I6556de366a758f7550e9b26357f231666caae419
tags/2.14.0
liyingjun 5 years ago
parent
commit
8b5dcee15e

+ 22
- 0
novaclient/tests/v1_1/test_quotas.py View File

@@ -26,6 +26,13 @@ class QuotaSetsTest(utils.TestCase):
26 26
         cs.quotas.get(tenant_id)
27 27
         cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id)
28 28
 
29
+    def test_user_quotas_get(self):
30
+        tenant_id = 'test'
31
+        user_id = 'fake_user'
32
+        cs.quotas.get(tenant_id, user_id=user_id)
33
+        url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
34
+        cs.assert_called('GET', url)
35
+
29 36
     def test_tenant_quotas_defaults(self):
30 37
         tenant_id = '97f4c221bff44578b0300df4ef119353'
31 38
         cs.quotas.defaults(tenant_id)
@@ -37,6 +44,14 @@ class QuotaSetsTest(utils.TestCase):
37 44
         cs.assert_called('PUT',
38 45
                    '/os-quota-sets/97f4c221bff44578b0300df4ef119353')
39 46
 
47
+    def test_update_user_quota(self):
48
+        tenant_id = '97f4c221bff44578b0300df4ef119353'
49
+        user_id = 'fake_user'
50
+        q = cs.quotas.get(tenant_id)
51
+        q.update(volumes=2, user_id=user_id)
52
+        url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
53
+        cs.assert_called('PUT', url)
54
+
40 55
     def test_force_update_quota(self):
41 56
         q = cs.quotas.get('97f4c221bff44578b0300df4ef119353')
42 57
         q.update(cores=2, force=True)
@@ -59,3 +74,10 @@ class QuotaSetsTest(utils.TestCase):
59 74
         tenant_id = 'test'
60 75
         cs.quotas.delete(tenant_id)
61 76
         cs.assert_called('DELETE', '/os-quota-sets/%s' % tenant_id)
77
+
78
+    def test_user_quotas_delete(self):
79
+        tenant_id = 'test'
80
+        user_id = 'fake_user'
81
+        cs.quotas.delete(tenant_id, user_id=user_id)
82
+        url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
83
+        cs.assert_called('DELETE', url)

+ 24
- 0
novaclient/tests/v1_1/test_shell.py View File

@@ -1213,6 +1213,12 @@ class ShellTest(utils.TestCase):
1213 1213
         self.assert_called('GET',
1214 1214
                 '/os-quota-sets/97f4c221bff44578b0300df4ef119353')
1215 1215
 
1216
+    def test_user_quota_show(self):
1217
+        self.run_command('quota-show --tenant '
1218
+                '97f4c221bff44578b0300df4ef119353 --user u1')
1219
+        self.assert_called('GET',
1220
+                '/os-quota-sets/97f4c221bff44578b0300df4ef119353?user_id=u1')
1221
+
1216 1222
     def test_quota_show_no_tenant(self):
1217 1223
         self.run_command('quota-show')
1218 1224
         self.assert_called('GET', '/os-quota-sets/tenant_id')
@@ -1237,6 +1243,17 @@ class ShellTest(utils.TestCase):
1237 1243
             {'quota_set': {'instances': 5,
1238 1244
                            'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1239 1245
 
1246
+    def test_user_quota_update(self):
1247
+        self.run_command(
1248
+            'quota-update 97f4c221bff44578b0300df4ef119353'
1249
+            ' --user=u1'
1250
+            ' --instances=5')
1251
+        self.assert_called(
1252
+            'PUT',
1253
+            '/os-quota-sets/97f4c221bff44578b0300df4ef119353?user_id=u1',
1254
+            {'quota_set': {'instances': 5,
1255
+                           'tenant_id': '97f4c221bff44578b0300df4ef119353'}})
1256
+
1240 1257
     def test_quota_force_update(self):
1241 1258
         self.run_command(
1242 1259
             'quota-update 97f4c221bff44578b0300df4ef119353'
@@ -1262,6 +1279,13 @@ class ShellTest(utils.TestCase):
1262 1279
         self.assert_called('DELETE',
1263 1280
                            '/os-quota-sets/97f4c221bff44578b0300df4ef119353')
1264 1281
 
1282
+    def test_user_quota_delete(self):
1283
+        self.run_command('quota-delete --tenant '
1284
+                         '97f4c221bff44578b0300df4ef119353 '
1285
+                         '--user u1')
1286
+        self.assert_called('DELETE',
1287
+                '/os-quota-sets/97f4c221bff44578b0300df4ef119353?user_id=u1')
1288
+
1265 1289
     def test_quota_class_show(self):
1266 1290
         self.run_command('quota-class-show test')
1267 1291
         self.assert_called('GET', '/os-quota-class-sets/test')

+ 19
- 6
novaclient/v1_1/quotas.py View File

@@ -31,17 +31,22 @@ class QuotaSet(base.Resource):
31 31
 class QuotaSetManager(base.Manager):
32 32
     resource_class = QuotaSet
33 33
 
34
-    def get(self, tenant_id):
34
+    def get(self, tenant_id, user_id=None):
35 35
         if hasattr(tenant_id, 'tenant_id'):
36 36
             tenant_id = tenant_id.tenant_id
37
-        return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
37
+        if user_id:
38
+            url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
39
+        else:
40
+            url = '/os-quota-sets/%s' % tenant_id
41
+        return self._get(url, "quota_set")
38 42
 
39 43
     def update(self, tenant_id, metadata_items=None,
40 44
                injected_file_content_bytes=None, injected_file_path_bytes=None,
41 45
                volumes=None, gigabytes=None,
42 46
                ram=None, floating_ips=None, fixed_ips=None, instances=None,
43 47
                injected_files=None, cores=None, key_pairs=None,
44
-               security_groups=None, security_group_rules=None, force=None):
48
+               security_groups=None, security_group_rules=None, force=None,
49
+               user_id=None):
45 50
 
46 51
         body = {'quota_set': {
47 52
                 'tenant_id': tenant_id,
@@ -65,11 +70,19 @@ class QuotaSetManager(base.Manager):
65 70
             if body['quota_set'][key] is None:
66 71
                 body['quota_set'].pop(key)
67 72
 
68
-        return self._update('/os-quota-sets/%s' % tenant_id, body, 'quota_set')
73
+        if user_id:
74
+            url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
75
+        else:
76
+            url = '/os-quota-sets/%s' % tenant_id
77
+        return self._update(url, body, 'quota_set')
69 78
 
70 79
     def defaults(self, tenant_id):
71 80
         return self._get('/os-quota-sets/%s/defaults' % tenant_id,
72 81
                          'quota_set')
73 82
 
74
-    def delete(self, tenant_id):
75
-        self._delete("/os-quota-sets/%s" % tenant_id)
83
+    def delete(self, tenant_id, user_id=None):
84
+        if user_id:
85
+            url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
86
+        else:
87
+            url = '/os-quota-sets/%s' % tenant_id
88
+        self._delete(url)

+ 22
- 7
novaclient/v1_1/shell.py View File

@@ -2895,8 +2895,10 @@ def _quota_update(manager, identifier, args):
2895 2895
         # default value of force is None to make sure this client
2896 2896
         # will be compatibile with old nova server
2897 2897
         force_update = getattr(args, 'force', None)
2898
+        user_id = getattr(args, 'user', None)
2898 2899
         if isinstance(manager, quotas.QuotaSetManager):
2899
-            manager.update(identifier, force=force_update, **updates)
2900
+            manager.update(identifier, force=force_update, user_id=user_id,
2901
+                           **updates)
2900 2902
         else:
2901 2903
             manager.update(identifier, **updates)
2902 2904
 
@@ -2905,13 +2907,17 @@ def _quota_update(manager, identifier, args):
2905 2907
     metavar='<tenant-id>',
2906 2908
     default=None,
2907 2909
     help='ID of tenant to list the quotas for.')
2910
+@utils.arg('--user',
2911
+    metavar='<user-id>',
2912
+    default=None,
2913
+    help='ID of user to list the quotas for.')
2908 2914
 def do_quota_show(cs, args):
2909
-    """List the quotas for a tenant."""
2915
+    """List the quotas for a tenant/user."""
2910 2916
 
2911 2917
     if not args.tenant:
2912
-        _quota_show(cs.quotas.get(cs.client.tenant_id))
2918
+        _quota_show(cs.quotas.get(cs.client.tenant_id, user_id=args.user))
2913 2919
     else:
2914
-        _quota_show(cs.quotas.get(args.tenant))
2920
+        _quota_show(cs.quotas.get(args.tenant, user_id=args.user))
2915 2921
 
2916 2922
 
2917 2923
 @utils.arg('--tenant',
@@ -2930,6 +2936,10 @@ def do_quota_defaults(cs, args):
2930 2936
 @utils.arg('tenant',
2931 2937
     metavar='<tenant-id>',
2932 2938
     help='ID of tenant to set the quotas for.')
2939
+@utils.arg('--user',
2940
+           metavar='<user-id>',
2941
+           default=None,
2942
+           help='ID of user to set the quotas for.')
2933 2943
 @utils.arg('--instances',
2934 2944
            metavar='<instances>',
2935 2945
            type=int, default=None,
@@ -3014,7 +3024,7 @@ def do_quota_defaults(cs, args):
3014 3024
     help='Whether force update the quota even if the already used'
3015 3025
             ' and reserved exceeds the new quota')
3016 3026
 def do_quota_update(cs, args):
3017
-    """Update the quotas for a tenant."""
3027
+    """Update the quotas for a tenant/user."""
3018 3028
 
3019 3029
     _quota_update(cs.quotas, args.tenant, args)
3020 3030
 
@@ -3022,10 +3032,15 @@ def do_quota_update(cs, args):
3022 3032
 @utils.arg('--tenant',
3023 3033
            metavar='<tenant-id>',
3024 3034
            help='ID of tenant to delete quota for.')
3035
+@utils.arg('--user',
3036
+           metavar='<user-id>',
3037
+           help='ID of user to delete quota for.')
3025 3038
 def do_quota_delete(cs, args):
3026
-    """Delete quota for a tenant so their quota will revert back to default."""
3039
+    """Delete quota for a tenant/user so their quota will Revert
3040
+       back to default.
3041
+    """
3027 3042
 
3028
-    cs.quotas.delete(args.tenant)
3043
+    cs.quotas.delete(args.tenant, user_id=args.user)
3029 3044
 
3030 3045
 
3031 3046
 @utils.arg('class_name',

Loading…
Cancel
Save