Allow to run also in Python 2. Especially for Old faggots with Centos

master
Коренберг Марк 2018-05-12 00:42:05 +05:00
parent 2f16f3c2bf
commit af3e040582
1 changed files with 10 additions and 13 deletions

23
main.py
View File

@ -1,27 +1,31 @@
#!/usr/bin/python3 #!/usr/bin/python3
import sys import sys
import json import json
import argparse import argparse
import logging import logging
import os import os
import time
import rados import rados
import configparser
from itertools import cycle, count from itertools import cycle, count
from pprint import pprint from pprint import pprint
import ceph_argparse import ceph_argparse
if sys.version_info >= (3,0):
from time import monotonic
else:
from time import time as monotonic
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def do_bench(secs, name, ioctx, data): def do_bench(secs, name, ioctx, data):
b = a = time.monotonic() b = a = monotonic()
stop = a + secs stop = a + secs
ops = 0 ops = 0
try: try:
while b <= stop: while b <= stop:
ioctx.write(name, next(data)) ioctx.write(name, next(data))
b = time.monotonic() b = monotonic()
ops += 1 ops += 1
finally: finally:
try: try:
@ -64,15 +68,8 @@ def main():
assert MODE in ('HOST', 'OSD') assert MODE in ('HOST', 'OSD')
# TODO: ugly code. pass whole client name, not rados_id to Rados constructor log.info('Attaching to CEPH cluster. pool=%s', pool)
config = configparser.ConfigParser() with rados.Rados(conffile='/etc/ceph/ceph.conf', conf=conf) as cluster:
config.read(conf['keyring'])
(client, rados_id) = config.sections()[0].split('.')
if client != 'client':
raise ValueError
log.info('Attaching to CEPH cluster. pool=%s, rados_id=%s', pool, rados_id)
with rados.Rados(conffile='/etc/ceph/ceph.conf', rados_id=rados_id, conf=conf) as cluster:
log.info('Getting map osd -> host.') log.info('Getting map osd -> host.')
#info = json.loads(subprocess.check_output(['ceph', 'osd', 'tree', '--format=json']).decode('utf-8')) #info = json.loads(subprocess.check_output(['ceph', 'osd', 'tree', '--format=json']).decode('utf-8'))
info = _cmd(cluster, 'osd tree') info = _cmd(cluster, 'osd tree')