def action_pull(): '''the fetch view to perform the pull, and return a response ''' # Ensure uri appears once container = request.args.get('q') uri = request.args.get('uri') container = '%s%s' % (uri, container.replace(uri, '')) print(container) # Make sure we use the right client os.environ['SREGISTRY_CLIENT'] = uri.replace('://', '') os.environ.putenv('SREGISTRY_CLIENT', uri.replace('://', '')) from sregistry.main import get_client client = get_client(image=container) print(client.client_name) try: image_file = client.pull(container, force=True) except: image_file = '''ERROR: manifest unknown, or pull error. Use docker-compose logs web to see issue!''' return Response(image_file, mimetype='text/plain')
def action_pull(): '''the fetch view to perform the pull, and return a response ''' # Ensure uri appears once container = request.form.get('uri') # ubuntu:latest uri = request.form.get('endpoint') # docker:// container = '%s%s' % (uri, container.replace(uri, '')) app.logger.info("PULL for %s" % container) # If nvidia is used, use sregistry client if 'nvidia' in uri: nvidia = app.sregistry._get_setting('SREGISTRY_NVIDIA_TOKEN') # Make sure we use the right client os.environ['SREGISTRY_CLIENT'] = uri.replace('://', '') os.environ.putenv('SREGISTRY_CLIENT', uri.replace('://', '')) from sregistry.main import get_client client = get_client(image=container) app.logger.info("Using client %s" % client.client_name) try: puller = client.pull(container, force=True) except: puller = '''ERROR: manifest unknown, or pull error. Use docker-compose logs web to see issue!''' else: # We will stream the response back! image, puller = Client.pull(container, stream=True, pull_folder='/tmp') puller = itertools.chain(puller, [image]) return Response(puller, mimetype='text/plain')
def main(args, parser, subparser): from sregistry.main import get_client, Client as cli # Does the user want to save the image? do_save = True if args.nocache is True or not hasattr(cli, 'storage'): do_save = False images = args.image if not isinstance(images, list): images = [images] # if the user has given more than one image, not allowed to name name = args.name if len(images) > 1: name = None for image in images: # Customize client based on uri cli = get_client(image, quiet=args.quiet) cli.announce(args.command) response = cli.pull(images=image, file_name=name, force=args.force, save=do_save)
def main(args, parser, extra): from sregistry.main import get_client if args.name is None: msg = "You must add the --name of a container uri to build." bot.exit(msg) cli = get_client(image=args.name, quiet=args.quiet) cli.announce(args.command) # If the client doesn't have the command, exit if not hasattr(cli, "build"): msg = "build is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) # Singularity Registry Server uses build with a recipe if cli.client_name == "google-build": response = run_google_build(cli, args) elif cli.client_name == "google-storage": response = run_compute_build(cli, args) # Currently allows for google_build else: bot.warning( "No URI specified, assuming Singularity Registry with Builder") response = run_registry_build(cli, args, extra) # If the client wants to preview, the config is returned if args.preview: print(json.dumps(response, indent=4, sort_keys=True))
def main(args, parser, extra): lookup = { 'ipython': ipython, 'python': python, 'bpython': bpython } shells = ['ipython', 'python', 'bpython'] # If the user supplies a client choice, make into a uri if args.endpoint is not None: if not args.endpoint.endswith('://'): args.endpoint = '%s://' %args.endpoint from sregistry.main import get_client cli = get_client(args.endpoint, quiet=args.quiet) # If the user asked for a specific shell via environment shell = cli._get_and_update_setting('SREGISTRY_SHELL') if shell is not None: shell = shell.lower() if shell in lookup: try: return lookup[shell](args) except ImportError: pass # Otherwise present order of liklihood to have on system for shell in shells: try: return lookup[shell](args) except ImportError: pass
def main(args, parser, subparser): from sregistry.main import get_client for image in args.image: cli = get_client(image, quiet=args.quiet) cli.announce(args.command) response = cli.remove(image=image, force=args.force)
def init_globus_client(): '''return a globus client with an up to date credential, or update. If the token isn't updated, the user will be prompted to issue a command to the container to do so. ''' if not hasattr(app, 'globus_client'): app.globus_client = get_client('globus://')
def instances(args): '''list running instances for a user, including all builders and report instance names and statuses. ''' from sregistry.main import get_client cli = get_client(quiet=args.quiet) cli.list_builders() sys.exit(0)
def bpython(args): import bpython from sregistry.main import get_client client = get_client(args.endpoint) client.announce(args.command) from sregistry.database.models import Container, Collection bpython.embed(locals_={'client': cli, 'Container': Container, 'Collection': Collection})
def python(args): import code from sregistry.main import get_client client = get_client(args.endpoint) client.announce(args.command) from sregistry.database.models import Container, Collection code.interact(local={"client":cli, 'Container': Container, 'Collection': Collection})
def ipython(args): '''give the user an ipython shell, optionally with an endpoint of choice. ''' # The client will announce itself (backend/database) unless it's get from sregistry.main import get_client client = get_client(args.endpoint) client.announce(args.command) from IPython import embed embed()
def kill(args): '''kill is a helper function to call the "kill" function of the client, meaning we bring down an instance. ''' from sregistry.main import get_client cli = get_client(quiet=args.quiet) if len(args.commands) > 0: for name in args.commands: cli.destroy(name) sys.exit(0)
def main(args, parser, subparser): from sregistry.main import get_client images = args.query if not isinstance(images, list): images = [images] cli = get_client(quiet=args.quiet) for image in images: cli.inspect(image)
def main(args, parser, extra): from sregistry.main import get_client cli = get_client(quiet=args.quiet) # If the client doesn't have the command, exit if not hasattr(cli, 'label_search'): msg = "label search is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) return cli.label_search(key=args.key, value=args.value)
def main(args, parser, subparser): from sregistry.main import get_client images = args.image if not isinstance(images, list): images = [images] for image in images: cli = get_client(image, quiet=args.quiet) cli.add(image_path=image, image_uri=args.name, copy=args.copy)
def main(args, parser, extra): from sregistry.main import get_client cli = get_client(debug=args.debug, quiet=args.quiet) cli.announce(args.command) if not hasattr(cli, 'rename'): msg = "rename is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) cli.rename(image_name=args.name, path=args.path)
def main(args,parser,subparser): '''the images entrypoint is intended to list images locally in the user database, optionally taking one or more query string to subset the search ''' from sregistry.main import get_client cli = get_client(quiet=args.quiet) for query in args.query: if query in ['','*']: query = None cli.images(query=query)
def main(args, parser, extra): from sregistry.main import get_client cli = get_client(quiet=args.quiet) cli.announce(args.command) # If the client doesn't have the command, exit if not hasattr(cli, 'mv'): msg = "move is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) cli.mv(image_name=args.name, path=args.path)
def main(args, parser, subparser): '''the list command corresponds with listing images for an external resource. This is different from listing images that are local to the database, which should be done with "images" ''' from sregistry.main import get_client cli = get_client(quiet=args.quiet) for query in args.query: if query in ['', '*']: query = None cli.ls(query=query)
def main(args, parser, extra): from sregistry.main import get_client image = args.image cli = get_client(image, quiet=args.quiet) # If the client doesn't have the command, exit if not hasattr(cli, "add"): bot.exit("add is only available when using the database") cli.add(image_path=image, image_uri=args.name, copy=args.copy)
def main(args, parser, extra): from sregistry.main import get_client image = args.query cli = get_client(image, quiet=args.quiet) # If the client doesn't have the command, exit if not hasattr(cli, 'get'): bot.exit("get for images requires using the sqlite database.") path = cli.get(image) if path is None: bot.exit("image {} not found in database".format(image))
def main(args, parser, subparser): from sregistry.main import get_client for query in args.query: if query in ['', '*']: query = None try: cli = get_client(query, args.quiet) cli.announce(args.command) cli.search(query=query, args=args) except NotImplementedError: bot.info('Search is not available for this endpoint.')
def main(args, parser, extra): from sregistry.main import get_client image = args.query cli = get_client(image, quiet=args.quiet) # If the client doesn't have the command, exit if not hasattr(cli, "inspect"): msg = "inspect is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) cli.inspect(image)
def main(args, parser, extra): from sregistry.main import get_client image = args.image cli = get_client(image, quiet=args.quiet) cli.announce(args.command) # If the client doesn't have the command, exit if not hasattr(cli, "delete"): msg = "delete is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) cli.delete(image=image, force=args.force)
def list_logs(args, container_name=None): '''list a specific log for a builder, or the latest log if none provided Parameters ========== args: the argparse object to look for a container name container_name: a default container name set to be None (show latest log) ''' from sregistry.main import get_client cli = get_client(quiet=args.quiet) if args.commands: container_name = args.commands.pop(0) cli.logs(container_name) sys.exit(0)
def main(args, parser, subparser): from sregistry.main import get_client # Does the user have a valid image? image = args.image[0] if not os.path.exists(image): subparser.print_help() bot.error("Please supply one or more paths to existing images.") sys.exit(1) # Authenticate cli = get_client(args.name, quiet=args.quiet) cli.announce(args.command) response = cli.push(path=image, name=args.name, tag=args.tag)
def main(args, parser, extra): '''the images entrypoint is intended to list images locally in the user database, optionally taking one or more query string to subset the search ''' from sregistry.main import get_client cli = get_client(quiet=args.quiet) # If the client doesn't have the command, exit if not hasattr(cli, 'images'): bot.exit("listing images requires using the sqlite database.") for query in args.query: if query in ['', '*']: query = None cli.images(query=query)
def main(args, parser, extra): from sregistry.main import get_client image = args.image cli = get_client(image, quiet=args.quiet) cli.announce(args.command) if not hasattr(cli, 'rm'): msg = "remove is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) result = cli.rm(image) if result is None: bot.exit("No {} record found in the database".format(image))
def main(args, parser, subparser): '''sharing an image means sending a remote share from an image you control to a contact, usually an email. ''' from sregistry.main import get_client images = args.image if not isinstance(images, list): images = [images] for image in images: print(image) # Detect any uri, and refresh client if necessary cli = get_client(image, quiet=args.quiet) cli.announce(args.command) cli.share(image, share_to=args.share_to)
def main(args, parser, extra): '''sharing an image means sending a remote share from an image you control to a contact, usually an email. ''' from sregistry.main import get_client image = args.image # Detect any uri, and refresh client if necessary cli = get_client(image, quiet=args.quiet) cli.announce(args.command) # If the client doesn't have the command, exit if not hasattr(cli, 'share'): msg = "share is not implemented for %s. Why don't you add it?" bot.exit(msg % cli.client_name) cli.share(image, share_to=args.share_to)