summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliyingjun <liyingjun1988@gmail.com>2013-07-30 10:18:59 +0800
committerliyingjun <liyingjun1988@gmail.com>2013-07-30 10:59:25 +0800
commit8b5dcee15eb82cd81d604be94e8f395627af4120 (patch)
tree8a55623529b4dbaf50d4394eea1105f0f7eae659
parent5fe9408d2e53ac24a578d0ed568a4cede303fe58 (diff)
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
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Vish Ishaya <vishvananda@gmail.com> Approved+1: Yun Mao <yunmao@gmail.com> Code-Review+2: Yun Mao <yunmao@gmail.com> Submitted-by: Jenkins Submitted-at: Tue, 30 Jul 2013 17:40:58 +0000 Reviewed-on: https://review.openstack.org/39200 Project: openstack/python-novaclient Branch: refs/heads/master
-rw-r--r--novaclient/tests/v1_1/test_quotas.py22
-rw-r--r--novaclient/tests/v1_1/test_shell.py24
-rw-r--r--novaclient/v1_1/quotas.py25
-rw-r--r--novaclient/v1_1/shell.py29
4 files changed, 87 insertions, 13 deletions
diff --git a/novaclient/tests/v1_1/test_quotas.py b/novaclient/tests/v1_1/test_quotas.py
index ce1c038..b545e6b 100644
--- a/novaclient/tests/v1_1/test_quotas.py
+++ b/novaclient/tests/v1_1/test_quotas.py
@@ -26,6 +26,13 @@ class QuotaSetsTest(utils.TestCase):
26 cs.quotas.get(tenant_id) 26 cs.quotas.get(tenant_id)
27 cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id) 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 def test_tenant_quotas_defaults(self): 36 def test_tenant_quotas_defaults(self):
30 tenant_id = '97f4c221bff44578b0300df4ef119353' 37 tenant_id = '97f4c221bff44578b0300df4ef119353'
31 cs.quotas.defaults(tenant_id) 38 cs.quotas.defaults(tenant_id)
@@ -37,6 +44,14 @@ class QuotaSetsTest(utils.TestCase):
37 cs.assert_called('PUT', 44 cs.assert_called('PUT',
38 '/os-quota-sets/97f4c221bff44578b0300df4ef119353') 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 def test_force_update_quota(self): 55 def test_force_update_quota(self):
41 q = cs.quotas.get('97f4c221bff44578b0300df4ef119353') 56 q = cs.quotas.get('97f4c221bff44578b0300df4ef119353')
42 q.update(cores=2, force=True) 57 q.update(cores=2, force=True)
@@ -59,3 +74,10 @@ class QuotaSetsTest(utils.TestCase):
59 tenant_id = 'test' 74 tenant_id = 'test'
60 cs.quotas.delete(tenant_id) 75 cs.quotas.delete(tenant_id)
61 cs.assert_called('DELETE', '/os-quota-sets/%s' % tenant_id) 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)
diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py
index 1ca22c6..727a1f1 100644
--- a/novaclient/tests/v1_1/test_shell.py
+++ b/novaclient/tests/v1_1/test_shell.py
@@ -1213,6 +1213,12 @@ class ShellTest(utils.TestCase):
1213 self.assert_called('GET', 1213 self.assert_called('GET',
1214 '/os-quota-sets/97f4c221bff44578b0300df4ef119353') 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 def test_quota_show_no_tenant(self): 1222 def test_quota_show_no_tenant(self):
1217 self.run_command('quota-show') 1223 self.run_command('quota-show')
1218 self.assert_called('GET', '/os-quota-sets/tenant_id') 1224 self.assert_called('GET', '/os-quota-sets/tenant_id')
@@ -1237,6 +1243,17 @@ class ShellTest(utils.TestCase):
1237 {'quota_set': {'instances': 5, 1243 {'quota_set': {'instances': 5,
1238 'tenant_id': '97f4c221bff44578b0300df4ef119353'}}) 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 def test_quota_force_update(self): 1257 def test_quota_force_update(self):
1241 self.run_command( 1258 self.run_command(
1242 'quota-update 97f4c221bff44578b0300df4ef119353' 1259 'quota-update 97f4c221bff44578b0300df4ef119353'
@@ -1262,6 +1279,13 @@ class ShellTest(utils.TestCase):
1262 self.assert_called('DELETE', 1279 self.assert_called('DELETE',
1263 '/os-quota-sets/97f4c221bff44578b0300df4ef119353') 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 def test_quota_class_show(self): 1289 def test_quota_class_show(self):
1266 self.run_command('quota-class-show test') 1290 self.run_command('quota-class-show test')
1267 self.assert_called('GET', '/os-quota-class-sets/test') 1291 self.assert_called('GET', '/os-quota-class-sets/test')
diff --git a/novaclient/v1_1/quotas.py b/novaclient/v1_1/quotas.py
index e174c6f..7c7ce54 100644
--- a/novaclient/v1_1/quotas.py
+++ b/novaclient/v1_1/quotas.py
@@ -31,17 +31,22 @@ class QuotaSet(base.Resource):
31class QuotaSetManager(base.Manager): 31class QuotaSetManager(base.Manager):
32 resource_class = QuotaSet 32 resource_class = QuotaSet
33 33
34 def get(self, tenant_id): 34 def get(self, tenant_id, user_id=None):
35 if hasattr(tenant_id, 'tenant_id'): 35 if hasattr(tenant_id, 'tenant_id'):
36 tenant_id = tenant_id.tenant_id 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 def update(self, tenant_id, metadata_items=None, 43 def update(self, tenant_id, metadata_items=None,
40 injected_file_content_bytes=None, injected_file_path_bytes=None, 44 injected_file_content_bytes=None, injected_file_path_bytes=None,
41 volumes=None, gigabytes=None, 45 volumes=None, gigabytes=None,
42 ram=None, floating_ips=None, fixed_ips=None, instances=None, 46 ram=None, floating_ips=None, fixed_ips=None, instances=None,
43 injected_files=None, cores=None, key_pairs=None, 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 body = {'quota_set': { 51 body = {'quota_set': {
47 'tenant_id': tenant_id, 52 'tenant_id': tenant_id,
@@ -65,11 +70,19 @@ class QuotaSetManager(base.Manager):
65 if body['quota_set'][key] is None: 70 if body['quota_set'][key] is None:
66 body['quota_set'].pop(key) 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 def defaults(self, tenant_id): 79 def defaults(self, tenant_id):
71 return self._get('/os-quota-sets/%s/defaults' % tenant_id, 80 return self._get('/os-quota-sets/%s/defaults' % tenant_id,
72 'quota_set') 81 'quota_set')
73 82
74 def delete(self, tenant_id): 83 def delete(self, tenant_id, user_id=None):
75 self._delete("/os-quota-sets/%s" % tenant_id) 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)
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index 7358a87..01ddadd 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -2895,8 +2895,10 @@ def _quota_update(manager, identifier, args):
2895 # default value of force is None to make sure this client 2895 # default value of force is None to make sure this client
2896 # will be compatibile with old nova server 2896 # will be compatibile with old nova server
2897 force_update = getattr(args, 'force', None) 2897 force_update = getattr(args, 'force', None)
2898 user_id = getattr(args, 'user', None)
2898 if isinstance(manager, quotas.QuotaSetManager): 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 else: 2902 else:
2901 manager.update(identifier, **updates) 2903 manager.update(identifier, **updates)
2902 2904
@@ -2905,13 +2907,17 @@ def _quota_update(manager, identifier, args):
2905 metavar='<tenant-id>', 2907 metavar='<tenant-id>',
2906 default=None, 2908 default=None,
2907 help='ID of tenant to list the quotas for.') 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.')
2908def do_quota_show(cs, args): 2914def do_quota_show(cs, args):
2909 """List the quotas for a tenant.""" 2915 """List the quotas for a tenant/user."""
2910 2916
2911 if not args.tenant: 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 else: 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@utils.arg('--tenant', 2923@utils.arg('--tenant',
@@ -2930,6 +2936,10 @@ def do_quota_defaults(cs, args):
2930@utils.arg('tenant', 2936@utils.arg('tenant',
2931 metavar='<tenant-id>', 2937 metavar='<tenant-id>',
2932 help='ID of tenant to set the quotas for.') 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@utils.arg('--instances', 2943@utils.arg('--instances',
2934 metavar='<instances>', 2944 metavar='<instances>',
2935 type=int, default=None, 2945 type=int, default=None,
@@ -3014,7 +3024,7 @@ def do_quota_defaults(cs, args):
3014 help='Whether force update the quota even if the already used' 3024 help='Whether force update the quota even if the already used'
3015 ' and reserved exceeds the new quota') 3025 ' and reserved exceeds the new quota')
3016def do_quota_update(cs, args): 3026def do_quota_update(cs, args):
3017 """Update the quotas for a tenant.""" 3027 """Update the quotas for a tenant/user."""
3018 3028
3019 _quota_update(cs.quotas, args.tenant, args) 3029 _quota_update(cs.quotas, args.tenant, args)
3020 3030
@@ -3022,10 +3032,15 @@ def do_quota_update(cs, args):
3022@utils.arg('--tenant', 3032@utils.arg('--tenant',
3023 metavar='<tenant-id>', 3033 metavar='<tenant-id>',
3024 help='ID of tenant to delete quota for.') 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.')
3025def do_quota_delete(cs, args): 3038def 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@utils.arg('class_name', 3046@utils.arg('class_name',