summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-03-09 07:12:51 +0000
committerGerrit Code Review <review@openstack.org>2016-03-09 07:12:51 +0000
commitc8e4a1407f565c89bb5e4964fcbe98c2188ca06c (patch)
tree2ce7f7d9d0fcc595018cb91448b9242ae409d105
parente0d58641bba8cacab855ed5aa3b7506737470441 (diff)
parentb711c3a0ca622389b7f41021eb8ecd5d633b81d7 (diff)
downloadpython-openstackclient-c8e4a1407f565c89bb5e4964fcbe98c2188ca06c.tar.gz
Merge "Add --reason for disable service"
-rw-r--r--doc/source/command-objects/compute-service.rst11
-rw-r--r--openstackclient/compute/v2/service.py22
-rw-r--r--openstackclient/tests/compute/v2/test_service.py26
-rw-r--r--releasenotes/notes/add-disable-reason-6e0f28459a09a60d.yaml4
4 files changed, 54 insertions, 9 deletions
diff --git a/doc/source/command-objects/compute-service.rst b/doc/source/command-objects/compute-service.rst
index 7bcab4d6..25a133d9 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 <reason>]
<host> <service>
.. _compute-service-set:
-.. describe:: --enable
+.. option:: --enable
Enable service (default)
-.. describe:: --disable
+.. option:: --disable
Disable service
+.. option:: --disable-reason <reason>
+
+ Reason for disabling the service (in quotes)
+
.. describe:: <host>
Name of host
diff --git a/openstackclient/compute/v2/service.py b/openstackclient/compute/v2/service.py
index 3c062724..1cc91711 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="<reason>",
+ help="Reason for disabling the service (in quotas)"
+ )
return parser
def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute
-
- if parsed_args.enabled:
- action = compute_client.services.enable
+ cs = compute_client.services
+
+ 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 2f8b2e7d..0246fbc8 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 00000000..298ccad5
--- /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