From 146689f27eba9f852d1070ef23db2e65113a78f8 Mon Sep 17 00:00:00 2001 From: Matthew Vliet Date: Mon, 24 Jan 2011 20:08:12 -0800 Subject: [PATCH] share and unshare images with users and groups --- .../repoman_client/subcommands/sharing.py | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 repoman-client/repoman_client/subcommands/sharing.py diff --git a/repoman-client/repoman_client/subcommands/sharing.py b/repoman-client/repoman_client/subcommands/sharing.py new file mode 100644 index 0000000..4b88de9 --- /dev/null +++ b/repoman-client/repoman_client/subcommands/sharing.py @@ -0,0 +1,80 @@ +from repoman_client.subcommand import SubCommand +from repoman_client.client import RepomanClient, RepomanError +from repoman_client.config import config +from argparse import ArgumentParser +import sys + +class ShareImage(SubCommand): + command_group = 'advanced' + command = 'share-image' + alias = None + description = 'Share an image with users or groups' + + def get_parser(self): + p = ArgumentParser(self.description) + p.add_argument('image', help='Image you want to share') + g = p.add_mutually_exclusive_group(required=True) + g.add_argument('-u', '--user', help='User to share with') + g.add_argument('-g', '--group', help='Group to share with') + return p + + def __call__(self, args, extra_args=None): + repo = RepomanClient(config.host, config.port, config.proxy) + status = "Shared image: '%s' with: '%s'" + if args.user: + func = repo.share_with_user + kwargs = {'user':args.user} + status = status % (args.image, args.user) + elif args.group: + func = repo.share_with_group + kwargs = {'group':args.group} + status = status % (args.image, args.group) + else: + kwargs = {} + + + try: + func(args.image, **kwargs) + print "[OK] %s" % status + except RepomanError, e: + print "[FAILED] %s\n\t-%s" % (status, e) + sys.exit(1) + + + +class UnshareImage(SubCommand): + command_group = 'advanced' + command = 'unshare-image' + alias = None + description = 'Remove a share from an image' + + def get_parser(self): + p = ArgumentParser(self.description) + p.add_argument('image', help='Image to unshare') + g = p.add_mutually_exclusive_group() + g.add_argument('-u', '--user', help='User to remove share from') + g.add_argument('-g', '--group', help='Group to remove share from') + #g.add_argument('-a', '--all', help='Remove all shares') + return p + + def __call__(self, args, extra_args=None): + repo = RepomanClient(config.host, config.port, config.proxy) + status = "Unshared image: '%s' with: '%s'" + if args.user: + func = repo.unshare_with_user + kwargs = {'user':args.user} + status = status % (args.image, args.user) + elif args.group: + func = repo.unshare_with_group + kwargs = {'group':args.group} + status = status % (args.image, args.group) + else: + kwargs = {} + + try: + func(args.image, **kwargs) + print "[OK] %s" % status + except RepomanError, e: + print "[FAILED] %s\n\t-%s" % (status, e) + sys.exit(1) +