diff --git a/ext_scripts/ext_rbd.py b/ext_scripts/ext_rbd.py index 3bf880fec3636014adc925646a0784de6eb2abf8..b9ddea74bb6510c0896ccd904c7125e8c68e2212 100755 --- a/ext_scripts/ext_rbd.py +++ b/ext_scripts/ext_rbd.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright (C) 2016-2017 GRNET S.A. # @@ -48,7 +48,7 @@ The following variables are optional: The code branches to the correct function, depending on the name (sys.argv[0]) of the executed script (attach, create, etc). -Returns O after successful completion, 1 on failure +Returns 0 after successful completion, 1 on failure """ @@ -136,7 +136,7 @@ class RBD(object): def list(pool=None, cephx=None): mappings = json.loads(RBD.exc(cephx, 'showmapped', '--format', 'json')) if pool: - return {k: v for k, v in mappings.iteritems() if v['pool'] == pool} + return [i for i in mappings if i['pool'] == pool] else: return mappings @@ -144,7 +144,7 @@ class RBD(object): def get_device(image, pool=None, cephx=None): """ Return the device the image is mapped else None""" list = RBD.list(pool=pool, cephx=cephx) - for mapping in list.itervalues(): + for mapping in list: if mapping['name'] == image: return mapping['device'] @@ -205,7 +205,7 @@ def read_env(): return None extp_params = {} - for k, v in os.environ.iteritems(): + for k, v in os.environ.items(): if k.startswith(PREFIX_EXTP): extp_params[k[len(PREFIX_EXTP):].lower()] = v @@ -231,7 +231,7 @@ def read_env(): extp_params.pop(k) userspace_params = {} - for p, v in extp_params.iteritems(): + for p, v in extp_params.items(): if p.startswith(PREFIX_USP): userspace_params[p[len(PREFIX_USP):]] = v extp_params.pop(p) @@ -312,7 +312,7 @@ def format_qemu_uri(name, pool=None, cephx=None, conf_file=None, cache=None, # although if 'ceph.conf' does not says otherwise, 'rbd_cache' is set # to true. extra_conf += ':rbd_cache_max_dirty=0' - for k, v in kwargs.iteritems(): + for k, v in kwargs.items(): extra_conf += ':%s=%s' % (k, v) if extra_conf: @@ -350,7 +350,7 @@ def attach(env): sys.stderr.write("Image '%s' already mapped to device '%s' \n" % (RBD.format_name(name, pool=pool), device)) - sys.stdout.write("%s" % device) + sys.stdout.write("%s" % device.decode()) qemu_uri = format_qemu_uri(name, pool=pool, cephx=cephx, cache=cache, **userspace_params) sys.stdout.write("\n%s" % qemu_uri)