diff --git a/doc/source/command-objects/compute-service.rst b/doc/source/command-objects/compute-service.rst index 7bcab4d692..25a133d97c 100644 --- a/doc/source/command-objects/compute-service.rst +++ b/doc/source/command-objects/compute-service.rst @@ -50,19 +50,24 @@ Set service command .. program:: compute service set .. code:: bash - os compute service list + os compute service set [--enable | --disable] + [--disable-reason ] .. _compute-service-set: -.. describe:: --enable +.. option:: --enable Enable service (default) -.. describe:: --disable +.. option:: --disable Disable service +.. option:: --disable-reason + + Reason for disabling the service (in quotes) + .. describe:: Name of host diff --git a/openstackclient/compute/v2/service.py b/openstackclient/compute/v2/service.py index 3c06272490..1cc91711eb 100644 --- a/openstackclient/compute/v2/service.py +++ b/openstackclient/compute/v2/service.py @@ -95,14 +95,24 @@ class SetService(command.Command): dest="enabled", help="Disable a service", action="store_false") + parser.add_argument( + "--disable-reason", + default=None, + metavar="", + help="Reason for disabling the service (in quotas)" + ) return parser def take_action(self, parsed_args): compute_client = self.app.client_manager.compute + cs = compute_client.services - if parsed_args.enabled: - action = compute_client.services.enable + if not parsed_args.enabled: + if parsed_args.disable_reason: + cs.disable_log_reason(parsed_args.host, + parsed_args.service, + parsed_args.disable_reason) + else: + cs.disable(parsed_args.host, parsed_args.service) else: - action = compute_client.services.disable - - action(parsed_args.host, parsed_args.service) + cs.enable(parsed_args.host, parsed_args.service) diff --git a/openstackclient/tests/compute/v2/test_service.py b/openstackclient/tests/compute/v2/test_service.py index 2f8b2e7d10..0246fbc86b 100644 --- a/openstackclient/tests/compute/v2/test_service.py +++ b/openstackclient/tests/compute/v2/test_service.py @@ -153,3 +153,29 @@ class TestServiceSet(TestService): compute_fakes.service_binary, ) self.assertIsNone(result) + + def test_service_set_disable_with_reason(self): + reason = 'earthquake' + arglist = [ + compute_fakes.service_host, + compute_fakes.service_binary, + '--disable', + '--disable-reason', + reason + ] + verifylist = [ + ('host', compute_fakes.service_host), + ('service', compute_fakes.service_binary), + ('enabled', False), + ('disable_reason', reason) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.service_mock.disable_log_reason.assert_called_with( + compute_fakes.service_host, + compute_fakes.service_binary, + reason + ) + self.assertIsNone(result) diff --git a/releasenotes/notes/add-disable-reason-6e0f28459a09a60d.yaml b/releasenotes/notes/add-disable-reason-6e0f28459a09a60d.yaml new file mode 100644 index 0000000000..298ccad5c4 --- /dev/null +++ b/releasenotes/notes/add-disable-reason-6e0f28459a09a60d.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add support for the ``--disable-reason`` of ``service set`` command