Loading ccserver/handlers.py +37 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import inspect import logging from sjrpc.utils import RpcHandler, pure from sjrpc.core import RpcError from conf import CCConf from exceptions import (AlreadyRegistered, AuthenticationError, RightError, ReservedTagError, BadObjectError, BadRoleError, Loading Loading @@ -463,6 +464,42 @@ class CliHandler(OnlineCCHandler): return errs.get_dict() @listed def shutdown(self, conn, query, reboot=True, gracefull=True): ''' Execute a shutdown on selected objects (must be roles hv or host). :param query: the tql query to select objects. :param reboot: reboot the host instead of just shut it off :param gracefull: properly shutdown the host :return: a dict where key is the id of a selected object, and the value a tuple (errcode, message) where errcode is (success|error|warn) and message an error message. ''' self._check(conn, 'execute', query) objects = self._server.list(query, show=set(('r',))) errs = Reporter() for obj in objects: if obj['r'] not in ('hv', 'host'): errs.error(obj['id'], 'bad role') continue try: objcon = self._server.get_connection(obj['id']) except KeyError: errs.error(obj['id'], 'node not connected') else: try: objcon.connection.call('node_shutdown', reboot, gracefull) except RpcError as err: errs.error(obj['id'], '%s (exc: %s)' % (err.message, err.exception)) else: errs.success(obj['id'], 'ok') return errs.get_dict() @listed def dbstats(self, conn): ''' Loading Loading
ccserver/handlers.py +37 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import inspect import logging from sjrpc.utils import RpcHandler, pure from sjrpc.core import RpcError from conf import CCConf from exceptions import (AlreadyRegistered, AuthenticationError, RightError, ReservedTagError, BadObjectError, BadRoleError, Loading Loading @@ -463,6 +464,42 @@ class CliHandler(OnlineCCHandler): return errs.get_dict() @listed def shutdown(self, conn, query, reboot=True, gracefull=True): ''' Execute a shutdown on selected objects (must be roles hv or host). :param query: the tql query to select objects. :param reboot: reboot the host instead of just shut it off :param gracefull: properly shutdown the host :return: a dict where key is the id of a selected object, and the value a tuple (errcode, message) where errcode is (success|error|warn) and message an error message. ''' self._check(conn, 'execute', query) objects = self._server.list(query, show=set(('r',))) errs = Reporter() for obj in objects: if obj['r'] not in ('hv', 'host'): errs.error(obj['id'], 'bad role') continue try: objcon = self._server.get_connection(obj['id']) except KeyError: errs.error(obj['id'], 'node not connected') else: try: objcon.connection.call('node_shutdown', reboot, gracefull) except RpcError as err: errs.error(obj['id'], '%s (exc: %s)' % (err.message, err.exception)) else: errs.success(obj['id'], 'ok') return errs.get_dict() @listed def dbstats(self, conn): ''' Loading