From: Dan Mick Date: Wed, 5 Apr 2017 02:36:33 +0000 (-0700) Subject: ceph.in: move daemon commands to their own function X-Git-Tag: v12.0.3~71^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=334f17554e336f16a4f474727cdb218f52d0212c;p=ceph.git ceph.in: move daemon commands to their own function Signed-off-by: Dan Mick --- diff --git a/src/ceph.in b/src/ceph.in index 3ab1c222a3c8..8b447122ea7a 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -565,50 +565,12 @@ def ping_monitor(cluster_handle, name, timeout): print(s) return 0 -### -# main -### - -def main(): - ceph_args = os.environ.get('CEPH_ARGS') - if ceph_args: - if "injectargs" in sys.argv: - i = sys.argv.index("injectargs") - sys.argv = sys.argv[:i] + ceph_args.split() + sys.argv[i:] - else: - sys.argv.extend(ceph_args.split()) - parser, parsed_args, childargs = parse_cmdargs() - - if parsed_args.version: - print('ceph version {0} ({1})'.format(CEPH_GIT_NICE_VER, CEPH_GIT_VER)) # noqa - return 0 - - global verbose - verbose = parsed_args.verbose - - if verbose: - print("parsed_args: {0}, childargs: {1}".format(parsed_args, childargs), file=sys.stderr) - if parsed_args.admin_socket_nope: - print('--admin-socket is used by daemons; '\ - 'you probably mean --admin-daemon/daemon', file=sys.stderr) - return 1 - - # pass on --id, --name, --conf - name = 'client.admin' - if parsed_args.client_id: - name = 'client.' + parsed_args.client_id - if parsed_args.client_name: - name = parsed_args.client_name - - # default '' means default conf search - conffile = '' - if parsed_args.cephconf: - conffile = parsed_args.cephconf - # For now, --admin-daemon is handled as usual. Try it - # first in case we can't connect() to the cluster - - format = parsed_args.output_format +def maybe_daemon_command(parsed_args, childargs): + """ + Check if --admin-socket, daemon, or daemonperf command + if it is, returns (boolean handled, return code if handled == True) + """ daemon_perf = False sockpath = None @@ -629,13 +591,13 @@ def main(): childargs[1]) except Exception as e: print('Can\'t get admin socket path: ' + str(e), file=sys.stderr) - return errno.EINVAL + return True, errno.EINVAL # for both: childargs = childargs[2:] else: print('{0} requires at least {1} arguments'.format(childargs[0], require_args), file=sys.stderr) - return errno.EINVAL + return True, errno.EINVAL if sockpath and daemon_perf: interval = 1 @@ -647,22 +609,73 @@ def main(): raise ValueError except ValueError: print('daemonperf: interval should be a positive number', file=sys.stderr) - return errno.EINVAL + return True, errno.EINVAL if len(childargs) > 1: if not childargs[1].isdigit(): print('daemonperf: count should be a positive integer', file=sys.stderr) - return errno.EINVAL + return True, errno.EINVAL count = int(childargs[1]) DaemonWatcher(sockpath).run(interval, count) - return 0 + return True, 0 elif sockpath: try: - raw_write(admin_socket(sockpath, childargs, format)) + raw_write(admin_socket(sockpath, childargs, parsed_args.output_format)) except Exception as e: print('admin_socket: {0}'.format(e), file=sys.stderr) - return errno.EINVAL + return True, errno.EINVAL + return True, 0 + + return False, 0 + +### +# main +### + +def main(): + ceph_args = os.environ.get('CEPH_ARGS') + if ceph_args: + if "injectargs" in sys.argv: + i = sys.argv.index("injectargs") + sys.argv = sys.argv[:i] + ceph_args.split() + sys.argv[i:] + else: + sys.argv.extend(ceph_args.split()) + parser, parsed_args, childargs = parse_cmdargs() + + if parsed_args.version: + print('ceph version {0} ({1})'.format(CEPH_GIT_NICE_VER, CEPH_GIT_VER)) # noqa return 0 + global verbose + verbose = parsed_args.verbose + + if verbose: + print("parsed_args: {0}, childargs: {1}".format(parsed_args, childargs), file=sys.stderr) + + if parsed_args.admin_socket_nope: + print('--admin-socket is used by daemons; '\ + 'you probably mean --admin-daemon/daemon', file=sys.stderr) + return 1 + + # pass on --id, --name, --conf + name = 'client.admin' + if parsed_args.client_id: + name = 'client.' + parsed_args.client_id + if parsed_args.client_name: + name = parsed_args.client_name + + # default '' means default conf search + conffile = '' + if parsed_args.cephconf: + conffile = parsed_args.cephconf + # For now, --admin-daemon is handled as usual. Try it + # first in case we can't connect() to the cluster + + format = parsed_args.output_format + + done, ret = maybe_daemon_command(parsed_args, childargs) + if done: + return ret + timeout = None if parsed_args.cluster_timeout: timeout = parsed_args.cluster_timeout