From 7107b5536e9ece347014ec88c5c5bb3e68050882 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Sat, 24 Oct 2015 12:08:35 +0800 Subject: [PATCH] Add "server stop" command to osc. There is no stop command in osc. Add it. Change-Id: Ia11a8f3b1245c884f7da442292009342d2ffde1e Implements: blueprint cmd-with-multi-servers --- doc/source/command-objects/server.rst | 15 +++++++++++++++ doc/source/commands.rst | 3 ++- openstackclient/compute/v2/server.py | 25 +++++++++++++++++++++++++ setup.cfg | 1 + 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index 4f0b836d58..3cb6598da4 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -610,6 +610,21 @@ Start server(s) Server(s) to start (name or ID) +server stop +----------- + +Stop server(s) + +.. program:: server stop +.. code:: bash + + os server stop + [ ...] + +.. describe:: + + Server(s) to stop (name or ID) + server suspend -------------- diff --git a/doc/source/commands.rst b/doc/source/commands.rst index d89e71935d..34a30c4e44 100644 --- a/doc/source/commands.rst +++ b/doc/source/commands.rst @@ -183,7 +183,8 @@ Those actions with an opposite action are noted in parens if applicable. * ``save`` - download an object locally * ``set`` (``unset``) - set a property on the object, formerly called metadata * ``show`` - display detailed information about the specific object -* ``start`` - start one or more servers +* ``start`` (``stop``) - start one or more servers +* ``stop`` (``start``) - stop one or more servers * ``suspend`` (``resume``) - stop a server and save to disk freeing memory * ``unlock`` (``lock``) - unlock a server * ``unpause`` (``pause``) - return a paused server to running state diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 2768951de6..e7dfbbef2a 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -1508,6 +1508,31 @@ class StartServer(command.Command): ).start() +class StopServer(command.Command): + """Stop server(s).""" + + log = logging.getLogger(__name__ + '.StopServer') + + def get_parser(self, prog_name): + parser = super(StopServer, self).get_parser(prog_name) + parser.add_argument( + 'server', + metavar='', + nargs="+", + help=_('Server(s) to stop (name or ID)'), + ) + return parser + + @utils.log_method(log) + def take_action(self, parsed_args): + compute_client = self.app.client_manager.compute + for server in parsed_args.server: + utils.find_resource( + compute_client.servers, + server, + ).stop() + + class SuspendServer(command.Command): """Suspend server""" diff --git a/setup.cfg b/setup.cfg index cfbc7c294b..d917f04210 100644 --- a/setup.cfg +++ b/setup.cfg @@ -134,6 +134,7 @@ openstack.compute.v2 = server_show = openstackclient.compute.v2.server:ShowServer server_ssh = openstackclient.compute.v2.server:SshServer server_start = openstackclient.compute.v2.server:StartServer + server_stop = openstackclient.compute.v2.server:StopServer server_suspend = openstackclient.compute.v2.server:SuspendServer server_unlock = openstackclient.compute.v2.server:UnlockServer server_unpause = openstackclient.compute.v2.server:UnpauseServer