本文整理汇总了Python中toolset.io.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: run
def run(self):
try:
#
# - first turn off the pods
# - keep track of the indices
#
def _query(zk):
replies = fire(zk, self.cluster, 'control/off', subset=self.indices)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
pods = run(self.proxy, _query)
#
# - then turn those pod back on
#
def _query(zk):
replies = fire(zk, self.cluster, 'control/on', subset=pods)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
assert pods == run(self.proxy, _query), 'one or more pods failed to switch back on'
self.out['reset'] = pods
self.out['ok'] = True
except AssertionError as failure:
logger.debug('%s : failed to reset -> %s' % (self.cluster, failure))
except Exception as failure:
logger.debug('%s : failed to reset -> %s' % (self.cluster, diagnostic(failure)))
开发者ID:nicbet,项目名称:ochothon,代码行数:32,代码来源:reset.py
示例2: run
def run(self):
try:
def _query(zk):
replies = fire(zk, self.cluster, 'control/off', subset=self.subset)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
js = run(self.proxy, _query)
def _query(zk):
replies = fire(zk, self.cluster, 'reset', subset=self.subset)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
assert js == run(self.proxy, _query), 'one or more pods did not respond'
def _query(zk):
replies = fire(zk, self.cluster, 'control/on', subset=self.subset)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
assert js == run(self.proxy, _query), 'one or more pods did not respond'
self.out['reset'] = js
self.out['ok'] = True
except AssertionError as failure:
logger.debug('%s : failed to reset -> %s' % (self.cluster, failure))
except Exception as failure:
logger.debug('%s : failed to reset -> %s' % (self.cluster, diagnostic(failure)))
开发者ID:lmok,项目名称:ochothon,代码行数:31,代码来源:reset.py
示例3: body
def body(self, args, proxy):
try:
with open(args.yaml[0], 'r') as f:
payload = yaml.load(f)
total = 0
merged = {}
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'control/signal', js=json.dumps(payload))
return len(replies), {key: data for key, (_, data, code) in replies.items() if code == 200}
pods, js = run(proxy, _query)
merged.update(js)
total += pods
pct = (len(merged) * 100) / total if total else 0
logger.info(json.dumps(merged) if args.json else '%d%% replies, pinged %d pods' % (pct, len(merged)))
except IOError:
logger.info('unable to load %s' % args.yaml[0])
except YAMLError as failure:
if hasattr(failure, 'problem_mark'):
mark = failure.problem_mark
assert 0, '%s is invalid (line %s, column %s)' % (args.yaml, mark.line+1, mark.column+1)
开发者ID:a3linux,项目名称:ochothon,代码行数:30,代码来源:ping.py
示例4: body
def body(self, args, unknown, proxy):
assert args.force or args.indices, 'you must specify --force if -i is not set'
if unknown is not None:
args.cmdline += unknown
files = {}
headers = {'X-Shell': ' '.join(args.cmdline)}
for token in args.cmdline:
if path.isfile(token):
with open(token, 'rb') as f:
files[token] = f.read()
def _query(zk):
replies = fire(zk, args.clusters[0], 'exec', subset=args.indices, headers=headers, files=files, timeout=args.timeout)
return len(replies), {key: js for key, (_, js, code) in replies.items() if code == 200}
total, js = run(proxy, _query)
pct = ((len(js) * 100) / total) if total else 0
if args.json:
logger.info(json.dumps(js))
elif js:
logger.info('<%s> -> %d%% replies (%d pods total) ->\n' % (args.clusters[0], pct, len(js)))
for key, log in js.items():
suffix = '\n\n %s\n' % '\n '.join(log['stdout']) if log['stdout'] else ''
logger.info('- %s (exit code %d)%s' % (key, log['code'], suffix))
return 0 if pct == 100 else 1
开发者ID:autodesk-cloud,项目名称:ochothon,代码行数:30,代码来源:exec.py
示例5: body
def body(self, args, proxy):
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'info')
return len(replies), \
[[key, '|', hints['ip'], '|', hints['process'], '|', hints['state']] for key, (_, hints, code) in replies.items() if code == 200]
total, js = run(proxy, _query)
if not total:
logger.info('\n<%s> -> no pods found' % token)
else:
#
# - justify & format the whole thing in a nice set of columns
#
pct = (len(js) * 100) / total
logger.info('\n<%s> -> %d%% replies (%d pods total) ->\n' % (token, pct, total))
rows = [['cluster', '|', 'pod IP', '|', 'process', '|', 'state'], ['', '|', '', '|', '', '|', '']] + js
widths = [max(map(len, col)) for col in zip(*rows)]
for row in rows:
logger.info(" ".join((val.ljust(width) for val, width in zip(row, widths))))
开发者ID:autodesk-cloud,项目名称:ochonetes,代码行数:25,代码来源:grep.py
示例6: body
def body(self, args, proxy):
outs = {}
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'info')
return len(replies), [[key, '|', hints['ip'], '|', hints['node'], '|', hints['process'], '|', hints['state']]
for key, (_, hints, code) in sorted(replies.items()) if code == 200]
total, js = run(proxy, _query)
outs.update({item[0]: {'ip': item[2], 'node': item[4], 'process': item[6], 'state': item[8]} for item in js})
if js and not args.json:
#
# - justify & format the whole thing in a nice set of columns
#
pct = (len(js) * 100) / total
logger.info('<%s> -> %d%% replies (%d pods total) ->\n' % (token, pct, len(js)))
rows = [['pod', '|', 'pod IP', '|', 'node', '|', 'process', '|', 'state'], ['', '|', '', '|', '', '|', '', '|', '']] + js
widths = [max(map(len, col)) for col in zip(*rows)]
for row in rows:
logger.info(' '.join((val.ljust(width) for val, width in zip(row, widths))))
if args.json:
logger.info(json.dumps(outs))
开发者ID:a3linux,项目名称:ochothon,代码行数:30,代码来源:grep.py
示例7: body
def body(self, args, proxy):
#
# - grab the user metrics returned in sanity_check()
# - those are returned via a POST /info
#
outs = {}
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'info')
return len(replies), {key: hints['metrics'] for key, (index, hints, code) in replies.items() if code == 200 and 'metrics' in hints}
total, js = run(proxy, _query)
outs.update(js)
#
# - prettify if not asked for a json string
#
if js and not args.json:
pct = (len(js) * 100) / total
logger.info('%d pods, %d%% replies ->\n' % (len(js), pct))
rows = [['pod', '|', 'metrics'], ['', '|', '']] + sorted([[key, '|', json.dumps(val)] for key, val in js.iteritems()])
widths = [max(map(len, col)) for col in zip(*rows)]
for row in rows:
logger.info(' '.join((val.ljust(width) for val, width in zip(row, widths))))
if args.json:
logger.info(json.dumps(outs))
开发者ID:a3linux,项目名称:ochothon,代码行数:33,代码来源:poll.py
示例8: body
def body(self, args, unknown, proxy):
port = str(args.port[0])
def _query(zk):
replies = fire(zk, args.clusters, 'info')
return len(replies), [[key, '|', hints['ip'], '|', hints['public'], '|', str(hints['ports'][port])] for key, (_, hints, code) in sorted(replies.items()) if code == 200 and port in hints['ports']]
total, js = run(proxy, _query)
pct = (len(js) * 100) / total if total else 0
if args.json:
out = {item[0]: {'ip': item[2], 'public': item[4], 'ports': item[6]} for item in js}
logger.info(json.dumps(out))
elif js:
#
# - justify & format the whole thing in a nice set of columns
#
logger.info('<%s> -> %d%% replies (%d pods total) ->\n' % (args.clusters, pct, len(js)))
rows = [['pod', '|', 'pod IP', '|', 'public IP', '|', 'TCP'], ['', '|', '', '|', '', '|', '']] + js
widths = [max(map(len, col)) for col in zip(*rows)]
for row in rows:
logger.info(' '.join((val.ljust(width) for val, width in zip(row, widths))))
return 0
开发者ID:nicbet,项目名称:ochothon,代码行数:26,代码来源:port.py
示例9: _spin
def _spin():
def _query(zk):
replies = fire(zk, self.cluster, 'info')
return [(hints['process'], seq) for seq, hints, _ in replies.values() if hints['process'] in target]
js = run(self.proxy, _query)
assert len(js) == capacity, 'not all pods running yet'
return js
开发者ID:autodesk-cloud,项目名称:ochothon,代码行数:8,代码来源:bump.py
示例10: _spin
def _spin():
def _query(zk):
replies = fire(zk, self.cluster, 'info')
return [seq for seq, _, _ in replies.values()]
js = run(self.proxy, _query)
assert len(js) == target, 'not all pods running yet'
return js
开发者ID:a3linux,项目名称:ochothon,代码行数:8,代码来源:scale.py
示例11: _spin
def _spin():
def _query(zk):
replies = fire(zk, qualified, 'info')
return [(hints['process'], seq) for seq, hints, _ in replies.values()
if hints['application'] == application and hints['process'] in target]
js = run(self.proxy, _query)
assert len(js) == self.pods, 'not all pods running yet'
return js
开发者ID:a3linux,项目名称:ochothon,代码行数:9,代码来源:deploy.py
示例12: run
def run(self):
try:
#
# - first turn the pod off
#
def _query(zk):
replies = fire(zk, self.cluster, 'control/off', subset=self.indices)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
js = run(self.proxy, _query)
#
# - reset it
# - this will force a reconnection to zookeeper
#
def _query(zk):
replies = fire(zk, self.cluster, 'reset', subset=self.indices)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
assert js == run(self.proxy, _query), 'one or more pods did not respond'
#
# - then turn the pod back on
#
def _query(zk):
replies = fire(zk, self.cluster, 'control/on', subset=self.indices)
return [seq for _, (seq, _, code) in replies.items() if code == 200]
assert js == run(self.proxy, _query), 'one or more pods did not respond'
self.out['reset'] = js
self.out['ok'] = True
except AssertionError as failure:
logger.debug('%s : failed to reset -> %s' % (self.cluster, failure))
except Exception as failure:
logger.debug('%s : failed to reset -> %s' % (self.cluster, diagnostic(failure)))
开发者ID:a3linux,项目名称:ochothon,代码行数:41,代码来源:reset.py
示例13: body
def body(self, args, proxy):
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'control/on', subset=args.indices)
return len(replies), [pod for pod, (_, _, code) in replies.items() if code == 200]
total, js = run(proxy, _query)
if js:
pct = (len(js) * 100) / total
logger.info('<%s> -> %d%% replies, %d pods on' % (token, pct, len(js)))
开发者ID:a3linux,项目名称:ochothon,代码行数:12,代码来源:on.py
示例14: _spin
def _spin():
def _query(zk):
replies = fire(zk, self.cluster, 'info')
return [(seq, hints['application'], hints['task']) for (seq, hints, _) in replies.values()]
js = run(self.proxy, _query)
if self.group is not None:
nb_pods = sum(1 for (_, key, _) in js if key == app)
else:
nb_pods = len(js)
assert nb_pods == target, 'not all pods running yet'
return js
开发者ID:pferrot,项目名称:ochothon,代码行数:12,代码来源:scale.py
示例15: body
def body(self, args, proxy):
for token in args.clusters:
def _query(zk):
return fire(zk, token, 'log')
js = run(proxy, _query)
for pod in sorted(js.keys()):
_, log, code = js[pod]
if code == 200:
logger.info('\n%s ->\n\n- %s' % (pod, '- '.join(log[-64:])))
开发者ID:autodesk-cloud,项目名称:ochonetes,代码行数:12,代码来源:log.py
示例16: body
def body(self, args, proxy):
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'log', subset=args.indices)
return len(replies), {key: log for key, (_, log, code) in replies.items() if code == 200}
total, js = run(proxy, _query)
if js:
pct = ((len(js) * 100) / total)
unrolled = ['- %s\n\n %s' % (key, ' '.join(log if args.long else log[-16:])) for key, log in js.items()]
logger.info('<%s> -> %d%% replies (%d pods total) ->\n%s' % (token, pct, len(js), '\n'.join(unrolled)))
开发者ID:UncleBarney,项目名称:ochothon,代码行数:13,代码来源:log.py
示例17: body
def body(self, args, proxy):
def _query(zk):
responses = fire(zk, '*', 'info')
return {key: hints['process'] for key, (_, hints, code) in responses.items() if code == 200}
js = run(proxy, _query)
if not js:
logger.info('\n0 pods')
else:
running = [pod for pod, state in js.items() if state == 'running']
pct = int((100 * len(running)) / len(js))
logger.info('\n%d pods, %d%% running ->\n - %s' % (len(js), pct, '\n - '.join(sorted(running))))
开发者ID:autodesk-cloud,项目名称:ochonetes,代码行数:13,代码来源:ls.py
示例18: body
def body(self, args, proxy):
assert args.force or args.subset, 'you must specify --force if -i is not set'
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'control/off', subset=args.subset)
return len(replies), [pod for pod, (_, _, code) in replies.items() if code == 200]
total, js = run(proxy, _query)
if js:
pct = (len(js) * 100) / total
logger.info('<%s> -> %d%% replies, %d pods off' % (token, pct, len(js)))
开发者ID:lmok,项目名称:ochothon,代码行数:14,代码来源:off.py
示例19: body
def body(self, args, proxy):
for token in args.clusters:
def _query(zk):
replies = fire(zk, token, 'control/off')
return len(replies), [pod for pod, (_, hints, code) in replies.items() if code == 200]
total, js = run(proxy, _query)
if not total:
logger.info("\n<%s> -> no pods found" % token)
else:
pct = (len(js) * 100) / total
logger.info('\n<%s> -> %d%% replies, %d pods off' % (token, pct, len(js)))
开发者ID:autodesk-cloud,项目名称:ochonetes,代码行数:15,代码来源:off.py
示例20: body
def body(self, args, _, proxy):
def _query(zk):
replies = fire(zk, args.clusters, 'log', subset=args.indices)
return len(replies), {key: log for key, (_, log, code) in replies.items() if code == 200}
total, js = run(proxy, _query)
pct = ((len(js) * 100) / total) if total else 0
if js:
#
# - justify & format the whole thing
#
unrolled = ['- %s\n\n %s' % (key, ' '.join(log if args.long else log[-16:])) for key, log in js.items()]
logger.info('<%s> -> %d%% replies (%d pods total) ->\n%s' % (args.clusters, pct, len(js), '\n'.join(unrolled)))
return 0
开发者ID:autodesk-cloud,项目名称:ochothon,代码行数:17,代码来源:log.py
注:本文中的toolset.io.run函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论