diff --git a/doc/source/command-objects/server.rst b/doc/source/command-objects/server.rst index fc27597125..d50ad37edd 100644 --- a/doc/source/command-objects/server.rst +++ b/doc/source/command-objects/server.rst @@ -168,6 +168,25 @@ Delete server(s) Server(s) to delete (name or ID) +server dump create +------------------ +Create a dump file in server(s) + +Trigger crash dump in server(s) with features like kdump in Linux. It will +create a dump file in the server(s) dumping the server(s)' memory, and also +crash the server(s). OSC sees the dump file (server dump) as a kind of +resource. + +.. program:: server dump create +.. code:: bash + + os server dump create + [ ...] + +.. describe:: + + Server(s) to create dump file (name or ID) + server list ----------- diff --git a/doc/source/commands.rst b/doc/source/commands.rst index 1c4f84b28b..bf5d7035a9 100644 --- a/doc/source/commands.rst +++ b/doc/source/commands.rst @@ -112,6 +112,7 @@ referring to both Compute and Volume quotas. * ``security group``: (**Compute**, **Network**) - groups of network access rules * ``security group rule``: (**Compute**, **Network**) - the individual rules that define protocol/IP/port access * ``server``: (**Compute**) virtual machine instance +* ``server dump``: (**Compute**) a dump file of a server created by features like kdump * ``server image``: (**Compute**) saved server disk image * ``service``: (**Identity**) a cloud service * ``service provider``: (**Identity**) a resource that consumes assertions from an ``identity provider`` diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index dd7bc470ba..4cb94822bd 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -542,6 +542,34 @@ class CreateServer(command.ShowOne): return zip(*sorted(six.iteritems(details))) +class CreateServerDump(command.Command): + """Create a dump file in server(s) + + Trigger crash dump in server(s) with features like kdump in Linux. + It will create a dump file in the server(s) dumping the server(s)' + memory, and also crash the server(s). OSC sees the dump file + (server dump) as a kind of resource. + """ + + def get_parser(self, prog_name): + parser = super(CreateServerDump, self).get_parser(prog_name) + parser.add_argument( + 'server', + metavar='', + nargs='+', + help=_('Server(s) to create dump file (name or ID)'), + ) + return parser + + 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, + ).trigger_crash_dump() + + class CreateServerImage(command.ShowOne): """Create a new disk image from a running server""" diff --git a/openstackclient/tests/compute/v2/test_server.py b/openstackclient/tests/compute/v2/test_server.py index f6b622916b..141e137000 100644 --- a/openstackclient/tests/compute/v2/test_server.py +++ b/openstackclient/tests/compute/v2/test_server.py @@ -490,6 +490,26 @@ class TestServerDelete(TestServer): ) +class TestServerDumpCreate(TestServer): + + def setUp(self): + super(TestServerDumpCreate, self).setUp() + + # Get the command object to test + self.cmd = server.CreateServerDump(self.app, None) + + # Set methods to be tested. + self.methods = { + 'trigger_crash_dump': None, + } + + def test_server_dump_one_server(self): + self.run_method_with_servers('trigger_crash_dump', 1) + + def test_server_dump_multi_servers(self): + self.run_method_with_servers('trigger_crash_dump', 3) + + class TestServerImageCreate(TestServer): columns = ( diff --git a/releasenotes/notes/bug-1538372-ef3a30298357f972.yaml b/releasenotes/notes/bug-1538372-ef3a30298357f972.yaml new file mode 100644 index 0000000000..e2c2d24765 --- /dev/null +++ b/releasenotes/notes/bug-1538372-ef3a30298357f972.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add support for the `server dump create` command + [Bug `1538372 `_] diff --git a/setup.cfg b/setup.cfg index c4d1000744..4cf9622ceb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -133,6 +133,7 @@ openstack.compute.v2 = server_start = openstackclient.compute.v2.server:StartServer server_stop = openstackclient.compute.v2.server:StopServer server_suspend = openstackclient.compute.v2.server:SuspendServer + server_dump_create = openstackclient.compute.v2.server:CreateServerDump server_unlock = openstackclient.compute.v2.server:UnlockServer server_unpause = openstackclient.compute.v2.server:UnpauseServer server_unrescue = openstackclient.compute.v2.server:UnrescueServer