summaryrefslogtreecommitdiffstats
path: root/geo-replication
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2015-06-25 00:18:01 +0530
committerVenky Shankar <vshankar@redhat.com>2015-06-26 05:42:08 -0700
commit3925f5cf33df85807db812211552fc16c7850d0d (patch)
treeb3dc923c717c489cf7c5cda6c55acd77be7de982 /geo-replication
parentaee44fccd450ac53421ebe729223ad1921e5f573 (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: I49f4b9279954d9f5d34aca2dd8a69c6f4b87fd19 BUG: 1226223 Signed-off-by: Kotresh HR <khiremat@redhat.com> Reviewed-on: http://review.gluster.org/11385 Reviewed-by: darshan n <dnarayan@redhat.com> Tested-by: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: Aravinda VK <avishwan@redhat.com>
Diffstat (limited to 'geo-replication')
-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: