summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTim <timothyasir@gluster.com>2011-09-23 11:29:58 +0530
committerTim <timothyasir@gluster.com>2011-09-23 13:58:03 +0530
commitce25dff2c1d6df5690ff2e22a6e7c0628d9a6b8c (patch)
tree9f6b762b682aaf73477daa659de9da5304e6b7ae /src
parent8edb51930080dfeb9ce08dff83f9db7f0a067771 (diff)
Removed grun.py and added grun() function into Utils.py
Diffstat (limited to 'src')
-rw-r--r--src/com.gluster.storage.management.gateway.scripts/src/common/Utils.py26
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/add_user_cifs_all.py2
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/create_volume_cifs_all.py2
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/delete_user_cifs_all.py6
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/delete_volume_cifs_all.py2
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/grun.py48
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/remove_server_volume_cifs_config.py4
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/setup_cifs_config_all.py2
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/gateway/update_volume_cifs_all.py3
9 files changed, 35 insertions, 60 deletions
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/common/Utils.py b/src/com.gluster.storage.management.gateway.scripts/src/common/Utils.py
index c7bb2f2b..9a17ba7b 100644
--- a/src/com.gluster.storage.management.gateway.scripts/src/common/Utils.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/common/Utils.py
@@ -24,7 +24,11 @@ SYSLOG_REQUIRED = False
LOG_FILE_NAME = None
LOG_FILE_OBJ = None
logOpened = False
-
+sshCommandPrefix = "ssh -l root -q -i /opt/glustermg/keys/gluster.pem -o BatchMode=yes -o GSSAPIAuthentication=no -o PasswordAuthentication=no -o StrictHostKeyChecking=no".split()
+try:
+ commandPath = "/opt/glustermg/%s/backend" % os.environ['GMG_VERSION']
+except KeyError, e:
+ commandPath = "/opt/glustermg/1.0.0/backend"
def log(priority, message=None):
global logOpened
@@ -299,3 +303,23 @@ def getCifsUserUid(userName):
if tokens[1] == userName:
return int(tokens[0])
return None
+
+def grun(serverFile, command, argumentList=[]):
+ commandList = ["%s/%s" % (commandPath, command)] + argumentList
+ serverNameList = Utils.readFile(serverFile, lines=True)
+ if not serverNameList:
+ return 1
+ status = True
+ for serverName in serverNameList:
+ rv = runCommand(sshCommandPrefix + [serverName.strip()] + commandList, output=True)
+ if rv["Status"] != 0:
+ sys.stderr.write("%s: %s\n" % (serverName, rv["Status"]))
+ sys.stderr.write("Stdout:\n%s\n" % rv["Stdout"])
+ sys.stderr.write("Stderr:\n%s\n" % rv["Stderr"])
+ sys.stderr.write("---\n")
+ status = False
+
+ if status:
+ return 0
+ else:
+ return 2
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/add_user_cifs_all.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/add_user_cifs_all.py
index 9c6329c7..adfd031c 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/add_user_cifs_all.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/gateway/add_user_cifs_all.py
@@ -63,7 +63,7 @@ def main():
existingUser = True
print (serverFile, uid, userName, password)
- rv = Utils.runCommand("grun.py %s add_user_cifs.py %s %s %s" % (serverFile, uid, userName, password))
+ rv = Utils.grun(serverFile, "add_user_cifs.py", [uid, userName, password])
if existingUser:
sys.exit(rv)
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/create_volume_cifs_all.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/create_volume_cifs_all.py
index 7186283c..8a43e7dc 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/create_volume_cifs_all.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/gateway/create_volume_cifs_all.py
@@ -50,7 +50,7 @@ def main():
sys.stderr.write("User %s does not exists\n" % missingUserList)
sys.exit(1)
- rv = Utils.runCommand(["grun.py", serverFile, "create_volume_cifs.py", volumeName] + userList)
+ rv = Utils.grun(serverFile, "create_volume_cifs.py", [volumeName] + userList)
if rv == 0:
if not addVolumeCifsConf(volumeName, userList):
sys.stderr.write("Failed to add volume %s and user-list %s in cifs volume configuration\n" % (volumeName, userList))
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_user_cifs_all.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_user_cifs_all.py
index cf49ed5c..a86e7264 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_user_cifs_all.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_user_cifs_all.py
@@ -34,13 +34,13 @@ def removeUser(userName):
def main():
if len(sys.argv) < 3:
- sys.stderr.write("usage: %s SERVER_LIST USERNAME\n" % os.path.basename(sys.argv[0]))
+ sys.stderr.write("usage: %s SERVER_FILE USERNAME\n" % os.path.basename(sys.argv[0]))
sys.exit(-1)
- serverList = sys.argv[1]
+ serverFile = sys.argv[1]
userName = sys.argv[2]
- rv = Utils.runCommand("grun.py %s delete_user_cifs.py %s" % (serverList, userName))
+ rv = Utils.grun(serverFile, "delete_user_cifs.py", [userName])
if rv == 0:
if not removeUser(userName):
Utils.log("Failed to remove the user:%s on gateway server\n" % userName)
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_volume_cifs_all.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_volume_cifs_all.py
index 71a7612b..925a3548 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_volume_cifs_all.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/gateway/delete_volume_cifs_all.py
@@ -39,7 +39,7 @@ def main():
serverFile = sys.argv[1]
volumeName = sys.argv[2]
- rv = Utils.runCommand(["grun.py", serverFile, "delete_volume_cifs.py", volumeName])
+ rv = Utils.grun(serverFile, "delete_volume_cifs.py", [volumeName])
if rv == 0:
if not removeVolumeCifsConf(volumeName):
sys.stderr.write("Failed to remove volume %s and user-list in cifs volume configuration\n" % volumeName)
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/grun.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/grun.py
deleted file mode 100755
index f91a07df..00000000
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/grun.py
+++ /dev/null
@@ -1,48 +0,0 @@
-#!/usr/bin/python
-# Copyright (C) 2011 Gluster, Inc. <http://www.gluster.com>
-# This file is part of Gluster Management Gateway.
-#
-
-import os
-import sys
-p1 = os.path.abspath(os.path.dirname(sys.argv[0]))
-p2 = "%s/common" % os.path.dirname(p1)
-if not p1 in sys.path:
- sys.path.append(p1)
-if not p2 in sys.path:
- sys.path.append(p2)
-import Utils
-
-
-def main():
- sshCommandPrefix = "ssh -l root -q -i /opt/glustermg/keys/gluster.pem -o BatchMode=yes -o GSSAPIAuthentication=no -o PasswordAuthentication=no -o StrictHostKeyChecking=no".split()
-
- if len(sys.argv) < 3:
- sys.stderr.write("usage: %s SERVER_FILE COMMAND [ARGUMENTS]\n" % os.path.basename(sys.argv[0]))
- sys.exit(-1)
- serverFile = sys.argv[1]
- try:
- command = ["/opt/glustermg/%s/backend/%s" % (os.environ['GMG_VERSION'], sys.argv[2])]
- except KeyError, e:
- command = ["/opt/glustermg/1.0.0/backend/%s" % sys.argv[2]]
- command += sys.argv[3:]
-
- serverNameList = Utils.readFile(serverFile, lines=True)
- status = True
- for serverName in serverNameList:
- rv = Utils.runCommand(sshCommandPrefix + [serverName.strip()] + command, output=True)
- if rv["Status"] != 0:
- sys.stderr.write("%s: %s\n" % (serverName, rv["Status"]))
- sys.stderr.write("Stdout:\n%s\n" % rv["Stdout"])
- sys.stderr.write("Stderr:\n%s\n" % rv["Stderr"])
- sys.stderr.write("---\n")
- status = False
-
- if status:
- sys.exit(0)
- else:
- sys.exit(2)
-
-
-if __name__ == "__main__":
- main()
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/remove_server_volume_cifs_config.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/remove_server_volume_cifs_config.py
index 97491312..27fb9b92 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/remove_server_volume_cifs_config.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/gateway/remove_server_volume_cifs_config.py
@@ -47,9 +47,9 @@ def main():
status = True
for volumeName in runningCifsVolumeList:
- if Utils.runCommand(["grun.py", tempFileName, "stop_volume_cifs.py", volumeName.strip()]) != 0:
+ if Utils.grun(tempFileName, "stop_volume_cifs.py", [volumeName.strip()]) != 0:
status = False
- if Utils.runCommand(["grun.py", tempFileName, "delete_volume_cifs.py", volumeName.strip()]) != 0:
+ if Utils.grun(tempFileName, "delete_volume_cifs.py", [volumeName.strip()]) != 0:
status = False
try:
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/setup_cifs_config_all.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/setup_cifs_config_all.py
index 8dd59c8c..e7e0a4a0 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/setup_cifs_config_all.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/gateway/setup_cifs_config_all.py
@@ -21,7 +21,7 @@ def main():
serverFile = sys.argv[1]
- rv = Utils.runCommand(["grun.py", serverFile, "setup_cifs_config.py"])
+ rv = Utils.grun(serverFile, "setup_cifs_config.py")
sys.exit(rv)
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/gateway/update_volume_cifs_all.py b/src/com.gluster.storage.management.gateway.scripts/src/gateway/update_volume_cifs_all.py
index 095ec0f7..e5576c45 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/gateway/update_volume_cifs_all.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/gateway/update_volume_cifs_all.py
@@ -51,8 +51,7 @@ def main():
sys.stderr.write("User %s does not exists\n" % missingUserList)
sys.exit(1)
-
- rv = Utils.runCommand(["grun.py", serverFile, "update_volume_cifs.py", volumeName] + userList)
+ rv = Utils.grun(serverFile, "update_volume_cifs.py", [volumeName] + userList)
if rv == 0:
if not updateVolumeCifsConf(volumeName, userList):
sys.stderr.write("Failed to update volume %s and user-list %s in cifs volume configuration\n" % (volumeName, userList))