diff --git a/src/__init__.py b/src/__init__.py index 851fe6d..5d60661 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -1,3 +1,9 @@ +import os +import sys + +from . import peer +from . import volume + class GlusterError(Exception): def __init__(self,value): self.value = value @@ -10,9 +16,5 @@ def __init__(self,value): def _str_(self): return repr(self.value) -import os,sys if not os.geteuid()==0: raise GlusterError("Gluster commands require root permissions.") - -import peer -import volume diff --git a/src/peer/__init__.py b/src/peer/__init__.py index 9bdb899..0e955c7 100644 --- a/src/peer/__init__.py +++ b/src/peer/__init__.py @@ -1,3 +1,3 @@ -from status import status -from probe import probe -from detach import detach +from .status import status +from .probe import probe +from .detach import detach diff --git a/src/peer/detach.py b/src/peer/detach.py index 53a6bc9..2f0e760 100644 --- a/src/peer/detach.py +++ b/src/peer/detach.py @@ -1,4 +1,5 @@ import subprocess + def detach(hostname,remotehost="localhost"): """ Detach ``host`` from the peer group. Failure will raise DetachError or DetachWarning. @@ -12,7 +13,7 @@ def detach(hostname,remotehost="localhost"): "peer", "detach", hostname]) - except subprocess.CalledProcessError,e: + except subprocess.CalledProcessError as e: response = e.output if response[-14:] == " is localhost\n": raise Warning(response) diff --git a/src/peer/probe.py b/src/peer/probe.py index dc21fb1..f65574b 100644 --- a/src/peer/probe.py +++ b/src/peer/probe.py @@ -13,9 +13,9 @@ def probe(hostname,remotehost="localhost"): "probe", host]) if response == "Probe on localhost not needed": - raise ProbeWarning, response + raise ProbeWarning(response) if response[:13] == "Probe on host": - raise ProbeWarning, response + raise ProbeWarning(response) if response[:33] == "Probe returned with unknown errno": - raise ProbeError, response + raise ProbeError(response) return true diff --git a/src/peer/status.py b/src/peer/status.py index 670d44f..d8b82a2 100644 --- a/src/peer/status.py +++ b/src/peer/status.py @@ -1,4 +1,5 @@ -import subprocess,re +import subprocess +import re def status(remotehost="localhost"): """ @@ -18,9 +19,9 @@ def _status(remotehost="localhost",recursion=False): "peer", "status"] try: - response = subprocess.check_output(program,stderr=subprocess.STDOUT).split("\n") - except subprocess.CalledProcessError,e: - print e.output + response = str(subprocess.check_output(program,stderr=subprocess.STDOUT), encoding="utf8").split("\n") + except subprocess.CalledProcessError as e: + print(e.output) raise # step through the output and build the dict @@ -43,13 +44,13 @@ def _status(remotehost="localhost",recursion=False): # our first pass through if not recursion: remotehost = [x for x in - _status(remotehost=peerstatus["host"].keys()[0],recursion=True)["host"].keys() - if x not in peerstatus["host"].keys()][0] + list(_status(remotehost=list(peerstatus["host"].keys())[0],recursion=True)["host"].keys()) + if x not in list(peerstatus["host"].keys())][0] peerstatus["host"][remotehost] = {} peerstatus["host"][remotehost]["self"] = True - peerstatus["host"][remotehost]["uuid"] = _status(remotehost=peerstatus["host"].keys()[0],recursion=True)["host"][remotehost]["uuid"] + peerstatus["host"][remotehost]["uuid"] = _status(remotehost=list(peerstatus["host"].keys())[0],recursion=True)["host"][hostname]["uuid"] peerstatus["host"][remotehost]["state"] = {} - for host in peerstatus["host"].keys(): + for host in list(peerstatus["host"].keys()): remotestatus = _status(host,recursion=True) for statehost in remotestatus["host"]: for state in remotestatus["host"][statehost]["state"]: diff --git a/src/volume/__init__.py b/src/volume/__init__.py index feb6eaf..0a468d7 100644 --- a/src/volume/__init__.py +++ b/src/volume/__init__.py @@ -1,2 +1,2 @@ -from info import info -from create import create +from .info import info +from .create import create diff --git a/src/volume/create.py b/src/volume/create.py index 56c693a..3cc4650 100644 --- a/src/volume/create.py +++ b/src/volume/create.py @@ -1,4 +1,5 @@ -import subprocess,re +import subprocess +import re def create(voldef={},remotehost="localhost"): """ @@ -8,9 +9,9 @@ def create(voldef={},remotehost="localhost"): """ brickdiv = 1 - if not "name" in voldef.keys(): + if not "name" in list(voldef.keys()): raise KeyError("Volume must have a name") - if not "bricks" in voldef.keys(): + if not "bricks" in list(voldef.keys()): raise KeyError("Volume must have bricks") program = ["/usr/sbin/gluster", @@ -19,17 +20,17 @@ def create(voldef={},remotehost="localhost"): "create", voldef["name"], ] - if "stripe" in voldef.keys(): + if "stripe" in list(voldef.keys()): stripe = int(voldef["stripe"]) program.append("stripe") program.append(str(stripe)) brickdiv = stripe - if "replica" in voldef.keys(): + if "replica" in list(voldef.keys()): replica = int(voldef["replica"]) program.append("replica") program.append(str(replica)) brickdiv = brickdiv * replica - if "transport" in voldef.keys(): + if "transport" in list(voldef.keys()): transport = voldef["transport"] if voldef["transport"] in ("tcp","rdma","tcp,rdma","rdma,tcp") else "tcp" program.append("transport") program.append(transport) @@ -37,7 +38,7 @@ def create(voldef={},remotehost="localhost"): raise KeyError("Invalid brick count. Bricks must be in multiples of %d" % brickdiv) [ program.append(x) for x in voldef["bricks"] ] - response = subprocess.check_output(program).split("\n") + response = str(subprocess.check_output(program), encoding="utf8").split("\n") success = "Creation of volume %s has been successful. Please start the volume to access data." % voldef["name"] if not success in response: raise RuntimeError(response) diff --git a/src/volume/info.py b/src/volume/info.py index 7871bdd..019d070 100644 --- a/src/volume/info.py +++ b/src/volume/info.py @@ -16,9 +16,9 @@ def info(volname="all",remotehost="localhost"): "info", volname] try: - response = subprocess.check_output(program,stderr=subprocess.STDOUT).split("\n") - except subprocess.CalledProcessError,e: - print e.output + response = str(subprocess.check_output(program,stderr=subprocess.STDOUT), encoding="utf-8").split("\n") + except subprocess.CalledProcessError as e: + print(e.output) raise