diff --git a/ceph_iscsi_config/client.py b/ceph_iscsi_config/client.py index 9ea6aca2..74ba5c57 100644 --- a/ceph_iscsi_config/client.py +++ b/ceph_iscsi_config/client.py @@ -69,7 +69,7 @@ def __init__(self, logger, client_iqn, image_list, chap): self.client_luns = {} self.tpg = None self.tpg_luns = {} - self.lun_id_list = range(256) # available LUN ids 0..255 + self.lun_id_list = list(range(256)) # available LUN ids 0..255 self.change_count = 0 # enable commit to the config for changes by default diff --git a/ceph_iscsi_config/common.py b/ceph_iscsi_config/common.py index e224209e..fcb42d04 100644 --- a/ceph_iscsi_config/common.py +++ b/ceph_iscsi_config/common.py @@ -230,8 +230,8 @@ def _seed_rbd_config(self): seed_now = Config.seed_config seed_now['created'] = get_time() seed = json.dumps(seed_now, sort_keys=True, indent=4, separators=(',', ': ')) - ioctx.write_full(self.config_name, seed) - ioctx.set_xattr(self.config_name, "epoch", "0") + ioctx.write_full(self.config_name, seed.encode('utf-8')) + ioctx.set_xattr(self.config_name, "epoch", "0".encode('utf-8')) self.changed = True self.unlock() @@ -361,8 +361,9 @@ def _commit_rbd(self, post_action): self.logger.debug("_commit_rbd updating config to {}".format(config_str)) config_str_fmtd = json.dumps(current_config, sort_keys=True, indent=4, separators=(',', ': ')) - ioctx.write_full(self.config_name, config_str_fmtd) - ioctx.set_xattr(self.config_name, "epoch", str(current_config["epoch"])) + ioctx.write_full(self.config_name, config_str_fmtd.encode('utf-8')) + ioctx.set_xattr(self.config_name, "epoch", + str(current_config["epoch"]).encode('utf-8')) del self.txn_list[:] # empty the list of transactions self.unlock() diff --git a/ceph_iscsi_config/lun.py b/ceph_iscsi_config/lun.py index 3b3593a1..8386cca8 100644 --- a/ceph_iscsi_config/lun.py +++ b/ceph_iscsi_config/lun.py @@ -933,7 +933,7 @@ def set_owner(gateways): gw_items = gw_nodes.items() # first entry is the lowest number of active_luns - gw_items.sort(key=lambda x: (x[1]['active_luns'])) + gw_items = sorted(gw_items, key=lambda x: (x[1]['active_luns'])) # 1st tuple is gw with lowest active_luns, so return the 1st # element which is the hostname diff --git a/ceph_iscsi_config/settings.py b/ceph_iscsi_config/settings.py index efed6b7b..4ec04734 100644 --- a/ceph_iscsi_config/settings.py +++ b/ceph_iscsi_config/settings.py @@ -1,7 +1,10 @@ __author__ = 'pcuzner@redhat.com' -from ConfigParser import ConfigParser +try: + from ConfigParser import ConfigParser +except ImportError: + from configparser import ConfigParser from distutils.util import strtobool import re @@ -29,7 +32,7 @@ def normalize_controls(raw_controls, settings_list): """ controls = {} - for key, raw_value in raw_controls.iteritems(): + for key, raw_value in raw_controls.items(): if key not in settings_list: raise ValueError("Supported controls: {}".format(",".join(settings_list))) diff --git a/ceph_iscsi_config/utils.py b/ceph_iscsi_config/utils.py index 8406b116..1d1a07a6 100644 --- a/ceph_iscsi_config/utils.py +++ b/ceph_iscsi_config/utils.py @@ -407,7 +407,7 @@ def gen_control_string(controls): :return: control string (str) """ control = '' - for key, value in controls.iteritems(): + for key, value in controls.items(): if value is not None: control += "{}={},".format(key, value) return None if control == '' else control[:-1] diff --git a/gwcli/ceph.py b/gwcli/ceph.py index 78b5f224..0aa9d7e1 100644 --- a/gwcli/ceph.py +++ b/gwcli/ceph.py @@ -190,7 +190,7 @@ def cluster_version(self): vers_out = os_cmd("ceph -c {} version".format(self.conf)) # RHEL packages include additional info, that we don't need - version_str = vers_out.split()[2] + version_str = vers_out.split()[2].decode('utf-8') return '.'.join(version_str.split('.')[:3]) def update_state(self): diff --git a/gwcli/client.py b/gwcli/client.py index 3f1246fc..5876e7db 100644 --- a/gwcli/client.py +++ b/gwcli/client.py @@ -45,7 +45,7 @@ def __init__(self, parent): % (self.path, 'hosts')) def load(self, client_info): - for client_iqn, client_settings in client_info.iteritems(): + for client_iqn, client_settings in client_info.items(): Client(self, client_iqn, client_settings) def ui_command_create(self, client_iqn): @@ -254,7 +254,7 @@ def __init__(self, parent, client_iqn, client_settings): self.ip_address = '' self.alias = '' - for k, v in client_settings.iteritems(): + for k, v in client_settings.items(): self.__setattr__(k, v) # decode the password if necessary diff --git a/gwcli/gateway.py b/gwcli/gateway.py index 3b6ddf93..9c8d5ab5 100644 --- a/gwcli/gateway.py +++ b/gwcli/gateway.py @@ -718,7 +718,7 @@ def __init__(self, parent, gateway_name, gateway_config): UINode.__init__(self, gateway_name, parent) - for k, v in gateway_config.iteritems(): + for k, v in gateway_config.items(): self.__setattr__(k, v) self.state = "DOWN" diff --git a/gwcli/storage.py b/gwcli/storage.py index 6ec9d922..d3c8471a 100644 --- a/gwcli/storage.py +++ b/gwcli/storage.py @@ -2,7 +2,10 @@ import json import time -import Queue +try: + import Queue +except ImportError: + import queue as Queue import threading import rados import rbd @@ -229,7 +232,7 @@ def ui_command_create(self, pool=None, image=None, size=None, count=1, self.logger.error(err) return - for k, v in controls.iteritems(): + for k, v in controls.items(): if not v: self.logger.error("Missing value for {}.".format(k)) return @@ -591,7 +594,7 @@ def __init__(self, parent, image_id, image_config, size=None, def _apply_config(self, image_config): # set the remaining attributes based on the fields in the dict disk_map = self.parent.disk_info - for k, v in image_config.iteritems(): + for k, v in image_config.items(): disk_map[self.image_id][k] = v self.__setattr__(k, v) for k in LUN.SETTINGS: diff --git a/rbd-target-api.py b/rbd-target-api.py index 39a1fe28..b198c52f 100755 --- a/rbd-target-api.py +++ b/rbd-target-api.py @@ -204,7 +204,7 @@ def parse_target_controls(request): return tpg_controls, client_controls controls = _parse_controls(request.form['controls'], GWTarget.SETTINGS) - for k, v in controls.iteritems(): + for k, v in controls.items(): if k in GWClient.SETTINGS: client_controls[k] = v else: @@ -257,11 +257,11 @@ def target(target_iqn=None): orig_tpg_controls = {} orig_client_controls = {} - for k, v in tpg_controls.iteritems(): + for k, v in tpg_controls.items(): orig_tpg_controls[k] = getattr(target, k) setattr(target, k, v) - for k, v in client_controls.iteritems(): + for k, v in client_controls.items(): orig_client_controls[k] = getattr(target, k) setattr(target, k, v) @@ -324,7 +324,7 @@ def local_target_reconfigure(target_iqn, tpg_controls, client_controls): logger.error("Unable to create an instance of the GWTarget class") return target.error_msg - for k, v in tpg_controls.iteritems(): + for k, v in tpg_controls.items(): setattr(target, k, v) if target.exists(): @@ -358,7 +358,7 @@ def local_target_reconfigure(target_iqn, tpg_controls, client_controls): client_errors = True continue - for k, v in client_controls.iteritems(): + for k, v in client_controls.items(): setattr(client, k, v) client.manage('reconfigure') @@ -830,7 +830,7 @@ def _disk(image_id): " : {}".format(lun.error_msg)) return jsonify(message="Unable to establish LUN instance"), 500 - for k, v in controls.iteritems(): + for k, v in controls.items(): setattr(lun, k, v) if mode == 'create' and len(config.config['disks']) >= 256: @@ -889,7 +889,7 @@ def _disk(image_id): return jsonify(message="LUN deactivated"), 200 elif mode == 'activate': - for k, v in controls.iteritems(): + for k, v in controls.items(): setattr(lun, k, v) try: @@ -968,7 +968,7 @@ def lun_reconfigure(image_id, controls): lun = LUN(logger, pool_name, image_name, size, disk['owner']) - for k, v in controls.iteritems(): + for k, v in controls.items(): setattr(lun, k, v) try: @@ -1306,7 +1306,7 @@ def clientlun(client_iqn): disk = request.form.get('disk') - lun_list = config.config['clients'][client_iqn]['luns'].keys() + lun_list = list(config.config['clients'][client_iqn]['luns'].keys()) if request.method == 'PUT': lun_list.append(disk) diff --git a/rbd-target-gw.py b/rbd-target-gw.py index e5de8b18..b1724734 100755 --- a/rbd-target-gw.py +++ b/rbd-target-gw.py @@ -181,7 +181,7 @@ def osd_blacklist_cleanup(): cleanup_state = False else: - blacklist_output = blacklist.split('\n')[:-1] + blacklist_output = blacklist.decode('utf-8').split('\n')[:-1] if len(blacklist_output) > 1: # We have entries to look for, so first build a list of ipv4