Skip to content
Open
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
10 changes: 6 additions & 4 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import os
import sys

from . import peer
from . import volume

class GlusterError(Exception):
def __init__(self,value):
self.value = value
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/peer/__init__.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/peer/detach.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess

def detach(hostname,remotehost="localhost"):
"""
Detach ``host`` from the peer group. Failure will raise DetachError or DetachWarning.
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/peer/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 9 additions & 8 deletions src/peer/status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess,re
import subprocess
import re

def status(remotehost="localhost"):
"""
Expand All @@ -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
Expand All @@ -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"]:
Expand Down
4 changes: 2 additions & 2 deletions src/volume/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from info import info
from create import create
from .info import info
from .create import create
15 changes: 8 additions & 7 deletions src/volume/create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess,re
import subprocess
import re

def create(voldef={},remotehost="localhost"):
"""
Expand All @@ -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",
Expand All @@ -19,25 +20,25 @@ 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)
if len(voldef["bricks"]) % brickdiv:
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)
Expand Down
6 changes: 3 additions & 3 deletions src/volume/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down