Move nova flavor interactions to REST

One REST call is removed because python-novaclient made an extra get
that we do not need to make.

Change-Id: Idfc72a0f353c248e5749aea926031e70dcdf4f94
This commit is contained in:
Monty Taylor 2017-01-31 11:33:52 -06:00
parent 7d982af93e
commit 28fc6b02fa
6 changed files with 34 additions and 66 deletions

View File

@ -0,0 +1,5 @@
---
upgrade:
- Nova flavor operations are now handled via REST calls
instead of via novaclient. There should be no noticable
difference.

View File

@ -82,45 +82,6 @@ class ProjectUpdate(task_manager.Task):
return client._project_manager.update(**self.args)
class FlavorList(task_manager.Task):
def main(self, client):
return client.nova_client.flavors.list(**self.args)
class FlavorCreate(task_manager.Task):
def main(self, client):
return client.nova_client.flavors.create(**self.args)
class FlavorDelete(task_manager.Task):
def main(self, client):
return client.nova_client.flavors.delete(**self.args)
class FlavorGet(task_manager.Task):
def main(self, client):
return client.nova_client.flavors.get(**self.args)
class FlavorListAccess(task_manager.Task):
def main(self, client):
return client.nova_client.flavor_access.list(**self.args)
class FlavorAddAccess(task_manager.Task):
def main(self, client):
return client.nova_client.flavor_access.add_tenant_access(
**self.args
)
class FlavorRemoveAccess(task_manager.Task):
def main(self, client):
return client.nova_client.flavor_access.remove_tenant_access(
**self.args
)
class ServerList(task_manager.Task):
def main(self, client):
return client.nova_client.servers.list(**self.args)

View File

@ -1745,8 +1745,8 @@ class OpenStackCloud(_normalize.Normalizer):
"""
with _utils.shade_exceptions("Error fetching flavor list"):
flavors = self._normalize_flavors(
self.manager.submit_task(
_tasks.FlavorList(is_public=None)))
self._compute_client.get(
'/flavors/detail', params=dict(is_public='None')))
with _utils.shade_exceptions("Error fetching flavor extra specs"):
for flavor in flavors:

View File

@ -1489,12 +1489,22 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
"""
with _utils.shade_exceptions("Failed to create flavor {name}".format(
name=name)):
flavor = self.manager.submit_task(
_tasks.FlavorCreate(name=name, ram=ram, vcpus=vcpus, disk=disk,
flavorid=flavorid, ephemeral=ephemeral,
swap=swap, rxtx_factor=rxtx_factor,
is_public=is_public)
)
payload = {
'disk': disk,
'OS-FLV-EXT-DATA:ephemeral': ephemeral,
'id': flavorid,
'os-flavor-access:is_public': is_public,
'name': name,
'ram': ram,
'rxtx_factor': rxtx_factor,
'swap': swap,
'vcpus': vcpus,
}
if flavorid == 'auto':
payload['id'] = None
flavor = self._compute_client.post(
'/flavors',
json=dict(flavor=payload))
return self._normalize_flavor(flavor)
@ -1515,7 +1525,8 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
with _utils.shade_exceptions("Unable to delete flavor {name}".format(
name=name_or_id)):
self.manager.submit_task(_tasks.FlavorDelete(flavor=flavor['id']))
self._compute_client.delete(
'/flavors/{id}'.format(id=flavor['id']))
return True
@ -1562,16 +1573,11 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
with _utils.shade_exceptions("Error trying to {action} access from "
"flavor ID {flavor}".format(
action=action, flavor=flavor_id)):
if action == 'add':
self.manager.submit_task(
_tasks.FlavorAddAccess(flavor=flavor_id,
tenant=project_id)
)
elif action == 'remove':
self.manager.submit_task(
_tasks.FlavorRemoveAccess(flavor=flavor_id,
tenant=project_id)
)
endpoint = '/flavors/{id}/action'.format(id=flavor_id)
access = {'tenant': project_id}
access_key = '{action}TenantAccess'.format(action=action)
self._compute_client.post(endpoint, json={access_key: access})
def add_flavor_access(self, flavor_id, project_id):
"""Grant access to a private flavor for a project/tenant.
@ -1605,9 +1611,8 @@ class OperatorCloud(openstackcloud.OpenStackCloud):
with _utils.shade_exceptions("Error trying to list access from "
"flavor ID {flavor}".format(
flavor=flavor_id)):
projects = self.manager.submit_task(
_tasks.FlavorListAccess(flavor=flavor_id)
)
projects = self._compute_client.get(
'/flavors/{id}/os-flavor-access'.format(id=flavor_id))
return _utils.normalize_flavor_accesses(projects)
def create_role(self, name):

View File

@ -321,3 +321,5 @@ class TestCreateServer(base.RequestsMockTestCase):
'server-name', 'image-id', 'vanilla',
nics=[{'net-id': 'some-network'}])
mock_image.assert_called_once()
self.assert_calls()

View File

@ -37,11 +37,6 @@ class TestFlavors(base.RequestsMockTestCase):
"id": None
}}))
self.register_uri(
'GET', '{endpoint}/flavors/{id}'.format(
endpoint=fakes.ENDPOINT, id=fakes.FLAVOR_ID),
json={'flavor': fakes.FAKE_FLAVOR})
self.op_cloud.create_flavor(
'vanilla', ram=65536, disk=1600, vcpus=24,
)