Translate final nova calls to REST

Change-Id: I89e0e59ec1ed6a81843da61bd3fce49d57da7c17
This commit is contained in:
Monty Taylor 2017-06-18 12:50:24 -05:00
parent 56244f5410
commit 56524c16a8
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
3 changed files with 17 additions and 54 deletions

View File

@ -255,28 +255,3 @@ class RoleAssignmentList(task_manager.Task):
class RolesForUser(task_manager.Task): class RolesForUser(task_manager.Task):
def main(self, client): def main(self, client):
return client.keystone_client.roles.roles_for_user(**self.args) 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()

View File

@ -2047,7 +2047,7 @@ class OpenStackCloud(
:returns: Munch object with the limits :returns: Munch object with the limits
""" """
kwargs = {} params = {}
project_id = None project_id = None
error_msg = "Failed to get limits" error_msg = "Failed to get limits"
if name_or_id: if name_or_id:
@ -2056,14 +2056,11 @@ class OpenStackCloud(
if not proj: if not proj:
raise OpenStackCloudException("project does not exist") raise OpenStackCloudException("project does not exist")
project_id = proj.id project_id = proj.id
kwargs['tenant_id'] = project_id params['tenant_id'] = project_id
error_msg = "{msg} for the project: {project} ".format( error_msg = "{msg} for the project: {project} ".format(
msg=error_msg, project=name_or_id) msg=error_msg, project=name_or_id)
with _utils.shade_exceptions(error_msg): limits = self._compute_client.get('/limits', params=params)
# 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))
return self._normalize_compute_limits(limits, project_id=project_id) return self._normalize_compute_limits(limits, project_id=project_id)

View File

@ -15,7 +15,6 @@ import iso8601
import jsonpatch import jsonpatch
from ironicclient import exceptions as ironic_exceptions from ironicclient import exceptions as ironic_exceptions
from novaclient import exceptions as nova_exceptions
from shade.exc import * # noqa from shade.exc import * # noqa
from shade import meta from shade import meta
@ -2075,13 +2074,11 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
# volume_quotas = {key: val for key, val in kwargs.items() # volume_quotas = {key: val for key, val in kwargs.items()
# if key in quota.VOLUME_QUOTAS} # if key in quota.VOLUME_QUOTAS}
try: kwargs['force'] = True
self.manager.submit_task( self._compute_client.put(
_tasks.NovaQuotasSet(tenant_id=proj.id, '/os-quota-sets/{project}'.format(project=proj.id),
force=True, json={'quota_set': kwargs},
**kwargs)) error_message="No valid quota or resource")
except nova_exceptions.BadRequest:
raise OpenStackCloudException("No valid quota or resource")
def get_compute_quotas(self, name_or_id): def get_compute_quotas(self, name_or_id):
""" Get quota for a project """ Get quota for a project
@ -2094,11 +2091,8 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
proj = self.get_project(name_or_id) proj = self.get_project(name_or_id)
if not proj: if not proj:
raise OpenStackCloudException("project does not exist") raise OpenStackCloudException("project does not exist")
try: return self._compute_client.get(
return self.manager.submit_task( '/os-quota-sets/{project}'.format(project=proj.id))
_tasks.NovaQuotasGet(tenant_id=proj.id))
except nova_exceptions.BadRequest:
raise OpenStackCloudException("nova client call failed")
def delete_compute_quotas(self, name_or_id): def delete_compute_quotas(self, name_or_id):
""" Delete quota for a project """ Delete quota for a project
@ -2112,11 +2106,8 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
proj = self.get_project(name_or_id) proj = self.get_project(name_or_id)
if not proj: if not proj:
raise OpenStackCloudException("project does not exist") raise OpenStackCloudException("project does not exist")
try: return self._compute_client.delete(
return self.manager.submit_task( '/os-quota-sets/{project}'.format(project=proj.id))
_tasks.NovaQuotasDelete(tenant_id=proj.id))
except nova_exceptions.BadRequest:
raise OpenStackCloudException("nova client call failed")
def get_compute_usage(self, name_or_id, start=None, end=None): def get_compute_usage(self, name_or_id, start=None, end=None):
""" Get usage for a specific project """ Get usage for a specific project
@ -2173,11 +2164,11 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
raise OpenStackCloudException("project does not exist: {}".format( raise OpenStackCloudException("project does not exist: {}".format(
name=proj.id)) name=proj.id))
with _utils.shade_exceptions( usage = self._compute_client.get(
"Unable to get resources usage for project: {name}".format( '/os-simple-tenant-usage/{project}'.format(project=proj.id),
name=proj.id)): params=dict(start=start.isoformat(), end=end.isoformat()),
usage = self.manager.submit_task( error_message="Unable to get usage for project: {name}".format(
_tasks.NovaUsageGet(tenant_id=proj.id, start=start, end=end)) name=proj.id))
return self._normalize_compute_usage(usage) return self._normalize_compute_usage(usage)