diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-08-05 18:05:41 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-08-05 18:05:41 +0530 |
| commit | 6f763f83b3f4e8bfef0b8b30648b8d31aa578ddd (patch) | |
| tree | a43f6c616d01fcf46d0dd835e412e58a3ea65e76 /src/com.gluster.storage.management.gateway | |
| parent | f123fb04e292c5ea8c2e9f6867c7010f11148e28 (diff) | |
| parent | 213b34139f55d22d0043d21a48bf83bdd2bef069 (diff) | |
Merge branch 'master' of github.com:gluster/console
Diffstat (limited to 'src/com.gluster.storage.management.gateway')
3 files changed, 90 insertions, 6 deletions
diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py index 02855cd7..f1e899ec 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/add_user_cifs_all.py @@ -18,6 +18,22 @@ defaultUid = 1024000 cifsUserFile = "/opt/glustermg/etc/users.cifs" +def getUid(userName): + try: + fp = open(cifsUserFile) + content = fp.read() + fp.close() + except IOError, e: + Utils.log("failed to read file %s: %s" % (cifsUserFile, str(e))) + return False + + for line in content.strip().split(): + tokens = line.split(":") + if tokens[1] == UserName: + return int(tokens[0]) + return None + + def getLastUid(): if not os.path.exists(cifsUserFile): return defaultUid @@ -55,13 +71,20 @@ def main(): userName = sys.argv[2] password = sys.argv[3] - uid = getLastUid() + existingUser = False + uid = getUid(userName) if not uid: - sys.exit(10) - - uid += 1 + uid = getLastUid() + if not uid: + sys.exit(10) + uid += 1 + else: + existingUser = True rv = Utils.runCommand("grun.py %s add_user_cifs.py %s %s %s" % (serverFile, uid, userName, password)) + if existingUser: + sys.exit(rv) + if rv == 0: if not setUid(uid, userName): sys.exit(11) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py index 0593257b..9cfe9dcf 100755 --- a/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/get_volume_user_cifs.py @@ -22,7 +22,7 @@ def main(): sys.stderr.write("usage: %s VOLUME_NAME\n" % os.path.basename(sys.argv[0])) sys.exit(-1) - volumeName = sys.argv[2] + volumeName = sys.argv[1] try: fp = open(cifsVolumeFile) @@ -33,7 +33,8 @@ def main(): if tokens[0] == volumeName: print "\n".join(tokens[1:]) sys.exit(0) - sys.exit(1) + # given volume is not configured for cifs export + sys.exit(0) except IOError, e: Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) sys.exit(2) diff --git a/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py new file mode 100755 index 00000000..a4d424b3 --- /dev/null +++ b/src/com.gluster.storage.management.gateway/WebContent/scripts/update_volume_cifs_all.py @@ -0,0 +1,60 @@ +#!/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 + + +cifsVolumeFile = "/opt/glustermg/etc/volumes.cifs" + + +def updateVolumeCifsConf(volumeName, userList): + try: + fp = open(cifsVolumeFile) + content = fp.read() + fp.close() + except IOError, e: + Utils.log("failed to read file %s: %s" % (cifsVolumeFile, str(e))) + return False + + try: + fp = open(cifsVolumeFile, "w") + for line in content.split(): + if line.split(":")[0] == volumeName: + fp.write("%s:%s\n" % (volumeName, ":".join(userList))) + else: + fp.write("%s\n" % line) + fp.close() + except IOError, e: + Utils.log("failed to write file %s: %s" % (cifsVolumeFile, str(e))) + return False + return True + + +def main(): + if len(sys.argv) < 4: + sys.stderr.write("usage: %s SERVER_FILE VOLUME_NAME USER1 USER2 ...\n" % os.path.basename(sys.argv[0])) + sys.exit(-1) + + serverFile = sys.argv[1] + volumeName = sys.argv[2] + userList = sys.argv[3:] + + rv = Utils.runCommand(["grun.py", serverFile, "update_volume_cifs.py", volumeName] + userList) + if rv == 0: + if not updateVolumeCifsConf(volumeName, userList): + sys.exit(11) + sys.exit(rv) + + +if __name__ == "__main__": + main() |
