From ec51bdb8da319c5d3b75d6df0bdc16169995850e Mon Sep 17 00:00:00 2001 From: Goutham Pratapa Date: Thu, 19 Jan 2017 13:26:31 +0530 Subject: [PATCH] Remove "--resources" option for "quota delete". Python-kingbirdclient uses python requests and it cannot send body along with the curl-request. So removed the option of sending resources(body). Made Kingbird-client compatible with Keystone_v2 and Keystone_v3. Change-Id: I9d7c0055d747245f76d1cbd1213ff74cb11d1faf --- kingbirdclient/api/base.py | 4 ++-- kingbirdclient/api/v1/client.py | 4 +++- kingbirdclient/api/v1/quota_manager.py | 8 ++------ kingbirdclient/commands/v1/quota_manager.py | 19 ++++--------------- kingbirdclient/tests/v1/test_quota_manager.py | 2 +- 5 files changed, 12 insertions(+), 25 deletions(-) diff --git a/kingbirdclient/api/base.py b/kingbirdclient/api/base.py index e453e2a..1774f38 100644 --- a/kingbirdclient/api/base.py +++ b/kingbirdclient/api/base.py @@ -74,8 +74,8 @@ class ResourceManager(object): json_object['usage'][values])) return resource - def _delete(self, url, data=None): - resp = self.http_client.delete(url, data) + def _delete(self, url): + resp = self.http_client.delete(url) if resp.status_code != 200: self._raise_api_exception(resp) diff --git a/kingbirdclient/api/v1/client.py b/kingbirdclient/api/v1/client.py index f20a7ec..1fad5c9 100644 --- a/kingbirdclient/api/v1/client.py +++ b/kingbirdclient/api/v1/client.py @@ -122,10 +122,12 @@ def authenticate(kingbird_url=None, username=None, endpoint_type=endpoint_type ) + # For Keystone version 'V2.0' and other. + serv_endpoint = endpoint_type if keystone.version == 'v2.0' else 'url' if service_type in catalog: service = catalog.get(service_type) kingbird_url = service[0].get( - endpoint_type) if service else None + serv_endpoint) if service else None return kingbird_url, token, project_id, user_id diff --git a/kingbirdclient/api/v1/quota_manager.py b/kingbirdclient/api/v1/quota_manager.py index 1b661c3..adfea74 100644 --- a/kingbirdclient/api/v1/quota_manager.py +++ b/kingbirdclient/api/v1/quota_manager.py @@ -50,14 +50,10 @@ class quota_manager(base.ResourceManager): url = '/%s/os-quota-sets/%s' % (tenant, target_tenant_id) return self._update(url, data) - def delete_quota(self, target_tenant_id, resources=None): - data = dict() - if resources: - resources = resources.split(',') - data["quota_set"] = str(resources) + def delete_quota(self, target_tenant_id): tenant = self.http_client.project_id url = '/%s/os-quota-sets/%s' % (tenant, target_tenant_id) - return self._delete(url, data) + return self._delete(url) def sync_quota(self, target_tenant_id): tenant = self.http_client.project_id diff --git a/kingbirdclient/commands/v1/quota_manager.py b/kingbirdclient/commands/v1/quota_manager.py index f357777..808b321 100644 --- a/kingbirdclient/commands/v1/quota_manager.py +++ b/kingbirdclient/commands/v1/quota_manager.py @@ -296,28 +296,17 @@ class DeleteQuota(command.Command): help='ID of tenant to delete quotas.' ) - parser.add_argument( - '--resources', - help='resources to which quotas have to be deleted.' - '-- comma seperated values(csv)' - ) - return parser def take_action(self, parsed_args): kingbird_client = self.app.client_manager.sync_engine target_tenant = parsed_args.tenant - resources = parsed_args.resources try: kingbird_client.quota_manager.\ - delete_quota(target_tenant, resources) - if resources: - print("Request to delete %s for tenant %s has been accepted." % - (parsed_args.resources, parsed_args.tenant)) - else: - print("Request to delete quotas" - " for tenant %s has been accepted." % - (parsed_args.tenant)) + delete_quota(target_tenant) + print("Request to delete quotas" + " for tenant %s has been accepted." % + (parsed_args.tenant)) except Exception as e: print(e) error_msg = "Unable to delete quota for specified resource." diff --git a/kingbirdclient/tests/v1/test_quota_manager.py b/kingbirdclient/tests/v1/test_quota_manager.py index a8228bc..e3511f1 100644 --- a/kingbirdclient/tests/v1/test_quota_manager.py +++ b/kingbirdclient/tests/v1/test_quota_manager.py @@ -83,7 +83,7 @@ class TestCLIQuotaManagerV1(base.BaseCommandTest): def test_delete_quota(self): self.call(quota_cmd.DeleteQuota, app_args=[FAKE_TENANT]) self.client.quota_manager.delete_quota.\ - assert_called_once_with(FAKE_TENANT, None) + assert_called_once_with(FAKE_TENANT) def test_sync_quota(self): self.call(quota_cmd.SyncQuota, app_args=[FAKE_TENANT])