INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
update secrets will update metadata needed for pull and search | def _update_secrets(self):
'''update secrets will update metadata needed for pull and search
'''
self.token = self._required_get_and_update('SREGISTRY_GITLAB_TOKEN')
self.headers["Private-Token"] = self.token |
since the user needs a job id and other parameters save this for them. | def _get_metadata(self):
'''since the user needs a job id and other parameters, save this
for them.
'''
metadata = {'SREGISTRY_GITLAB_FOLDER': self.artifacts,
'api_base': self.api_base,
'SREGISTRY_GITLAB_BASE': self.base,
'SR... |
starting with an image string in either of the following formats: job_id|collection job_id|collection|job_name Parse the job_name job_id and collection uri from it. If the user provides the first option we use the job_name set by the client ( default is build ). Parameters ========== image: the string to parse with val... | def _parse_image_name(self, image, retry=True):
'''starting with an image string in either of the following formats:
job_id|collection
job_id|collection|job_name
Parse the job_name, job_id, and collection uri from it. If the user
provides the first option, we use th... |
get all settings either for a particular client if a name is provided or across clients. | def get_settings(self, client_name=None):
'''get all settings, either for a particular client if a name is provided,
or across clients.
Parameters
==========
client_name: the client name to return settings for (optional)
'''
settings = read_client_secrets()
if client_name i... |
return a setting from the environment ( first priority ) and then secrets ( second priority ) if one can be found. If not return None. | def get_setting(self, name, default=None):
'''return a setting from the environment (first priority) and then
secrets (second priority) if one can be found. If not, return None.
Parameters
==========
name: they key (index) of the setting to look up
default: (optional) if not foun... |
Look for a setting in the environment ( first priority ) and then the settings file ( second ). If something is found the settings file is updated. The order of operations works as follows: | def get_and_update_setting(self, name, default=None):
'''Look for a setting in the environment (first priority) and then
the settings file (second). If something is found, the settings
file is updated. The order of operations works as follows:
1. The .sregistry settings file is used as a cache... |
a wrapper to get_and_update but if not successful will print an error and exit. | def required_get_and_update(self, name, default=None):
'''a wrapper to get_and_update, but if not successful, will print an
error and exit.
'''
setting = self._get_and_update_setting(name, default=None)
if setting in [None, ""]:
bot.exit('You must export %s' % name)
return setting |
Just update a setting doesn t need to be returned. | def update_setting(self, name, value):
'''Just update a setting, doesn't need to be returned.
'''
if value is not None:
updates = {name : value}
update_client_secrets(backend=self.client_name,
updates=updates) |
use a parsed names dictionary from get_image_name ( above ) to return the path in storage based on the user s preferences | def get_storage_name(self, names, remove_dir=False):
'''use a parsed names dictionary from get_image_name (above) to return
the path in storage based on the user's preferences
Parameters
==========
names: the output from parse_image_name
'''
storage_folder = os.path.dirname(name... |
Authorize a client based on encrypting the payload with the client token which should be matched on the receiving server | def authorize(self, names, payload=None, request_type="push"):
'''Authorize a client based on encrypting the payload with the client
token, which should be matched on the receiving server'''
if self.secrets is not None:
if "registry" in self.secrets:
# Use the payload to generate a... |
push an image to your Storage. If the collection doesn t exist it is created. Parameters ========== path: should correspond to an absolute image path ( or derive it ) name: should be the complete uri that the user has requested to push. tag: should correspond with an image tag. This is provided to mirror Docker | def push(self, path, name, tag=None):
'''push an image to your Storage. If the collection doesn't exist,
it is created.
Parameters
==========
path: should correspond to an absolute image path (or derive it)
name: should be the complete uri that the user has requested to push.
... |
trigger a build on Google Cloud ( storage then compute ) given a name recipe and Github URI where the recipe can be found. Parameters ========== name: should be the complete uri that the user has requested to push. commit: a commit to use not required and can be parsed from URI repo: should correspond to a Github URL o... | def build(self, repo,
config=None,
name=None,
commit=None,
tag="latest",
recipe="Singularity",
preview=False):
'''trigger a build on Google Cloud (storage then compute) given a name
recipe, and Github URI where... |
list builders or instances for the project. They should start with sregistry - builder | def list_builders(self, project=None, zone='us-west1-a'):
'''list builders, or instances for the project. They should start with
sregistry-builder
Parameters
==========
project: specify a project, will default to environment first
zone: the zone to use, defaults to us-west1-a if ... |
list templates in the builder bundle library. If a name is provided look it up | def list_templates(self, name=None):
'''list templates in the builder bundle library. If a name is provided,
look it up
Parameters
==========
name: the name of a template to look up
'''
configs = self._get_templates()
rows = []
# DETAIL: The user wants to retrieve a par... |
list templates in the builder bundle library. If a name is provided look it up | def get_templates(self):
'''list templates in the builder bundle library. If a name is provided,
look it up
'''
base = 'https://singularityhub.github.io/builders'
base = self._get_and_update_setting('SREGISTRY_BUILDER_REPO', base)
base = "%s/configs.json" %base
return self._get(base) |
load a particular template based on a name. We look for a name IN data so the query name can be a partial string of the full name. | def load_templates(self, name):
'''load a particular template based on a name. We look for a name IN data,
so the query name can be a partial string of the full name.
Parameters
==========
name: the name of a template to look up
'''
configs = self._get_templates()
templates ... |
get instances will return the ( unparsed ) list of instances for functions for the user. This is primarily used by get_builders to print a list of builder instances. | def get_instances(self, project=None, zone='us-west1-a'):
'''get instances will return the (unparsed) list of instances, for
functions for the user. This is primarily used by get_builders
to print a list of builder instances.
Parameters
==========
project: specify a project, will... |
get the ip_address of an inserted instance. Will try three times with delay to give the instance time to start up. | def get_ipaddress(self, name, retries=3, delay=3):
'''get the ip_address of an inserted instance. Will try three times with
delay to give the instance time to start up.
Parameters
==========
name: the name of the instance to get the ip address for.
retries: the number of retries ... |
load a google compute config meaning that we have the following cases: | def load_build_config(self, config=None):
'''load a google compute config, meaning that we have the following cases:
1. the user has not provided a config file directly, we look in env.
2. the environment is not set, so we use a reasonable default
3. if the final string is not found as a file,... |
setup the build based on the selected configuration file meaning producing the configuration file filled in based on the user s input Parameters ========== config: the complete configuration file provided by the client template: an optional custom start script to use tag: a user specified tag for the build derived from... | def setup_build(self, name, repo, config, tag=None, commit=None,
recipe="Singularity", startup_script=None):
'''setup the build based on the selected configuration file, meaning
producing the configuration file filled in based on the user's input
Parameters
==========
... |
setconfig will update a lookup to give priority based on the following: 1. If both values are None we set the value to None 2. If the currently set ( the config. json ) is set but not runtime use config 3. If the runtime is set but not config. json we use runtime 4. If both are set we use runtime | def setconfig(lookup, key, value=None):
'''setconfig will update a lookup to give priority based on the following:
1. If both values are None, we set the value to None
2. If the currently set (the config.json) is set but not runtime, use config
3. If the runtime is set but not config.json, we... |
run a build meaning inserting an instance. Retry if there is failure | def run_build(self, config):
'''run a build, meaning inserting an instance. Retry if there is failure
Parameters
==========
config: the configuration dictionary generated by setup_build
'''
project = self._get_project()
zone = self._get_zone()
bot.custom(prefix='INSTANCE', me... |
a show all search that doesn t require a query | def search_all(self):
'''a "show all" search that doesn't require a query'''
results = set()
# Here we get names of collections, and then look up containers
for container in self.conn.get_account()[1]:
# The result here is just the name
for result in self.conn.get_container(container[... |
search for a specific container. This function would likely be similar to the above but have different filter criteria from the user ( based on the query ) | def container_query(self, query):
'''search for a specific container.
This function would likely be similar to the above, but have different
filter criteria from the user (based on the query)
'''
results = set()
query = remove_uri(query)
# Here we get names of collections, and then look u... |
return a list of containers determined by finding the metadata field type with value container. We alert the user to no containers if results is empty and exit | def list_containers(self):
'''return a list of containers, determined by finding the metadata field
"type" with value "container." We alert the user to no containers
if results is empty, and exit
{'metadata': {'items':
[
{'key': 't... |
a list all search that doesn t require a query. Here we return to the user all objects that have custom metadata value of container | def search_all(self):
'''a "list all" search that doesn't require a query. Here we return to
the user all objects that have custom metadata value of "container"
IMPORTANT: the upload function adds this metadata. For a container to
be found by the client, it must have the type as container in m... |
search for a specific container. This function would likely be similar to the above but have different filter criteria from the user ( based on the query ) | def container_query(self, query, quiet=False):
'''search for a specific container.
This function would likely be similar to the above, but have different
filter criteria from the user (based on the query)
'''
results = self._list_containers()
matches = []
for result in results:
... |
a show all search that doesn t require a query | def search_all(self):
'''a "show all" search that doesn't require a query'''
results = []
# Parse through folders (collections):
for entry in self.dbx.files_list_folder('').entries:
# Parse through containers
for item in self.dbx.files_list_folder(entry.path_lower).entries:
... |
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 | 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.quie... |
pull an image from google storage based on the identifier Parameters ========== images: refers to the uri given by the user to pull in the format <collection >/ <namespace >. You should have an API that is able to retrieve a container based on parsing this uri. file_name: the user s requested name for the file. It can ... | def pull(self, images, file_name=None, save=True, **kwargs):
'''pull an image from google storage, based on the identifier
Parameters
==========
images: refers to the uri given by the user to pull in the format
<collection>/<namespace>. You should have an API that is able to
... |
sharing an image means sending a remote share from an image you control to a contact usually an email. | 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:
... |
initialize the database with the default database path or custom of | def init_db(self, db_path):
'''initialize the database, with the default database path or custom of
the format sqlite:////scif/data/expfactory.db
The custom path can be set with the environment variable SREGISTRY_DATABASE
when a user creates the client, we must initialize this db
the database s... |
generate a uri on the fly from database parameters if one is not saved with the initial model ( it should be but might not be possible ) | def get_uri(self):
'''generate a uri on the fly from database parameters if one is not
saved with the initial model (it should be, but might not be possible)
'''
uri = "%s/%s:%s" %(self.collection.name, self.name, self.tag)
if self.version not in [None,'']:
uri = "%s@... |
get default build template. | def get_build_template():
'''get default build template.
'''
base = get_installdir()
name = "%s/main/templates/build/singularity-cloudbuild.json" % base
if os.path.exists(name):
bot.debug("Found template %s" %name)
return read_json(name)
bot.warning("Template %s not found." % n... |
query will show images determined by the extension of img or simg. | def search(self, query=None, args=None):
'''query will show images determined by the extension of img
or simg.
Parameters
==========
query: the container name (path) or uri to search for
args.endpoint: can be an endpoint id and optional path, e.g.:
--endpoint 6881a... |
list all endpoints providing a list of endpoints to the user to better filter the search. This function takes no arguments as the user has not provided an endpoint id or query. | def list_endpoints(self, query=None):
'''list all endpoints, providing a list of endpoints to the user to
better filter the search. This function takes no arguments,
as the user has not provided an endpoint id or query.
'''
bot.info('Please select an endpoint id to query from')
endpoints... |
An endpoint is required here to list files within. Optionally we can take a path relative to the endpoint root. | def list_endpoint(self, endpoint, query=None):
'''An endpoint is required here to list files within. Optionally, we can
take a path relative to the endpoint root.
Parameters
==========
endpoint: a single endpoint ID or an endpoint id and relative path.
If no path is pro... |
share will use the client to get a shareable link for an image of choice. the functions returns a url of choice to send to a recipient. | def share(self, query, share_to=None):
'''share will use the client to get a shareable link for an image of choice.
the functions returns a url of choice to send to a recipient.
'''
names = parse_image_name(remove_uri(query))
# Dropbox path is the path in storage with a slash
dropbox_path =... |
set the API base or default to use Docker Hub. The user is able to set the base api version and protocol via a settings file of environment variables: SREGISTRY_NVIDIA_BASE: defaults to nvcr. io SREGISTRY_NVIDIA_TOKEN: defaults to $oauthtoken SREGISTRY_NVIDIA_VERSION: defaults to v2 SREGISTRY_NVIDIA_NO_HTTPS: defaults ... | def _set_base(self):
'''set the API base or default to use Docker Hub. The user is able
to set the base, api version, and protocol via a settings file
of environment variables:
SREGISTRY_NVIDIA_BASE: defaults to nvcr.io
SREGISTRY_NVIDIA_TOKEN: defaults to $oauthtoke... |
update secrets will take a secrets credential file either located at. sregistry or the environment variable SREGISTRY_CLIENT_SECRETS and update the current client secrets as well as the associated API base. For the case of using Docker Hub if we find a. docker secrets file we update from there. | def _update_secrets(self):
'''update secrets will take a secrets credential file
either located at .sregistry or the environment variable
SREGISTRY_CLIENT_SECRETS and update the current client
secrets as well as the associated API base. For the case of
using Docker H... |
pull an image from a Globus endpoint. The user must have the default local endpoint set up. For example: | def pull(self, images, file_name=None, save=True, **kwargs):
'''pull an image from a Globus endpoint. The user must have the default
local endpoint set up. For example:
6881ae2e-db26-11e5-9772-22000b9da45e:.singularity/shub/sherlock_vep.simg
Parameters
==========
images: refers to the gl... |
if the user has specified settings to provide a cache for credentials files initialize it. The root for the folder is created if it doesn t exist. The path for the specific client is returned and it s not assumed to be either a folder or a file ( this is up to the developer of the client ). | def get_credential_cache():
'''if the user has specified settings to provide a cache for credentials
files, initialize it. The root for the folder is created if it doesn't
exist. The path for the specific client is returned, and it's
not assumed to be either a folder or a file (this is up to th... |
update client secrets will update the data structure for a particular authentication. This should only be used for a ( quasi permanent ) token or similar. The secrets file if found is updated and saved by default. | def update_client_secrets(backend, updates, secrets=None, save=True):
'''update client secrets will update the data structure for a particular
authentication. This should only be used for a (quasi permanent) token
or similar. The secrets file, if found, is updated and saved by default.
'''
if ... |
for private or protected registries a client secrets file is required to be located at. sregistry. If no secrets are found we use default of Singularity Hub and return a dummy secrets. | def read_client_secrets():
'''for private or protected registries, a client secrets file is required
to be located at .sregistry. If no secrets are found, we use default
of Singularity Hub, and return a dummy secrets.
'''
client_secrets = _default_client_secrets()
# If token file not prov... |
init client will check if the user has defined a bucket that differs from the default use the application credentials to get the bucket and then instantiate the client. | def _init_client(self):
'''init client will check if the user has defined a bucket that
differs from the default, use the application credentials to
get the bucket, and then instantiate the client.
'''
# Get storage and compute services
self._get_services()
... |
get version 1 of the google compute and storage service | def _get_services(self, version='v1'):
'''get version 1 of the google compute and storage service
Parameters
==========
version: version to use (default is v1)
'''
self._bucket_service = storage.Client()
creds = GoogleCredentials.get_application_default()
... |
get a bucket based on a bucket name. If it doesn t exist create it. | def _get_bucket(self):
'''get a bucket based on a bucket name. If it doesn't exist, create it.
'''
# Case 1: The bucket already exists
try:
self._bucket = self._bucket_service.get_bucket(self._bucket_name)
# Case 2: The bucket needs to be created
except goog... |
delete object will delete a file from a bucket | def delete_object(service, bucket_name, object_name):
'''delete object will delete a file from a bucket
Parameters
==========
storage_service: the service obtained with get_storage_service
bucket_name: the name of the bucket
object_name: the "name" parameter of the object.
'... |
delete an image from Google Storage. | def delete(self, name):
'''delete an image from Google Storage.
Parameters
==========
name: the name of the file (or image) to delete
'''
bot.debug("DELETE %s" % name)
for file_object in files:
if isinstance(file_object, dict):
if "kind" in file_object:
... |
destroy an instance meaning take down the instance and stop the build. | def destroy(self, name):
'''destroy an instance, meaning take down the instance and stop the build.
Parameters
==========
name: the name of the instance to stop building.
'''
instances = self._get_instances()
project = self._get_project()
zone = self._get_zone()
found = Fa... |
get_subparser will get a dictionary of subparsers to help with printing help | def get_subparsers(parser):
'''get_subparser will get a dictionary of subparsers, to help with printing help
'''
actions = [action for action in parser._actions
if isinstance(action, argparse._SubParsersAction)]
subparsers = dict()
for action in actions:
# get all subparser... |
main is the entrypoint to the sregistry client. The flow works to first to determine the subparser in use based on the command. The command then imports the correct main ( files imported in this folder ) associated with the action of choice. When the client is imported it is actually importing a return of the function ... | def main():
'''main is the entrypoint to the sregistry client. The flow works to first
to determine the subparser in use based on the command. The command then
imports the correct main (files imported in this folder) associated with
the action of choice. When the client is imported, it is actually impor... |
Generate a robot name. Inspiration from Haikunator but much more poorly implemented ; ) | def generate(self, delim='-', length=4, chars='0123456789'):
'''
Generate a robot name. Inspiration from Haikunator, but much more
poorly implemented ;)
Parameters
==========
delim: Delimiter
length: TokenLength
chars: TokenChars
'''
... |
mkdir_p attempts to get the same functionality as mkdir - p: param path: the path to create. | def mkdir_p(path):
'''mkdir_p attempts to get the same functionality as mkdir -p
:param path: the path to create.
'''
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
bot.error("Error creating p... |
get a temporary file with an optional prefix. By default will be created in/ tmp unless SREGISTRY_TMPDIR is set. By default the file is closed ( and just a name returned ). | def get_tmpfile(requested_tmpdir=None, prefix=""):
'''get a temporary file with an optional prefix. By default will be
created in /tmp unless SREGISTRY_TMPDIR is set. By default, the file
is closed (and just a name returned).
Parameters
==========
requested_tmpdir: an optional re... |
get a temporary directory for an operation. If SREGISTRY_TMPDIR is set return that. Otherwise return the output of tempfile. mkdtemp | def get_tmpdir(requested_tmpdir=None, prefix="", create=True):
'''get a temporary directory for an operation. If SREGISTRY_TMPDIR
is set, return that. Otherwise, return the output of tempfile.mkdtemp
Parameters
==========
requested_tmpdir: an optional requested temporary directory, firs... |
extract a tar archive to a specified output folder | def extract_tar(archive, output_folder, handle_whiteout=False):
'''extract a tar archive to a specified output folder
Parameters
==========
archive: the archive file to extract
output_folder: the output folder to extract to
handle_whiteout: use docker2oci variation to handle... |
use blob2oci to handle whiteout files for extraction. Credit for this script goes to docker2oci by Olivier Freyermouth and see script folder for license. | def _extract_tar(archive, output_folder):
'''use blob2oci to handle whiteout files for extraction. Credit for this
script goes to docker2oci by Olivier Freyermouth, and see script
folder for license.
Parameters
==========
archive: the archive to extract
output_folder the o... |
create_memory_tar will take a list of files ( each a dictionary with name permission and content ) and write the tarfile ( a sha256 sum name is used ) to the output_folder. If there is no output folde specified the tar is written to a temporary folder. | def create_tar(files, output_folder=None):
'''create_memory_tar will take a list of files (each a dictionary
with name, permission, and content) and write the tarfile
(a sha256 sum name is used) to the output_folder.
If there is no output folde specified, the
tar is written to a temp... |
get_content_hash will return a hash for a list of content ( bytes/ other ) | def get_content_hash(contents):
'''get_content_hash will return a hash for a list of content (bytes/other)
'''
hasher = hashlib.sha256()
for content in contents:
if isinstance(content, io.BytesIO):
content = content.getvalue()
if not isinstance(content, bytes):
co... |
find the SHA256 hash string of a file | def get_file_hash(filename):
'''find the SHA256 hash string of a file
'''
hasher = hashlib.sha256()
with open(filename, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hasher.update(chunk)
return hasher.hexdigest() |
write_json will ( optionally pretty print ) a json object to file | def write_json(json_obj, filename, mode="w", print_pretty=True):
'''write_json will (optionally,pretty print) a json object to file
Parameters
==========
json_obj: the dict to print to json
filename: the output file to write to
pretty_print: if True, will use nicer formatting
... |
write_file will open a file filename and write content content and properly close the file | def read_file(filename, mode="r", readlines=True):
'''write_file will open a file, "filename" and write content, "content"
and properly close the file
'''
with open(filename, mode) as filey:
if readlines is True:
content = filey.readlines()
else:
content = file... |
read_json reads in a json file and returns the data structure as dict. | def read_json(filename, mode='r'):
'''read_json reads in a json file and returns
the data structure as dict.
'''
with open(filename, mode) as filey:
data = json.load(filey)
return data |
clean up will delete a list of files only if they exist | def clean_up(files):
'''clean up will delete a list of files, only if they exist
'''
if not isinstance(files, list):
files = [files]
for f in files:
if os.path.exists(f):
bot.verbose3("Cleaning up %s" % f)
os.remove(f) |
pull an image from a docker hub. This is a ( less than ideal ) workaround that actually does the following: | def pull(self, images, file_name=None, save=True, force=False, **kwargs):
'''pull an image from a docker hub. This is a (less than ideal) workaround
that actually does the following:
- creates a sandbox folder
- adds docker layers, metadata folder, and custom metadata to it
- converts t... |
pull an image from a singularity registry Parameters ========== images: refers to the uri given by the user to pull in the format <collection >/ <namespace >. You should have an API that is able to retrieve a container based on parsing this uri. file_name: the user s requested name for the file. It can optionally be No... | def pull(self, images, file_name=None, save=True, **kwargs):
'''pull an image from a singularity registry
Parameters
==========
images: refers to the uri given by the user to pull in the format
<collection>/<namespace>. You should have an API that is able to
retrieve a container based on pars... |
push an image to an S3 endpoint | def push(self, path, name, tag=None):
'''push an image to an S3 endpoint'''
path = os.path.abspath(path)
image = os.path.basename(path)
bot.debug("PUSH %s" % path)
if not os.path.exists(path):
bot.error('%s does not exist.' %path)
sys.exit(1)
# Extract the metadata
names =... |
get a collection if it exists. If it doesn t exist create it first. | def get_or_create_collection(self, name):
'''get a collection if it exists. If it doesn't exist, create it first.
Parameters
==========
name: the collection name, usually parsed from get_image_names()['name']
'''
from sregistry.database.models import Collection
collection = self.get_collec... |
get a collection if it exists otherwise return None. | def get_collection(self, name):
'''get a collection, if it exists, otherwise return None.
'''
from sregistry.database.models import Collection
return Collection.query.filter(Collection.name == name).first() |
get a container otherwise return None. | def get_container(self, name, collection_id, tag="latest", version=None):
'''get a container, otherwise return None.
'''
from sregistry.database.models import Container
if version is None:
container = Container.query.filter_by(collection_id = collection_id,
... |
Do a get for a container and then a collection and then return None if no result is found. Parameters ========== name: should coincide with either the collection name or the container name with the collection. A query is done first for the collection and then the container and the path to the image file returned. | def get(self, name, quiet=False):
'''Do a get for a container, and then a collection, and then return None
if no result is found.
Parameters
==========
name: should coincide with either the collection name, or the container
name with the collection. A query is done first for the collect... |
List local images in the database optionally with a query. | def images(self, query=None):
'''List local images in the database, optionally with a query.
Paramters
=========
query: a string to search for in the container or collection name|tag|uri
'''
from sregistry.database.models import Collection, Container
rows = []
if query is not... |
Inspect a local image in the database which typically includes the basic fields in the model. | def inspect(self, name):
'''Inspect a local image in the database, which typically includes the
basic fields in the model.
'''
print(name)
container = self.get(name)
if container is not None:
collection = container.collection.name
fields = container.__dict__.copy()
fi... |
rename performs a move but ensures the path is maintained in storage | def rename(self, image_name, path):
'''rename performs a move, but ensures the path is maintained in storage
Parameters
==========
image_name: the image name (uri) to rename to.
path: the name to rename (basename is taken)
'''
container = self.get(image_name, quiet=True)
i... |
Move an image from it s current location to a new path. Removing the image from organized storage is not the recommended approach however is still a function wanted by some. | def mv(self, image_name, path):
'''Move an image from it's current location to a new path.
Removing the image from organized storage is not the recommended approach
however is still a function wanted by some.
Parameters
==========
image_name: the parsed image name.
path: t... |
_cp is the shared function between mv ( move ) and rename and performs the move and returns the updated container Parameters ========== image_name: an image_uri to look up a container in the database container: the container object to move ( must have a container. image move_to: the full path to move it to | def cp(self, move_to, image_name=None, container=None, command="copy"):
'''_cp is the shared function between mv (move) and rename, and performs
the move, and returns the updated container
Parameters
==========
image_name: an image_uri to look up a container in the database
c... |
Remove an image from the database and filesystem. | def rmi(self, image_name):
'''Remove an image from the database and filesystem.
'''
container = self.rm(image_name, delete=True)
if container is not None:
bot.info("[rmi] %s" % container) |
Remove an image from the database akin to untagging the image. This does not delete the file from the cache unless delete is set to True ( as called by rmi ). | def rm(self, image_name, delete=False):
'''Remove an image from the database, akin to untagging the image. This
does not delete the file from the cache, unless delete is set to True
(as called by rmi).
'''
container = self.get(image_name)
if container is not None:
name = container.uri or... |
get or create a container including the collection to add it to. This function can be used from a file on the local system or via a URL that has been downloaded. Either way if one of url version or image_file is not provided the model is created without it. If a version is not provided but a file path is then the file ... | def add(self, image_path=None,
image_uri=None,
image_name=None,
url=None,
metadata=None,
save=True,
copy=False):
'''get or create a container, including the collection to add it to.
This function can be used from a file on the... |
push an image to Singularity Registry | def push(self, path, name, tag=None):
'''push an image to Singularity Registry'''
path = os.path.abspath(path)
image = os.path.basename(path)
bot.debug("PUSH %s" % path)
if not os.path.exists(path):
bot.error('%s does not exist.' %path)
sys.exit(1)
# Interaction with a registr... |
take a recipe and return the complete header line. If remove_header is True only return the value. | def parse_header(recipe, header="from", remove_header=True):
'''take a recipe, and return the complete header, line. If
remove_header is True, only return the value.
Parameters
==========
recipe: the recipe file
headers: the header key to find and parse
remove_header: if t... |
find recipes will use a list of base folders files or patterns over a subset of content to find recipe files ( indicated by Starting with Singularity Parameters ========== base: if defined consider folders recursively below this level. | def find_recipes(folders, pattern=None, base=None):
'''find recipes will use a list of base folders, files,
or patterns over a subset of content to find recipe files
(indicated by Starting with Singularity
Parameters
==========
base: if defined, consider folders recursively ... |
find folder recipes will find recipes based on a particular pattern. Parameters ========== base_folder: the base folder to recursively walk pattern: a default pattern to search for manifest: an already started manifest base: if defined consider folders under this level recursively. | def find_folder_recipes(base_folder,
pattern="Singularity",
manifest=None,
base=None):
'''find folder recipes will find recipes based on a particular pattern.
Parameters
==========
base_folder: the base folder to r... |
find_single_recipe will parse a single file and if valid return an updated manifest | def find_single_recipe(filename, pattern="Singularity", manifest=None):
'''find_single_recipe will parse a single file, and if valid,
return an updated manifest
Parameters
==========
filename: the filename to assess for a recipe
pattern: a default pattern to search for
man... |
trigger a build on Google Cloud ( builder then storage ) given a name recipe and Github URI where the recipe can be found. Parameters ========== recipe: the local recipe to build. name: should be the complete uri that the user has requested to push. context: the dependency files needed for the build. If not defined onl... | def build(self, name,
recipe="Singularity",
context=None,
preview=False):
'''trigger a build on Google Cloud (builder then storage) given a name
recipe, and Github URI where the recipe can be found.
Parameters
==========
recipe: the ... |
given a list of files copy them to a temporary folder compress into a. tar. gz and rename based on the file hash. Return the full path to the. tar. gz in the temporary folder. | def create_build_package(package_files):
'''given a list of files, copy them to a temporary folder,
compress into a .tar.gz, and rename based on the file hash.
Return the full path to the .tar.gz in the temporary folder.
Parameters
==========
package_files: a list of files to inc... |
load a google compute config meaning that we start with a template and mimic the following example cloudbuild. yaml: | def load_build_config(self, name, recipe):
'''load a google compute config, meaning that we start with a template,
and mimic the following example cloudbuild.yaml:
steps:
- name: "singularityware/singularity:${_SINGULARITY_VERSION}"
args: ['build', 'julia-centos-another.sif', 'juli... |
run a build meaning creating a build. Retry if there is failure | def run_build(self, config, bucket, names):
'''run a build, meaning creating a build. Retry if there is failure
'''
project = self._get_project()
# prefix, message, color
bot.custom('PROJECT', project, "CYAN")
bot.custom('BUILD ', config['steps'][0]['name'], "CYAN")
response ... |
a specific function to take a blob along with a SUCCESS response from Google build the original config and update the blob metadata with the artifact file name dependencies and image hash. | def update_blob_metadata(blob, response, config, bucket, names):
'''a specific function to take a blob, along with a SUCCESS response
from Google build, the original config, and update the blob
metadata with the artifact file name, dependencies, and image hash.
'''
manifest = os.path.basenam... |
query a Singularity registry for a list of images. If query is None collections are listed. | def search(self, query=None, args=None):
'''query a Singularity registry for a list of images.
If query is None, collections are listed.
EXAMPLE QUERIES:
'''
# You can optionally better parse the image uri (query), but not
# necessary
# names = parse_image_name(remove_uri(query))
... |
a show all search that doesn t require a query | def search_all(self):
'''a "show all" search that doesn't require a query'''
# This should be your apis url for a search
url = '...'
# paginte get is what it sounds like, and what you want for multiple
# pages of results
results = self._paginate_get(url)
if len(results) == 0:
b... |
return a collection and repo name and tag for an image file. Parameters ========= image_name: a user provided string indicating a collection image and optionally a tag. tag: optionally specify tag as its own argument over - rides parsed image tag defaults: use defaults latest for tag and library for collection. base: i... | def parse_image_name(image_name,
tag=None,
version=None,
defaults=True,
ext="sif",
default_collection="library",
default_tag="latest",
base=None,
lowe... |
format_container_name will take a name supplied by the user remove all special characters ( except for those defined by special - characters and return the new image name. | def format_container_name(name, special_characters=None):
'''format_container_name will take a name supplied by the user,
remove all special characters (except for those defined by "special-characters"
and return the new image name.
'''
if special_characters is None:
special_characters = []
... |
get the uri for an image if within acceptable Parameters ========== image: the image uri in the format <uri >:// <registry >/ <namespace >: <tag > | def get_uri(image):
'''get the uri for an image, if within acceptable
Parameters
==========
image: the image uri, in the format <uri>://<registry>/<namespace>:<tag>
'''
# Ensure we have a string
image = image or ''
# Find uri prefix, including ://
regexp = re.compile('^.... |
pull an image from storage using Swift. The image is found based on the storage uri Parameters ========== images: refers to the uri given by the user to pull in the format <collection >/ <namespace >. You should have an API that is able to retrieve a container based on parsing this uri. file_name: the user s requested ... | def pull(self, images, file_name=None, save=True, **kwargs):
'''pull an image from storage using Swift. The image is found based on the
storage uri
Parameters
==========
images: refers to the uri given by the user to pull in the format
<collection>/<namespace>. You should have a... |
push an image to Google Cloud Drive meaning uploading it path: should correspond to an absolte image path ( or derive it ) name: should be the complete uri that the user has requested to push. tag: should correspond with an image tag. This is provided to mirror Docker | def push(self, path, name, tag=None):
'''push an image to Google Cloud Drive, meaning uploading it
path: should correspond to an absolte image path (or derive it)
name: should be the complete uri that the user has requested to push.
tag: should correspond with an image tag. This is provided to mirr... |
set the API base or default to use Docker Hub. The user is able to set the base api version and protocol via a settings file of environment variables: | def _set_base(self, zone=None):
'''set the API base or default to use Docker Hub. The user is able
to set the base, api version, and protocol via a settings file
of environment variables:
'''
if hasattr(self.aws._client_config, 'region_name'):
zone = self.aws._c... |
update secrets will take a secrets credential file either located at. sregistry or the environment variable SREGISTRY_CLIENT_SECRETS and update the current client secrets as well as the associated API base. For the case of using Docker Hub if we find a. docker secrets file we update from there. | def _update_secrets(self):
'''update secrets will take a secrets credential file
either located at .sregistry or the environment variable
SREGISTRY_CLIENT_SECRETS and update the current client
secrets as well as the associated API base. For the case of
using Docker H... |
get_logging_level will configure a logging to standard out based on the user s selected level which should be in an environment variable called MESSAGELEVEL. if MESSAGELEVEL is not set the maximum level ( 5 ) is assumed ( all messages ). | def get_logging_level():
'''get_logging_level will configure a logging to standard out based on the user's
selected level, which should be in an environment variable called
MESSAGELEVEL. if MESSAGELEVEL is not set, the maximum level
(5) is assumed (all messages).
'''
level = os.environ.get("MESS... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.