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):
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()

View File

@ -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)

View File

@ -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)