|
|
cb8e9e |
From c7eb7af261214e058f94af4f99eba5a8299d43ce Mon Sep 17 00:00:00 2001
|
|
|
cb8e9e |
From: Kotresh HR <khiremat@redhat.com>
|
|
|
cb8e9e |
Date: Thu, 25 Jun 2015 00:18:01 +0530
|
|
|
cb8e9e |
Subject: [PATCH 161/190] geo-rep: Fix add user in mountbroker user management
|
|
|
cb8e9e |
|
|
|
cb8e9e |
The CLI 'gluster system:: execute mountbroker user <USERNAME> <VOLUMES>'
|
|
|
cb8e9e |
to set volumes associated with a user replaces existing user and associated
|
|
|
cb8e9e |
volumes upon setting with existing user. This patch fixes it by appending
|
|
|
cb8e9e |
the volumes if the user already exists.
|
|
|
cb8e9e |
|
|
|
cb8e9e |
It also introduces following CLI to remove volume for a corresponding user.
|
|
|
cb8e9e |
|
|
|
cb8e9e |
'gluster system:: execute mountbroker volumedel <USERNAME> <VOLUME>'
|
|
|
cb8e9e |
<USERNAME>: username
|
|
|
cb8e9e |
<VOLUME>: comman separated list of volumes to delete
|
|
|
cb8e9e |
|
|
|
cb8e9e |
If it is the last volume to be deleted associated with the user,
|
|
|
cb8e9e |
it will delete the user as well as it doesn't make sense to keep
|
|
|
cb8e9e |
only user without volumes associated.
|
|
|
cb8e9e |
|
|
|
cb8e9e |
BUG: 1234869
|
|
|
cb8e9e |
Change-Id: Ib60ef07b5fc2b4a4010bea6641fe7475b1497244
|
|
|
cb8e9e |
Reviewed-On: http://review.gluster.org/11385
|
|
|
cb8e9e |
Reviewed-On: http://review.gluster.org/11386
|
|
|
cb8e9e |
Signed-off-by: Kotresh HR <khiremat@redhat.com>
|
|
|
cb8e9e |
Reviewed-on: https://code.engineering.redhat.com/gerrit/51611
|
|
|
cb8e9e |
Reviewed-by: Venky Shankar <vshankar@redhat.com>
|
|
|
cb8e9e |
Tested-by: Venky Shankar <vshankar@redhat.com>
|
|
|
cb8e9e |
---
|
|
|
cb8e9e |
geo-replication/src/peer_mountbroker.in | 34 ++++++++++++++++++++++++++++++-
|
|
|
cb8e9e |
1 files changed, 33 insertions(+), 1 deletions(-)
|
|
|
cb8e9e |
|
|
|
cb8e9e |
diff --git a/geo-replication/src/peer_mountbroker.in b/geo-replication/src/peer_mountbroker.in
|
|
|
cb8e9e |
index 4c97c69..8573abd 100644
|
|
|
cb8e9e |
--- a/geo-replication/src/peer_mountbroker.in
|
|
|
cb8e9e |
+++ b/geo-replication/src/peer_mountbroker.in
|
|
|
cb8e9e |
@@ -86,8 +86,31 @@ class MountbrokerUserMgmt(object):
|
|
|
cb8e9e |
del(self._options[key])
|
|
|
cb8e9e |
|
|
|
cb8e9e |
def add_user(self, user, volumes):
|
|
|
cb8e9e |
+ vols = set()
|
|
|
cb8e9e |
+ for k, v in self._options.iteritems():
|
|
|
cb8e9e |
+ if k.startswith("mountbroker-geo-replication.") \
|
|
|
cb8e9e |
+ and user == k.split(".")[-1]:
|
|
|
cb8e9e |
+ vols.update(v.split(","))
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ vols.update(volumes)
|
|
|
cb8e9e |
self.set_opt("mountbroker-geo-replication.%s" % user,
|
|
|
cb8e9e |
- ",".join(volumes))
|
|
|
cb8e9e |
+ ",".join(vols))
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ def remove_volume(self, user, volumes):
|
|
|
cb8e9e |
+ vols = set()
|
|
|
cb8e9e |
+ for k, v in self._options.iteritems():
|
|
|
cb8e9e |
+ if k.startswith("mountbroker-geo-replication.") \
|
|
|
cb8e9e |
+ and user == k.split(".")[-1]:
|
|
|
cb8e9e |
+ vols.update(v.split(","))
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ for v1 in volumes:
|
|
|
cb8e9e |
+ vols.discard(v1)
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
+ if vols:
|
|
|
cb8e9e |
+ self.set_opt("mountbroker-geo-replication.%s" % user,
|
|
|
cb8e9e |
+ ",".join(vols))
|
|
|
cb8e9e |
+ else:
|
|
|
cb8e9e |
+ self.remove_opt("mountbroker-geo-replication.%s" % user)
|
|
|
cb8e9e |
|
|
|
cb8e9e |
def remove_user(self, user):
|
|
|
cb8e9e |
self.remove_opt("mountbroker-geo-replication.%s" % user)
|
|
|
cb8e9e |
@@ -129,6 +152,7 @@ def _get_args():
|
|
|
cb8e9e |
subparsers = parser.add_subparsers(title='subcommands', dest='cmd')
|
|
|
cb8e9e |
parser_useradd = subparsers.add_parser('user')
|
|
|
cb8e9e |
parser_userdel = subparsers.add_parser('userdel')
|
|
|
cb8e9e |
+ parser_volumedel = subparsers.add_parser('volumedel')
|
|
|
cb8e9e |
subparsers.add_parser('info')
|
|
|
cb8e9e |
parser_opt = subparsers.add_parser('opt')
|
|
|
cb8e9e |
parser_optdel = subparsers.add_parser('optdel')
|
|
|
cb8e9e |
@@ -137,6 +161,10 @@ def _get_args():
|
|
|
cb8e9e |
parser_useradd.add_argument('volumes', type=str, default='',
|
|
|
cb8e9e |
help="Volumes list. ',' seperated")
|
|
|
cb8e9e |
|
|
|
cb8e9e |
+ parser_volumedel.add_argument('username', help="Username", type=str)
|
|
|
cb8e9e |
+ parser_volumedel.add_argument('volumes', type=str, default='',
|
|
|
cb8e9e |
+ help="Volumes list. ',' seperated")
|
|
|
cb8e9e |
+
|
|
|
cb8e9e |
parser_userdel.add_argument('username', help="Username", type=str)
|
|
|
cb8e9e |
|
|
|
cb8e9e |
parser_opt.add_argument('opt_name', help="Name", type=str)
|
|
|
cb8e9e |
@@ -163,6 +191,10 @@ def main():
|
|
|
cb8e9e |
volumes = [v.strip() for v in args.volumes.split(",")
|
|
|
cb8e9e |
if v.strip() != ""]
|
|
|
cb8e9e |
m.add_user(args.username, volumes)
|
|
|
cb8e9e |
+ elif args.cmd == "volumedel":
|
|
|
cb8e9e |
+ volumes = [v.strip() for v in args.volumes.split(",")
|
|
|
cb8e9e |
+ if v.strip() != ""]
|
|
|
cb8e9e |
+ m.remove_volume(args.username, volumes)
|
|
|
cb8e9e |
elif args.cmd == "info":
|
|
|
cb8e9e |
info = m.info()
|
|
|
cb8e9e |
if not args.json:
|
|
|
cb8e9e |
--
|
|
|
cb8e9e |
1.7.1
|
|
|
cb8e9e |
|