Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Python3 #2

Merged
merged 1 commit into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ceph_iscsi_config/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions ceph_iscsi_config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ceph_iscsi_config/lun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions ceph_iscsi_config/settings.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))

Expand Down
2 changes: 1 addition & 1 deletion ceph_iscsi_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion gwcli/ceph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions gwcli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gwcli/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions gwcli/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions rbd-target-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion rbd-target-gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down