summaryrefslogtreecommitdiffstats
path: root/geo-replication/src/peer_mountbroker.in
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2015-06-25 00:18:01 +0530
committerVijay Bellur <vbellur@redhat.com>2015-06-28 07:48:26 -0700
commit43b173415278eb79f703ca9d9b30cd595cfb41cd (patch)
tree879de77551c853f5c8d8a48e2c41fde5822e20e7 /geo-replication/src/peer_mountbroker.in
parent088711acdaaf8935718171bd79ae053ae8fc3d75 (diff)
geo-rep: Fix add user in mountbroker user management
The CLI 'gluster system:: execute mountbroker user <USERNAME> <VOLUMES>' to set volumes associated with a user replaces existing user and associated volumes upon setting with existing user. This patch fixes it by appending the volumes if the user already exists. It also introduces following CLI to remove volume for a corresponding user. 'gluster system:: execute mountbroker volumedel <USERNAME> <VOLUME>' <USERNAME>: username <VOLUME>: comman separated list of volumes to delete If it is the last volume to be deleted associated with the user, it will delete the user as well as it doesn't make sense to keep only user without volumes associated. Change-Id: I4c7240ce912e1b836794bf0682a5fc6e5b2adc70 BUG: 1235428 Reviewed-On: http://review.gluster.org/11385 Signed-off-by: Kotresh HR <khiremat@redhat.com> Reviewed-on: http://review.gluster.org/11386 Tested-by: NetBSD Build System <jenkins@build.gluster.org> Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Milind Changire <mchangir@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'geo-replication/src/peer_mountbroker.in')
-rw-r--r--geo-replication/src/peer_mountbroker.in34
1 files changed, 33 insertions, 1 deletions
diff --git a/geo-replication/src/peer_mountbroker.in b/geo-replication/src/peer_mountbroker.in
index 4c97c6923c4..8573abdf122 100644
--- a/geo-replication/src/peer_mountbroker.in
+++ b/geo-replication/src/peer_mountbroker.in
@@ -86,8 +86,31 @@ class MountbrokerUserMgmt(object):
del(self._options[key])
def add_user(self, user, volumes):
+ vols = set()
+ for k, v in self._options.iteritems():
+ if k.startswith("mountbroker-geo-replication.") \
+ and user == k.split(".")[-1]:
+ vols.update(v.split(","))
+
+ vols.update(volumes)
self.set_opt("mountbroker-geo-replication.%s" % user,
- ",".join(volumes))
+ ",".join(vols))
+
+ def remove_volume(self, user, volumes):
+ vols = set()
+ for k, v in self._options.iteritems():
+ if k.startswith("mountbroker-geo-replication.") \
+ and user == k.split(".")[-1]:
+ vols.update(v.split(","))
+
+ for v1 in volumes:
+ vols.discard(v1)
+
+ if vols:
+ self.set_opt("mountbroker-geo-replication.%s" % user,
+ ",".join(vols))
+ else:
+ self.remove_opt("mountbroker-geo-replication.%s" % user)
def remove_user(self, user):
self.remove_opt("mountbroker-geo-replication.%s" % user)
@@ -129,6 +152,7 @@ def _get_args():
subparsers = parser.add_subparsers(title='subcommands', dest='cmd')
parser_useradd = subparsers.add_parser('user')
parser_userdel = subparsers.add_parser('userdel')
+ parser_volumedel = subparsers.add_parser('volumedel')
subparsers.add_parser('info')
parser_opt = subparsers.add_parser('opt')
parser_optdel = subparsers.add_parser('optdel')
@@ -137,6 +161,10 @@ def _get_args():
parser_useradd.add_argument('volumes', type=str, default='',
help="Volumes list. ',' seperated")
+ parser_volumedel.add_argument('username', help="Username", type=str)
+ parser_volumedel.add_argument('volumes', type=str, default='',
+ help="Volumes list. ',' seperated")
+
parser_userdel.add_argument('username', help="Username", type=str)
parser_opt.add_argument('opt_name', help="Name", type=str)
@@ -163,6 +191,10 @@ def main():
volumes = [v.strip() for v in args.volumes.split(",")
if v.strip() != ""]
m.add_user(args.username, volumes)
+ elif args.cmd == "volumedel":
+ volumes = [v.strip() for v in args.volumes.split(",")
+ if v.strip() != ""]
+ m.remove_volume(args.username, volumes)
elif args.cmd == "info":
info = m.info()
if not args.json: