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>
This commit is contained in:
Kotresh HR 2015-06-25 00:18:01 +05:30 committed by Venky Shankar
parent aee44fccd4
commit 3925f5cf33

View File

@ -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: