summaryrefslogtreecommitdiff
path: root/openstackclient/volume/v2
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-08-16 18:46:55 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2016-08-17 10:42:28 +0800
commit81431d24a9f94f56c4c39cb12bf846871f6230d8 (patch)
tree214803522991d527a7f0ccf5c37c2e640fb2a4d2 /openstackclient/volume/v2
parentfc7a69e410f217a436f7dae97b35314019a48b1b (diff)
downloadpython-openstackclient-81431d24a9f94f56c4c39cb12bf846871f6230d8.tar.gz
Add "volume service set" command
Add "volume service set" command in volume v1 and v2 (v1 is the same as v2) to disable or enable volume service. Change-Id: Ibb2db7e93b24cb2e0d2a7c28b6fd8bcc851b8d2f Closes-Bug: #1613597
Diffstat (limited to 'openstackclient/volume/v2')
-rw-r--r--openstackclient/volume/v2/service.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/openstackclient/volume/v2/service.py b/openstackclient/volume/v2/service.py
index 2df38573..867c4b9c 100644
--- a/openstackclient/volume/v2/service.py
+++ b/openstackclient/volume/v2/service.py
@@ -15,6 +15,7 @@
"""Service action implementations"""
from osc_lib.command import command
+from osc_lib import exceptions
from osc_lib import utils
from openstackclient.i18n import _
@@ -72,3 +73,58 @@ class ListService(command.Lister):
(utils.get_item_properties(
s, columns,
) for s in data))
+
+
+class SetService(command.Command):
+ """Set volume service properties"""
+
+ def get_parser(self, prog_name):
+ parser = super(SetService, self).get_parser(prog_name)
+ parser.add_argument(
+ "host",
+ metavar="<host>",
+ help=_("Name of host")
+ )
+ parser.add_argument(
+ "service",
+ metavar="<service>",
+ help=_("Name of service (Binary name)")
+ )
+ enabled_group = parser.add_mutually_exclusive_group()
+ enabled_group.add_argument(
+ "--enable",
+ action="store_true",
+ help=_("Enable volume service")
+ )
+ enabled_group.add_argument(
+ "--disable",
+ action="store_true",
+ help=_("Disable volume service")
+ )
+ parser.add_argument(
+ "--disable-reason",
+ metavar="<reason>",
+ help=_("Reason for disabling the service "
+ "(should be used with --disable option)")
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ if parsed_args.disable_reason and not parsed_args.disable:
+ msg = _("Cannot specify option --disable-reason without "
+ "--disable specified.")
+ raise exceptions.CommandError(msg)
+
+ service_client = self.app.client_manager.volume
+ if parsed_args.enable:
+ service_client.services.enable(
+ parsed_args.host, parsed_args.service)
+ if parsed_args.disable:
+ if parsed_args.disable_reason:
+ service_client.services.disable_log_reason(
+ parsed_args.host,
+ parsed_args.service,
+ parsed_args.disable_reason)
+ else:
+ service_client.services.disable(
+ parsed_args.host, parsed_args.service)