Skip to content

Commit

Permalink
share and unshare images with users and groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mvliet committed Jan 25, 2011
1 parent 8608b69 commit 146689f
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions repoman-client/repoman_client/subcommands/sharing.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 146689f

Please sign in to comment.