diff --git a/lower-constraints.txt b/lower-constraints.txt index 7993a18325..a84643caed 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -99,7 +99,7 @@ python-mimeparse==1.6.0 python-mistralclient==3.1.0 python-muranoclient==0.8.2 python-neutronclient==6.7.0 -python-novaclient==14.2.0 +python-novaclient==15.0.0 python-octaviaclient==1.3.0 python-rsdclient==0.1.0 python-saharaclient==1.4.0 diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 9ba918123e..538c9c4fa0 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -2811,12 +2811,32 @@ class UnshelveServer(command.Command): nargs='+', help=_('Server(s) to unshelve (name or ID)'), ) + parser.add_argument( + '--availability-zone', + default=None, + help=_('Name of the availability zone in which to unshelve a ' + 'SHELVED_OFFLOADED server (supported by ' + '--os-compute-api-version 2.77 or above)'), + ) return parser def take_action(self, parsed_args): compute_client = self.app.client_manager.compute + support_az = compute_client.api_version >= api_versions.APIVersion( + '2.77') + if not support_az and parsed_args.availability_zone: + msg = _("--os-compute-api-version 2.77 or greater is required " + "to support the '--availability-zone' option.") + raise exceptions.CommandError(msg) + for server in parsed_args.server: - utils.find_resource( - compute_client.servers, - server, - ).unshelve() + if support_az: + utils.find_resource( + compute_client.servers, + server + ).unshelve(availability_zone=parsed_args.availability_zone) + else: + utils.find_resource( + compute_client.servers, + server, + ).unshelve() diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 0793116af6..5c98188a76 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -109,6 +109,10 @@ class TestServer(compute_fakes.TestComputev2): version = self.app.client_manager.compute.api_version if version >= api_versions.APIVersion('2.73'): method.assert_called_with(reason=None) + elif method_name == 'unshelve': + version = self.app.client_manager.compute.api_version + if version >= api_versions.APIVersion('2.77'): + method.assert_called_with(availability_zone=None) else: method.assert_called_with() else: @@ -4777,6 +4781,56 @@ class TestServerUnshelve(TestServer): def test_unshelve_multi_servers(self): self.run_method_with_servers('unshelve', 3) + def test_unshelve_server_with_specified_az(self): + server = compute_fakes.FakeServer.create_one_server() + arglist = [ + server.id, + '--availability-zone', "foo-az", + ] + verifylist = [ + ('availability_zone', "foo-az"), + ('server', [server.id]) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + ex = self.assertRaises(exceptions.CommandError, + self.cmd.take_action, + parsed_args) + self.assertIn( + '--os-compute-api-version 2.77 or greater is required', str(ex)) + + +class TestServerUnshelveV277(TestServerUnshelve): + + def setUp(self): + super(TestServerUnshelveV277, self).setUp() + + self.server = compute_fakes.FakeServer.create_one_server( + methods=self.methods) + + # This is the return value for utils.find_resource() + self.servers_mock.get.return_value = self.server + + # Get the command object to test + self.cmd = server.UnshelveServer(self.app, None) + + def test_specified_az_to_unshelve_with_v277(self): + self.app.client_manager.compute.api_version = api_versions.APIVersion( + '2.77') + + arglist = [ + '--availability-zone', "foo-az", + self.server.id, + ] + verifylist = [ + ('availability_zone', "foo-az"), + ('server', [self.server.id]) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.servers_mock.get.assert_called_with(self.server.id) + self.server.unshelve.assert_called_with(availability_zone="foo-az") + class TestServerGeneral(TestServer): OLD = { diff --git a/releasenotes/notes/bp-support-specifying-az-when-restore-shelved-server-16e864223d51b50a.yaml b/releasenotes/notes/bp-support-specifying-az-when-restore-shelved-server-16e864223d51b50a.yaml new file mode 100644 index 0000000000..0e7dacbe17 --- /dev/null +++ b/releasenotes/notes/bp-support-specifying-az-when-restore-shelved-server-16e864223d51b50a.yaml @@ -0,0 +1,7 @@ +--- +features: + - Add ``--availability-zone`` option to ``server unshelve`` + command to enable users to specify an availability zone during + unshelve of a shelved offloaded server. Note that it requires + ``--os-compute-api-version 2.77`` or greater. + [Blueprint ` =3.15.3 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 python-glanceclient>=2.8.0 # Apache-2.0 python-keystoneclient>=3.17.0 # Apache-2.0 -python-novaclient>=14.2.0 # Apache-2.0 +python-novaclient>=15.0.0 # Apache-2.0 python-cinderclient>=3.3.0 # Apache-2.0