forked from dbharris/repoman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
share and unshare images with users and groups
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|