# just a couple of globals
verbose = False
-cluster = None
+cluster_handle = None
class ArgumentError(Exception):
"""
help='client id for authentication')
parser.add_argument('--name', '-n', dest='client_name',
help='client name for authentication')
+ parser.add_argument('--cluster', help='cluster name')
parser.add_argument('--admin-daemon', dest='admin_socket',
help='submit admin-socket commands (\"help\" for help')
parser.print_help()
print '\n'
- if (cluster):
+ if (cluster_handle):
help_for_target(target=('mon', ''))
- if help_all and cluster:
+ if help_all and cluster_handle:
# try/except in case there are no daemons of that type
try:
firstosd = osdids()[0]
print >> sys.stderr, 'submit {0} to osd.{1}'.\
format(json.dumps(cmddict), osdid)
ret, outbuf, outs = \
- cluster.osd_command(osdid, json.dumps(cmddict), inbuf, timeout)
+ cluster_handle.osd_command(osdid, json.dumps(cmddict), inbuf,
+ timeout)
elif target[0] == 'pg':
# leave it in cmddict for the OSD to use too
print >> sys.stderr, 'submit {0} for pgid {1}'.\
format(json.dumps(cmddict), pgid)
ret, outbuf, outs = \
- cluster.pg_command(pgid, json.dumps(cmddict), inbuf, timeout)
+ cluster_handle.pg_command(pgid, json.dumps(cmddict), inbuf,
+ timeout)
elif target[0] == 'mon':
if verbose:
print >> sys.stderr, '{0} to {1}'.\
format(json.dumps(cmddict), target[0])
- ret, outbuf, outs = cluster.mon_command(json.dumps(cmddict),
- inbuf, timeout)
+ ret, outbuf, outs = cluster_handle.mon_command(json.dumps(cmddict),
+ inbuf, timeout)
except Exception as e:
raise RuntimeError('"{0}": exception {1}'.format(prefix, e))
return 1
# handle any 'generic' ceph arguments that we didn't parse here
- global cluster
- cluster = rados.Rados(name=name, conffile='')
+ global cluster_handle
+
+ # rados.Rados() will call rados_create2, and then read the conf file,
+ # and then set the keys from the dict. So we must do these
+ # "pre-file defaults" first (see common_preinit in librados)
+ conf_defaults = {
+ 'log_to_stderr':'true',
+ 'err_to_stderr':'true',
+ 'log_flush_on_exit':'true',
+ }
+ cluster_handle = rados.Rados(name=name, clustername=parsed_args.cluster,
+ conf_defaults=conf_defaults, conffile='')
- retargs = cluster.conf_parse_argv(childargs)
+ retargs = cluster_handle.conf_parse_argv(childargs)
#tmp = childargs
childargs = retargs
if not childargs:
childargs.remove('--')
try:
- cluster.connect()
+ cluster_handle.connect()
except KeyboardInterrupt:
print >> sys.stderr, "connection aborted"
return 1
# this instance keeps the watch connection alive, but is
# otherwise unused
- logwatch = rados.MonitorLog(cluster, level, watch_cb, 0)
+ logwatch = rados.MonitorLog(cluster_handle, level, watch_cb, 0)
# loop forever letting watch_cb print lines
while True:
try:
prefix='get_command_descriptions')
if ret == -errno.EINVAL:
# send command to old monitor
- ret, outbuf, outs = cluster.mon_command(' '.join(sys.argv[1:]), inbuf)
+ ret, outbuf, outs = cluster_handle.mon_command(' '.join(sys.argv[1:]),
+ inbuf)
elif ret:
if ret < 0:
ret = -ret