Client support for service force-down

This patch adds support for service force-down.

Change-Id: Ie7712dced3a38ec27d2de8ecf948279e3a4400c8
Partially-Implements: blueprint enhance-service-api
This commit is contained in:
miaohb 2017-05-26 09:47:10 +08:00
parent 99af1df53c
commit e1d7cb0a7a
2 changed files with 23 additions and 1 deletions

View File

@ -89,11 +89,14 @@ class ServiceManager(base.Manager):
**kwargs)
return resp, body
def _update_body(self, host, binary, disabled_reason=None):
def _update_body(self, host, binary, disabled_reason=None,
force_down=None):
body = {"host": host,
"binary": binary}
if disabled_reason is not None:
body["disabled_reason"] = disabled_reason
if force_down is not None:
body["forced_down"] = force_down
return body
def enable(self, host, binary):
@ -105,3 +108,8 @@ class ServiceManager(base.Manager):
"""Disable the service specified by hostname and binary."""
body = self._update_body(host, binary, reason)
return self._action("/disable", qparams=body)
def force_down(self, host, binary, force_down=None):
"""Force service state to down specified by hostname and binary."""
body = self._update_body(host, binary, force_down=force_down)
return self._action("/force_down", qparams=body)

View File

@ -61,3 +61,17 @@ def do_service_disable(cs, args):
"""Disable the Zun service."""
res = cs.services.disable(args.host, args.binary, args.reason)
utils.print_dict(res[1]['service'])
@utils.arg('host', metavar='<hostname>', help='Name of host.')
@utils.arg('binary', metavar='<binary>', help='Service binary.')
@utils.arg(
'--unset',
dest='force_down',
help="Unset the force state down of service.",
action='store_false',
default=True)
def do_service_force_down(cs, args):
"""Force Zun service to down or unset the force state."""
res = cs.services.force_down(args.host, args.binary, args.force_down)
utils.print_dict(res[1]['service'])