本文整理汇总了Python中mgr_module.CommandResult.wait方法的典型用法代码示例。如果您正苦于以下问题:Python CommandResult.wait方法的具体用法?Python CommandResult.wait怎么用?Python CommandResult.wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mgr_module.CommandResult
的用法示例。
在下文中一共展示了CommandResult.wait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _open_connection
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def _open_connection(self, pool_name='device_health_metrics'):
pools = self.module.rados.list_pools()
is_pool = False
for pool in pools:
if pool == pool_name:
is_pool = True
break
if not is_pool:
self.module.log.debug('create %s pool' % pool_name)
# create pool
result = CommandResult('')
self.module.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd pool create',
'format': 'json',
'pool': pool_name,
'pg_num': 1,
}), '')
r, outb, outs = result.wait()
assert r == 0
# set pool application
result = CommandResult('')
self.module.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd pool application enable',
'format': 'json',
'pool': pool_name,
'app': 'mgr_devicehealth',
}), '')
r, outb, outs = result.wait()
assert r == 0
ioctx = self.module.rados.open_ioctx(pool_name)
return ioctx
示例2: open_connection
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def open_connection(self, create_if_missing=True):
pools = self.rados.list_pools()
is_pool = False
for pool in pools:
if pool == self.pool_name:
is_pool = True
break
if not is_pool:
if not create_if_missing:
return None
self.log.debug('create %s pool' % self.pool_name)
# create pool
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd pool create',
'format': 'json',
'pool': self.pool_name,
'pg_num': 1,
}), '')
r, outb, outs = result.wait()
assert r == 0
# set pool application
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd pool application enable',
'format': 'json',
'pool': self.pool_name,
'app': 'mgr_devicehealth',
}), '')
r, outb, outs = result.wait()
assert r == 0
ioctx = self.rados.open_ioctx(self.pool_name)
return ioctx
示例3: handle_osd_map
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def handle_osd_map(self):
"""
Check pools on each OSDMap change
"""
subtree_type = self.get_config('subtree') or 'rack'
failure_domain = self.get_config('failure_domain') or 'host'
pg_num = self.get_config('pg_num') or '128'
num_rep = self.get_config('num_rep') or '2'
prefix = self.get_config('prefix') or 'by-' + subtree_type + '-'
osdmap = self.get("osd_map")
lpools = []
for pool in osdmap['pools']:
if pool['pool_name'].find(prefix) == 0:
lpools.append(pool['pool_name'])
self.log.debug('localized pools = %s', lpools)
subtrees = []
tree = self.get('osd_map_tree')
for node in tree['nodes']:
if node['type'] == subtree_type:
subtrees.append(node['name'])
pool_name = prefix + node['name']
if pool_name not in lpools:
self.log.info('Creating localized pool %s', pool_name)
#
result = CommandResult("")
self.send_command(result, "mon", "", json.dumps({
"prefix": "osd crush rule create-replicated",
"format": "json",
"name": pool_name,
"root": node['name'],
"type": failure_domain,
}), "")
r, outb, outs = result.wait()
result = CommandResult("")
self.send_command(result, "mon", "", json.dumps({
"prefix": "osd pool create",
"format": "json",
"pool": pool_name,
'rule': pool_name,
"pool_type": 'replicated',
'pg_num': str(pg_num),
}), "")
r, outb, outs = result.wait()
result = CommandResult("")
self.send_command(result, "mon", "", json.dumps({
"prefix": "osd pool set",
"format": "json",
"pool": pool_name,
'var': 'size',
"val": str(num_rep),
}), "")
r, outb, outs = result.wait()
示例4: get_compat_weight_set_weights
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def get_compat_weight_set_weights(self, ms):
if not CRUSHMap.have_default_choose_args(ms.crush_dump):
# enable compat weight-set first
self.log.debug('ceph osd crush weight-set create-compat')
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd crush weight-set create-compat',
'format': 'json',
}), '')
r, outb, outs = result.wait()
if r != 0:
self.log.error('Error creating compat weight-set')
return
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd crush dump',
'format': 'json',
}), '')
r, outb, outs = result.wait()
if r != 0:
self.log.error('Error dumping crush map')
return
try:
crushmap = json.loads(outb)
except:
raise RuntimeError('unable to parse crush map')
else:
crushmap = ms.crush_dump
raw = CRUSHMap.get_default_choose_args(crushmap)
weight_set = {}
for b in raw:
bucket = None
for t in crushmap['buckets']:
if t['id'] == b['bucket_id']:
bucket = t
break
if not bucket:
raise RuntimeError('could not find bucket %s' % b['bucket_id'])
self.log.debug('bucket items %s' % bucket['items'])
self.log.debug('weight set %s' % b['weight_set'][0])
if len(bucket['items']) != len(b['weight_set'][0]):
raise RuntimeError('weight-set size does not match bucket items')
for pos in range(len(bucket['items'])):
weight_set[bucket['items'][pos]['id']] = b['weight_set'][0][pos]
self.log.debug('weight_set weights %s' % weight_set)
return weight_set
示例5: _osd
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def _osd(self, osd_id):
osd_id = int(osd_id)
osd_map = global_instance().get("osd_map")
osd = None
for o in osd_map['osds']:
if o['osd'] == osd_id:
osd = o
break
assert osd is not None # TODO 400
osd_spec = "{0}".format(osd_id)
osd_metadata = global_instance().get_metadata(
"osd", osd_spec)
result = CommandResult("")
global_instance().send_command(result, "osd", osd_spec,
json.dumps({
"prefix": "perf histogram dump",
}),
"")
r, outb, outs = result.wait()
assert r == 0
histogram = json.loads(outb)
return {
"osd": osd,
"osd_metadata": osd_metadata,
"osd_histogram": histogram
}
示例6: get_file_sd_config
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def get_file_sd_config(self):
servers = self.list_servers()
targets = []
for server in servers:
hostname = server.get('hostname', '')
for service in server.get('services', []):
if service['type'] != 'mgr':
continue
id_ = service['id']
# get port for prometheus module at mgr with id_
# TODO use get_config_prefix or get_config here once
# https://github.com/ceph/ceph/pull/20458 is merged
result = CommandResult("")
global_instance().send_command(
result, "mon", '',
json.dumps({
"prefix": "config-key get",
'key': "config/mgr/mgr/prometheus/{}/server_port".format(id_),
}),
"")
r, outb, outs = result.wait()
if r != 0:
global_instance().log.error("Failed to retrieve port for mgr {}: {}".format(id_, outs))
targets.append('{}:{}'.format(hostname, DEFAULT_PORT))
else:
port = json.loads(outb)
targets.append('{}:{}'.format(hostname, port))
ret = [
{
"targets": targets,
"labels": {}
}
]
return 0, json.dumps(ret), ""
示例7: handle_command
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def handle_command(self, inbuf, cmd):
self.log.error("handle_command")
if cmd['prefix'] == 'device query-daemon-health-metrics':
who = cmd.get('who', '')
if who[0:4] != 'osd.':
return (-errno.EINVAL, '', 'not a valid <osd.NNN> id')
osd_id = who[4:]
result = CommandResult('')
self.send_command(result, 'osd', osd_id, json.dumps({
'prefix': 'smart',
'format': 'json',
}), '')
r, outb, outs = result.wait()
return (r, outb, outs)
elif cmd['prefix'] == 'device scrape-daemon-health-metrics':
who = cmd.get('who', '')
if who[0:4] != 'osd.':
return (-errno.EINVAL, '', 'not a valid <osd.NNN> id')
id = int(who[4:])
return self.scrape_osd(id)
elif cmd['prefix'] == 'device scrape-health-metrics':
if 'devid' in cmd:
return self.scrape_device(cmd['devid'])
return self.scrape_all();
elif cmd['prefix'] == 'device show-health-metrics':
return self.show_device_metrics(cmd['devid'], cmd.get('sample'))
else:
# mgr should respect our self.COMMANDS and not call us for
# any prefix we don't advertise
raise NotImplementedError(cmd['prefix'])
示例8: reset_device_life_expectancy
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def reset_device_life_expectancy(self, device_id):
result = CommandResult('')
self.module.send_command(result, 'mon', '', json.dumps({
'prefix': 'device rm-life-expectancy',
'devid': device_id
}), '')
ret, outb, outs = result.wait()
if ret != 0:
self.module.log.error(
'failed to reset device life expectancy, %s' % outs)
return ret
示例9: _get
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def _get(self):
mds_spec = "{0}:0".format(self.fscid)
result = CommandResult("")
self._module.send_command(result, "mds", mds_spec,
json.dumps({
"prefix": "session ls",
}),
"")
r, outb, outs = result.wait()
# TODO handle nonzero returns, e.g. when rank isn't active
assert r == 0
return json.loads(outb)
示例10: mark_out_etc
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def mark_out_etc(self, osd_ids):
self.log.info('Marking out OSDs: %s' % osd_ids)
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd out',
'format': 'json',
'ids': osd_ids,
}), '')
r, outb, outs = result.wait()
if r != 0:
self.log.warn('Could not mark OSD %s out. r: [%s], outb: [%s], outs: [%s]' % (osd_ids, r, outb, outs))
for osd_id in osd_ids:
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd primary-affinity',
'format': 'json',
'id': int(osd_id),
'weight': 0.0,
}), '')
r, outb, outs = result.wait()
if r != 0:
self.log.warn('Could not set osd.%s primary-affinity, r: [%s], outs: [%s]' % (osd_id, r, outb, outs))
示例11: compat_weight_set_reweight
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def compat_weight_set_reweight(self, osd, new_weight):
self.log.debug('ceph osd crush weight-set reweight-compat')
result = CommandResult('')
self.send_command(result, 'mon', '', json.dumps({
'prefix': 'osd crush weight-set reweight-compat',
'format': 'json',
'item': 'osd.%d' % osd,
'weight': [new_weight],
}), '')
r, outb, outs = result.wait()
if r != 0:
self.log.error('Error setting compat weight-set osd.%d to %f' %
(osd, new_weight))
return
示例12: do_scrape_osd
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def do_scrape_osd(self, osd_id, ioctx, devid=''):
self.log.debug('do_scrape_osd osd.%d' % osd_id)
# scrape from osd
result = CommandResult('')
self.send_command(result, 'osd', str(osd_id), json.dumps({
'prefix': 'smart',
'format': 'json',
'devid': devid,
}), '')
r, outb, outs = result.wait()
try:
return json.loads(outb)
except:
self.log.debug('Fail to parse JSON result from "%s"' % outb)
示例13: handle_command
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def handle_command(self, cmd):
self.log.error("handle_command")
if cmd['prefix'] == 'osd smart get':
result = CommandResult('')
self.send_command(result, 'osd', cmd['osd_id'], json.dumps({
'prefix': 'smart',
'format': 'json',
}), '')
r, outb, outs = result.wait()
return (r, outb, outs)
else:
# mgr should respect our self.COMMANDS and not call us for
# any prefix we don't advertise
raise NotImplementedError(cmd['prefix'])
示例14: _config_dump
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def _config_dump(self):
"""Report cluster configuration
This report is the standard `config dump` report. It does not include
configuration defaults; these can be inferred from the version number.
"""
result = CommandResult("")
args = dict(prefix = "config dump", format = "json")
self.send_command(result, "mon", "", json.dumps(args), "")
ret, outb, outs = result.wait()
if ret == 0:
return json.loads(outb), []
else:
self.log.warning("send_command 'config dump' failed. \
ret={}, outs=\"{}\"".format(ret, outs))
return [], ["Failed to read monitor config dump"]
示例15: do_scrape_daemon
# 需要导入模块: from mgr_module import CommandResult [as 别名]
# 或者: from mgr_module.CommandResult import wait [as 别名]
def do_scrape_daemon(self, daemon_type, daemon_id, devid=''):
"""
:return: a dict, or None if the scrape failed.
"""
self.log.debug('do_scrape_daemon %s.%s' % (daemon_type, daemon_id))
result = CommandResult('')
self.send_command(result, daemon_type, daemon_id, json.dumps({
'prefix': 'smart',
'format': 'json',
'devid': devid,
}), '')
r, outb, outs = result.wait()
try:
return json.loads(outb)
except (IndexError, ValueError):
self.log.error(
"Fail to parse JSON result from daemon {0}.{1} ({2})".format(
daemon_type, daemon_id, outb))