diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 151c6783c7..d4edf8c535 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -1576,7 +1576,7 @@ class RemoveServerVolume(command.Command): ) -class RescueServer(command.ShowOne): +class RescueServer(command.Command): _description = _("Put server in rescue mode") def get_parser(self, prog_name): @@ -1586,16 +1586,35 @@ class RescueServer(command.ShowOne): metavar='', help=_('Server (name or ID)'), ) + parser.add_argument( + '--image', + metavar='', + help=_('Image (name or ID) to use for the rescue mode.' + ' Defaults to the currently used one.'), + ) + parser.add_argument( + '--password', + metavar='', + help=_("Set the password on the rescued instance"), + ) return parser def take_action(self, parsed_args): - compute_client = self.app.client_manager.compute - _, body = utils.find_resource( + image_client = self.app.client_manager.image + + image = None + if parsed_args.image: + image = utils.find_resource( + image_client.images, + parsed_args.image, + ) + + utils.find_resource( compute_client.servers, parsed_args.server, - ).rescue() - return zip(*sorted(six.iteritems(body))) + ).rescue(image=image, + password=parsed_args.password) class ResizeServer(command.Command): diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py index b7a2599674..0b29fe5fbd 100644 --- a/openstackclient/tests/functional/compute/v2/test_server.py +++ b/openstackclient/tests/functional/compute/v2/test_server.py @@ -184,7 +184,18 @@ class ServerTests(common.ComputeTestCase): # rescue raw_output = self.openstack('server rescue ' + name) - self.assertNotEqual("", raw_output) + self.assertEqual("", raw_output) + self.wait_for_status(name, "RESCUE") + + # unrescue + raw_output = self.openstack('server unrescue ' + name) + self.assertEqual("", raw_output) + self.wait_for_status(name, "ACTIVE") + + # rescue with image + raw_output = self.openstack('server rescue --image ' + + self.image_name + ' ' + name) + self.assertEqual("", raw_output) self.wait_for_status(name, "RESCUE") # unrescue diff --git a/releasenotes/notes/bug-1703278-5e45a92e43552dec.yaml b/releasenotes/notes/bug-1703278-5e45a92e43552dec.yaml new file mode 100644 index 0000000000..c1a3552123 --- /dev/null +++ b/releasenotes/notes/bug-1703278-5e45a92e43552dec.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Add ``--image`` and ``--password`` options to the ``server rescue`` command. + [Bug `1703278 `_]