From 770a3c3ed8f3a922847842d8cf30779b99218575 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 15 Oct 2021 12:28:04 +0100 Subject: [PATCH] compute: Add support for migrations API Change Ideeca99a89c920a09cfc3799bbcc7e24046a5c43 added support for the server migrations API ('/servers/{id}/migrations'), which allowed interaction with individual server migration records. This change adds support for the migrations API ('/os-migrations'), which allows users to list all migrations. Change-Id: I681a5738c3ed359c2b3b26620c7fd3a51da3e302 Signed-off-by: Stephen Finucane --- doc/source/user/proxies/compute.rst | 7 ++ doc/source/user/resources/compute/index.rst | 1 + .../user/resources/compute/v2/migration.rst | 12 +++ openstack/compute/v2/_proxy.py | 11 +++ openstack/compute/v2/migration.py | 72 +++++++++++++++++ .../tests/unit/compute/v2/test_migration.py | 81 +++++++++++++++++++ openstack/tests/unit/compute/v2/test_proxy.py | 4 + .../add-migrations-946adf16674d4b2a.yaml | 5 ++ 8 files changed, 193 insertions(+) create mode 100644 doc/source/user/resources/compute/v2/migration.rst create mode 100644 openstack/compute/v2/migration.py create mode 100644 openstack/tests/unit/compute/v2/test_migration.py create mode 100644 releasenotes/notes/add-migrations-946adf16674d4b2a.yaml diff --git a/doc/source/user/proxies/compute.rst b/doc/source/user/proxies/compute.rst index fb9379802..ff9853375 100644 --- a/doc/source/user/proxies/compute.rst +++ b/doc/source/user/proxies/compute.rst @@ -165,3 +165,10 @@ Server Migration Operations :noindex: :members: abort_server_migration, force_complete_server_migration, get_server_migration, server_migrations + +Migration Operations +^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: openstack.compute.v2._proxy.Proxy + :noindex: + :members: migrations diff --git a/doc/source/user/resources/compute/index.rst b/doc/source/user/resources/compute/index.rst index aee022fdc..993cff52d 100644 --- a/doc/source/user/resources/compute/index.rst +++ b/doc/source/user/resources/compute/index.rst @@ -9,6 +9,7 @@ Compute Resources v2/image v2/keypair v2/limits + v2/migration v2/server v2/server_interface v2/server_migration diff --git a/doc/source/user/resources/compute/v2/migration.rst b/doc/source/user/resources/compute/v2/migration.rst new file mode 100644 index 000000000..ba02f3e17 --- /dev/null +++ b/doc/source/user/resources/compute/v2/migration.rst @@ -0,0 +1,12 @@ +openstack.compute.v2.migration +============================== + +.. automodule:: openstack.compute.v2.migration + +The Migration Class +------------------- + +The ``Migration`` class inherits from :class:`~openstack.resource.Resource`. + +.. autoclass:: openstack.compute.v2.migration.Migration + :members: diff --git a/openstack/compute/v2/_proxy.py b/openstack/compute/v2/_proxy.py index c0df32926..d812d8977 100644 --- a/openstack/compute/v2/_proxy.py +++ b/openstack/compute/v2/_proxy.py @@ -20,6 +20,7 @@ from openstack.compute.v2 import hypervisor as _hypervisor from openstack.compute.v2 import image as _image from openstack.compute.v2 import keypair as _keypair from openstack.compute.v2 import limits +from openstack.compute.v2 import migration as _migration from openstack.compute.v2 import quota_set as _quota_set from openstack.compute.v2 import server as _server from openstack.compute.v2 import server_diagnostics as _server_diagnostics @@ -1830,6 +1831,16 @@ class Proxy(proxy.Proxy): server_id=server_id, ) + # ========== Migrations ========== + + def migrations(self): + """Return a generator of migrations for all servers. + + :returns: A generator of Migration objects + :rtype: :class:`~openstack.compute.v2.migration.Migration` + """ + return self._list(_migration.Migration) + # ========== Server diagnostics ========== def get_server_diagnostics(self, server): diff --git a/openstack/compute/v2/migration.py b/openstack/compute/v2/migration.py new file mode 100644 index 000000000..5fc8c8f5c --- /dev/null +++ b/openstack/compute/v2/migration.py @@ -0,0 +1,72 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack import resource + + +class Migration(resource.Resource): + resources_key = 'migrations' + base_path = '/os-migrations' + + # capabilities + allow_list = True + + _query_mapping = resource.QueryParameters( + 'host', + 'status', + 'migration_type', + 'source_compute', + 'user_id', + 'project_id', + changes_since='changes-since', + changes_before='changes-before', + server_id='instance_uuid', + ) + + #: The date and time when the resource was created. + created_at = resource.Body('created_at') + #: The target compute of the migration. + dest_compute = resource.Body('dest_compute') + #: The target host of the migration. + dest_host = resource.Body('dest_host') + #: The target node of the migration. + dest_node = resource.Body('dest_node') + #: The type of the migration. One of 'migration', 'resize', + #: 'live-migration' or 'evacuation' + migration_type = resource.Body('migration_type') + #: The ID of the old flavor. This value corresponds to the ID of the flavor + #: in the database. This will be the same as new_flavor_id except for + #: resize operations. + new_flavor_id = resource.Body('new_instance_type_id') + #: The ID of the old flavor. This value corresponds to the ID of the flavor + #: in the database. + old_flavor_id = resource.Body('old_instance_type_id') + #: The ID of the project that initiated the server migration (since + #: microversion 2.80) + project_id = resource.Body('project_id') + #: The UUID of the server + server_id = resource.Body('instance_uuid') + #: The source compute of the migration. + source_compute = resource.Body('source_compute') + #: The source node of the migration. + source_node = resource.Body('source_node') + #: The current status of the migration. + status = resource.Body('status') + #: The date and time when the resource was last updated. + updated_at = resource.Body('updated_at') + #: The ID of the user that initiated the server migration (since + #: microversion 2.80) + user_id = resource.Body('user_id') + #: The UUID of the migration (since microversion 2.59) + uuid = resource.Body('uuid', alternate_id=True) + + _max_microversion = '2.80' diff --git a/openstack/tests/unit/compute/v2/test_migration.py b/openstack/tests/unit/compute/v2/test_migration.py new file mode 100644 index 000000000..ad4315767 --- /dev/null +++ b/openstack/tests/unit/compute/v2/test_migration.py @@ -0,0 +1,81 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstack.compute.v2 import migration +from openstack.tests.unit import base + +EXAMPLE = { + 'uuid': '42341d4b-346a-40d0-83c6-5f4f6892b650', + 'instance_uuid': '9128d044-7b61-403e-b766-7547076ff6c1', + 'user_id': '78348f0e-97ee-4d70-ad34-189692673ea2', + 'project_id': '9842f0f7-1229-4355-afe7-15ebdbb8c3d8', + 'created_at': '2016-06-23T14:42:02.000000', + 'updated_at': '2016-06-23T14:42:02.000000', + 'status': 'migrating', + 'source_compute': 'compute10', + 'source_node': 'node10', + 'dest_host': '5.6.7.8', + 'dest_compute': 'compute20', + 'dest_node': 'node20', + 'migration_type': 'resize', + 'old_instance_type_id': 5, + 'new_instance_type_id': 6, +} + + +class TestMigration(base.TestCase): + + def test_basic(self): + sot = migration.Migration() + self.assertIsNone(sot.resource_key) # we don't support fetch + self.assertEqual('migrations', sot.resources_key) + self.assertEqual('/os-migrations', sot.base_path) + self.assertFalse(sot.allow_create) + self.assertFalse(sot.allow_fetch) + self.assertFalse(sot.allow_commit) + self.assertFalse(sot.allow_delete) + self.assertTrue(sot.allow_list) + + self.assertDictEqual( + { + 'limit': 'limit', + 'marker': 'marker', + 'host': 'host', + 'status': 'status', + 'migration_type': 'migration_type', + 'source_compute': 'source_compute', + 'user_id': 'user_id', + 'project_id': 'project_id', + 'changes_since': 'changes-since', + 'changes_before': 'changes-before', + 'server_id': 'instance_uuid', + }, + sot._query_mapping._mapping, + ) + + def test_make_it(self): + sot = migration.Migration(**EXAMPLE) + self.assertEqual(EXAMPLE['uuid'], sot.id) + self.assertEqual(EXAMPLE['instance_uuid'], sot.server_id) + self.assertEqual(EXAMPLE['user_id'], sot.user_id) + self.assertEqual(EXAMPLE['project_id'], sot.project_id) + self.assertEqual(EXAMPLE['created_at'], sot.created_at) + self.assertEqual(EXAMPLE['updated_at'], sot.updated_at) + self.assertEqual(EXAMPLE['status'], sot.status) + self.assertEqual(EXAMPLE['source_compute'], sot.source_compute) + self.assertEqual(EXAMPLE['source_node'], sot.source_node) + self.assertEqual(EXAMPLE['dest_host'], sot.dest_host) + self.assertEqual(EXAMPLE['dest_compute'], sot.dest_compute) + self.assertEqual(EXAMPLE['dest_node'], sot.dest_node) + self.assertEqual(EXAMPLE['migration_type'], sot.migration_type) + self.assertEqual(EXAMPLE['old_instance_type_id'], sot.old_flavor_id) + self.assertEqual(EXAMPLE['new_instance_type_id'], sot.new_flavor_id) diff --git a/openstack/tests/unit/compute/v2/test_proxy.py b/openstack/tests/unit/compute/v2/test_proxy.py index 5ecfa9cd6..b8687690e 100644 --- a/openstack/tests/unit/compute/v2/test_proxy.py +++ b/openstack/tests/unit/compute/v2/test_proxy.py @@ -21,6 +21,7 @@ from openstack.compute.v2 import hypervisor from openstack.compute.v2 import image from openstack.compute.v2 import keypair from openstack.compute.v2 import limits +from openstack.compute.v2 import migration from openstack.compute.v2 import quota_set from openstack.compute.v2 import server from openstack.compute.v2 import server_group @@ -1052,6 +1053,9 @@ class TestCompute(TestComputeProxy): expected_kwargs={'server_id': 'server'}, ) + def test_migrations(self): + self.verify_list(self.proxy.migrations, migration.Migration) + def test_fetch_security_groups(self): self._verify( 'openstack.compute.v2.server.Server.fetch_security_groups', diff --git a/releasenotes/notes/add-migrations-946adf16674d4b2a.yaml b/releasenotes/notes/add-migrations-946adf16674d4b2a.yaml new file mode 100644 index 000000000..f199f91f2 --- /dev/null +++ b/releasenotes/notes/add-migrations-946adf16674d4b2a.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add support for the Compute service's migrations API, allowing users to + list all in-progress migrations for all servers.