From 28fc6b02faed384337b187a13e7dc7ce01e3b318 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 31 Jan 2017 11:33:52 -0600 Subject: [PATCH] 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 --- .../nova-flavor-to-rest-0a5757e35714a690.yaml | 5 +++ shade/_tasks.py | 39 ---------------- shade/openstackcloud.py | 4 +- shade/operatorcloud.py | 45 ++++++++++--------- shade/tests/unit/test_create_server.py | 2 + shade/tests/unit/test_flavors.py | 5 --- 6 files changed, 34 insertions(+), 66 deletions(-) create mode 100644 releasenotes/notes/nova-flavor-to-rest-0a5757e35714a690.yaml diff --git a/releasenotes/notes/nova-flavor-to-rest-0a5757e35714a690.yaml b/releasenotes/notes/nova-flavor-to-rest-0a5757e35714a690.yaml new file mode 100644 index 000000000..1e1f501c2 --- /dev/null +++ b/releasenotes/notes/nova-flavor-to-rest-0a5757e35714a690.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - Nova flavor operations are now handled via REST calls + instead of via novaclient. There should be no noticable + difference. diff --git a/shade/_tasks.py b/shade/_tasks.py index cfb13cc87..372c9eab7 100644 --- a/shade/_tasks.py +++ b/shade/_tasks.py @@ -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) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 87cf70656..6bac67d5f 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -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: diff --git a/shade/operatorcloud.py b/shade/operatorcloud.py index 0c59e80d7..301d34e14 100644 --- a/shade/operatorcloud.py +++ b/shade/operatorcloud.py @@ -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): diff --git a/shade/tests/unit/test_create_server.py b/shade/tests/unit/test_create_server.py index d51800a9d..5f3b018ff 100644 --- a/shade/tests/unit/test_create_server.py +++ b/shade/tests/unit/test_create_server.py @@ -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() diff --git a/shade/tests/unit/test_flavors.py b/shade/tests/unit/test_flavors.py index da06ca601..9881b231c 100644 --- a/shade/tests/unit/test_flavors.py +++ b/shade/tests/unit/test_flavors.py @@ -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, )