CLI for disable service reason
Adds cli option to allow users to give reason for service-disable. Also adds disabled reason as a column in service list, so any disabled service can be seen with reason. A recent nova change that allows disable-log-reason allows users to provide reason for disabling service. This just adds the cli option for the method. Blueprint record-reason-for-disabling-service Change-Id: If263788c34279d6b4c568d5e0320448d2ff67a12
This commit is contained in:
parent
b526c9beff
commit
d095b8a335
novaclient
@ -1377,6 +1377,12 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
'binary': body['binary'],
|
||||
'status': 'disabled'}})
|
||||
|
||||
def put_os_services_disable_log_reason(self, body, **kw):
|
||||
return (200, {}, {'service': {'host': body['host'],
|
||||
'binary': body['binary'],
|
||||
'status': 'disabled',
|
||||
'disabled_reason': body['disabled_reason']}})
|
||||
|
||||
#
|
||||
# Fixed IPs
|
||||
#
|
||||
|
@ -66,3 +66,12 @@ class ServicesTest(utils.TestCase):
|
||||
cs.assert_called('PUT', '/os-services/disable', values)
|
||||
self.assertTrue(isinstance(service, services.Service))
|
||||
self.assertEqual(service.status, 'disabled')
|
||||
|
||||
def test_services_disable_log_reason(self):
|
||||
service = cs.services.disable_log_reason('compute1', 'nova-compute',
|
||||
'disable bad host')
|
||||
values = {'host': 'compute1', 'binary': 'nova-compute',
|
||||
'disabled_reason': 'disable bad host'}
|
||||
cs.assert_called('PUT', '/os-services/disable-log-reason', values)
|
||||
self.assertTrue(isinstance(service, services.Service))
|
||||
self.assertEqual(service.status, 'disabled')
|
||||
|
@ -956,6 +956,12 @@ class ShellTest(utils.TestCase):
|
||||
body = {'host': 'host1', 'binary': 'nova-cert'}
|
||||
self.assert_called('PUT', '/os-services/disable', body)
|
||||
|
||||
def test_services_disable_with_reason(self):
|
||||
self.run_command('service-disable host1 nova-cert --reason no_reason')
|
||||
body = {'host': 'host1', 'binary': 'nova-cert',
|
||||
'disabled_reason': 'no_reason'}
|
||||
self.assert_called('PUT', '/os-services/disable-log-reason', body)
|
||||
|
||||
def test_fixed_ips_get(self):
|
||||
self.run_command('fixed-ip-get 192.168.1.1')
|
||||
self.assert_called('GET', '/os-fixed-ips/192.168.1.1')
|
||||
|
@ -59,3 +59,8 @@ class ServiceManager(base.ManagerWithFind):
|
||||
"""Enable the service specified by hostname and binary"""
|
||||
body = {"host": host, "binary": binary}
|
||||
return self._update("/os-services/disable", body, "service")
|
||||
|
||||
def disable_log_reason(self, host, binary, reason):
|
||||
"""Disable the service with reason"""
|
||||
body = {"host": host, "binary": binary, "disabled_reason": reason}
|
||||
return self._update("/os-services/disable-log-reason", body, "service")
|
||||
|
@ -2543,6 +2543,10 @@ def do_service_list(cs, args):
|
||||
"""Show a list of all running services. Filter by host & binary."""
|
||||
result = cs.services.list(host=args.host, binary=args.binary)
|
||||
columns = ["Binary", "Host", "Zone", "Status", "State", "Updated_at"]
|
||||
# NOTE(sulo): we check if the response has disabled_reason
|
||||
# so as not to add the column when the extended ext is not enabled.
|
||||
if hasattr(result[0], 'disabled_reason'):
|
||||
columns.append("Disabled Reason")
|
||||
utils.print_list(result, columns)
|
||||
|
||||
|
||||
@ -2556,10 +2560,18 @@ def do_service_enable(cs, args):
|
||||
|
||||
@utils.arg('host', metavar='<hostname>', help='Name of host.')
|
||||
@utils.arg('binary', metavar='<binary>', help='Service binary.')
|
||||
@utils.arg('--reason', metavar='<reason>',
|
||||
help='Reason for disabling service.')
|
||||
def do_service_disable(cs, args):
|
||||
"""Disable the service"""
|
||||
result = cs.services.disable(args.host, args.binary)
|
||||
utils.print_list([result], ['Host', 'Binary', 'Status'])
|
||||
if args.reason:
|
||||
result = cs.services.disable_log_reason(args.host, args.binary,
|
||||
args.reason)
|
||||
utils.print_list([result], ['Host', 'Binary', 'Status',
|
||||
'Disabled Reason'])
|
||||
else:
|
||||
result = cs.services.disable(args.host, args.binary)
|
||||
utils.print_list([result], ['Host', 'Binary', 'Status'])
|
||||
|
||||
|
||||
@utils.arg('fixed_ip', metavar='<fixed_ip>', help='Fixed IP Address.')
|
||||
|
Loading…
x
Reference in New Issue
Block a user