From 56524c16a82f0b75cb9e576eb74982d8b19fb105 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 18 Jun 2017 12:50:24 -0500 Subject: [PATCH] Translate final nova calls to REST Change-Id: I89e0e59ec1ed6a81843da61bd3fce49d57da7c17 --- shade/_tasks.py | 25 ------------------------- shade/openstackcloud.py | 9 +++------ shade/operatorcloud.py | 37 ++++++++++++++----------------------- 3 files changed, 17 insertions(+), 54 deletions(-) diff --git a/shade/_tasks.py b/shade/_tasks.py index 7b3d53f4f..c944347a4 100644 --- a/shade/_tasks.py +++ b/shade/_tasks.py @@ -255,28 +255,3 @@ class RoleAssignmentList(task_manager.Task): class RolesForUser(task_manager.Task): def main(self, client): return client.keystone_client.roles.roles_for_user(**self.args) - - -class NovaQuotasSet(task_manager.Task): - def main(self, client): - return client.nova_client.quotas.update(**self.args) - - -class NovaQuotasGet(task_manager.Task): - def main(self, client): - return client.nova_client.quotas.get(**self.args) - - -class NovaQuotasDelete(task_manager.Task): - def main(self, client): - return client.nova_client.quotas.delete(**self.args) - - -class NovaUsageGet(task_manager.Task): - def main(self, client): - return client.nova_client.usage.get(**self.args) - - -class NovaLimitsGet(task_manager.Task): - def main(self, client): - return client.nova_client.limits.get(**self.args).to_dict() diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index e847236fa..12bd1784d 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -2047,7 +2047,7 @@ class OpenStackCloud( :returns: Munch object with the limits """ - kwargs = {} + params = {} project_id = None error_msg = "Failed to get limits" if name_or_id: @@ -2056,14 +2056,11 @@ class OpenStackCloud( if not proj: raise OpenStackCloudException("project does not exist") project_id = proj.id - kwargs['tenant_id'] = project_id + params['tenant_id'] = project_id error_msg = "{msg} for the project: {project} ".format( msg=error_msg, project=name_or_id) - with _utils.shade_exceptions(error_msg): - # TODO(mordred) Before we convert this to REST, we need to add - # in support for running calls with a different project context - limits = self.manager.submit_task(_tasks.NovaLimitsGet(**kwargs)) + limits = self._compute_client.get('/limits', params=params) return self._normalize_compute_limits(limits, project_id=project_id) diff --git a/shade/operatorcloud.py b/shade/operatorcloud.py index 3b039b8d7..2ded0fb07 100644 --- a/shade/operatorcloud.py +++ b/shade/operatorcloud.py @@ -15,7 +15,6 @@ import iso8601 import jsonpatch from ironicclient import exceptions as ironic_exceptions -from novaclient import exceptions as nova_exceptions from shade.exc import * # noqa from shade import meta @@ -2075,13 +2074,11 @@ class OperatorCloud(openstackcloud.OpenStackCloud): # volume_quotas = {key: val for key, val in kwargs.items() # if key in quota.VOLUME_QUOTAS} - try: - self.manager.submit_task( - _tasks.NovaQuotasSet(tenant_id=proj.id, - force=True, - **kwargs)) - except nova_exceptions.BadRequest: - raise OpenStackCloudException("No valid quota or resource") + kwargs['force'] = True + self._compute_client.put( + '/os-quota-sets/{project}'.format(project=proj.id), + json={'quota_set': kwargs}, + error_message="No valid quota or resource") def get_compute_quotas(self, name_or_id): """ Get quota for a project @@ -2094,11 +2091,8 @@ class OperatorCloud(openstackcloud.OpenStackCloud): proj = self.get_project(name_or_id) if not proj: raise OpenStackCloudException("project does not exist") - try: - return self.manager.submit_task( - _tasks.NovaQuotasGet(tenant_id=proj.id)) - except nova_exceptions.BadRequest: - raise OpenStackCloudException("nova client call failed") + return self._compute_client.get( + '/os-quota-sets/{project}'.format(project=proj.id)) def delete_compute_quotas(self, name_or_id): """ Delete quota for a project @@ -2112,11 +2106,8 @@ class OperatorCloud(openstackcloud.OpenStackCloud): proj = self.get_project(name_or_id) if not proj: raise OpenStackCloudException("project does not exist") - try: - return self.manager.submit_task( - _tasks.NovaQuotasDelete(tenant_id=proj.id)) - except nova_exceptions.BadRequest: - raise OpenStackCloudException("nova client call failed") + return self._compute_client.delete( + '/os-quota-sets/{project}'.format(project=proj.id)) def get_compute_usage(self, name_or_id, start=None, end=None): """ Get usage for a specific project @@ -2173,11 +2164,11 @@ class OperatorCloud(openstackcloud.OpenStackCloud): raise OpenStackCloudException("project does not exist: {}".format( name=proj.id)) - with _utils.shade_exceptions( - "Unable to get resources usage for project: {name}".format( - name=proj.id)): - usage = self.manager.submit_task( - _tasks.NovaUsageGet(tenant_id=proj.id, start=start, end=end)) + usage = self._compute_client.get( + '/os-simple-tenant-usage/{project}'.format(project=proj.id), + params=dict(start=start.isoformat(), end=end.isoformat()), + error_message="Unable to get usage for project: {name}".format( + name=proj.id)) return self._normalize_compute_usage(usage)