Search is not available for this dataset
text stringlengths 75 104k |
|---|
def logs(self, name=None):
'''return logs for a particular container. The logs file is equivalent to
the name, but with extension .log. If there is no name, the most recent
log is returned.
Parameters
==========
name: the container name to print logs for.
'''
content = N... |
def list_logs(self):
'''return a list of logs. We return any file that ends in .log
'''
results = []
for image in self._bucket.list_blobs():
if image.name.endswith('log'):
results.append(image)
if len(results) == 0:
bot.info("No containers found, based on extension .log"... |
def print_log(self, logname):
'''helper function to retrieve a particular log, and print.
Parameters
==========
name: the name of the log to retrieve
'''
content = None
# Try to retrieve the blob (log) if exists
logfile = self._bucket.get_blob(logname)
print(lognam... |
def parse_endpoint_name(self, endpoint):
'''split an endpoint name by colon, as the user can provide an
endpoint name separated from a path:
Parameters
==========
endpoint 12345:/path/on/remote
'''
parts = [x for x in endpoint.split(':') if x]
endpoint = parts[0]
if... |
def create_endpoint_folder(self, endpoint_id, folder):
'''create an endpoint folder, catching the error if it exists.
Parameters
==========
endpoint_id: the endpoint id parameters
folder: the relative path of the folder to create
'''
try:
res = self.transfer_client.oper... |
def get_endpoint_path(self, endpoint_id):
'''return the first fullpath to a folder in the endpoint based on
expanding the user's home from the globus config file. This
function is fragile but I don't see any other way to do it.
Parameters
==========
endpoint_id: the endpoint ... |
def init_transfer_client(self):
'''return a transfer client for the user'''
if self._tokens_need_update():
self._update_tokens()
access_token = self.transfer['access_token']
# Createe Refresh Token Authorizer
authorizer = globus_sdk.RefreshTokenAuthorizer(
... |
def get_endpoint(self, endpoint_id):
'''use a transfer client to get a specific endpoint based on an endpoint id.
Parameters
==========
endpoint_id: the endpoint_id to retrieve
'''
endpoint = None
if not hasattr(self, 'transfer_client'):
self._init_transfer_cl... |
def get_endpoints(self, query=None):
'''use a transfer client to get endpoints. If a search term is included,
we use it to search a scope of "all" in addition to personal and shared
endpoints. Endpoints are organized
by type (my-endpoints, shared-with-me, optionally all) and then id.
Pa... |
def list_containers(self):
'''return a list of containers. Since Google Drive definitely has other
kinds of files, we look for containers in a special sregistry folder,
(meaning the parent folder is sregistry) and with properties of type
as container.
'''
# Get or create the base
fo... |
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 properties value type set to
container, which is set when the image is pushed.
IMPORTANT: the upload function adds this metadata. For a container to
be fou... |
def container_query(self, query, quiet=False):
'''search for a specific container.
This function is the same as the search all, but instead of showing all
results, filters them down based on user criteria (the query)
'''
results = self._list_containers()
matches = []
for result in results:... |
def status(backend):
'''print the status for all or one of the backends.
'''
print('[backend status]')
settings = read_client_secrets()
print('There are %s clients found in secrets.' %len(settings))
if 'SREGISTRY_CLIENT' in settings:
print('active: %s' %settings['SREGISTRY_CLIENT'])
... |
def add(backend, variable, value, force=False):
'''add the variable to the config
'''
print('[add]')
settings = read_client_secrets()
# If the variable begins with the SREGISTRY_<CLIENT> don't add it
prefix = 'SREGISTRY_%s_' %backend.upper()
if not variable.startswith(prefix):
varia... |
def remove(backend, variable):
'''remove a variable from the config, if found.
'''
print('[remove]')
settings = read_client_secrets()
# If the variable begins with the SREGISTRY_<CLIENT> don't add it
prefixed = variable
prefix = 'SREGISTRY_%s_' %backend.upper()
if not variable.startswit... |
def activate(backend):
'''activate a backend by adding it to the .sregistry configuration file.
'''
settings = read_client_secrets()
if backend is not None:
settings['SREGISTRY_CLIENT'] = backend
update_secrets(settings)
print('[activate] %s' %backend) |
def delete_backend(backend):
'''delete a backend, and update the secrets file
'''
settings = read_client_secrets()
if backend in settings:
del settings[backend]
# If the backend was the active client, remove too
if 'SREGISTRY_CLIENT' in settings:
if settings['SREGIST... |
def list_backends(backend=None):
'''return a list of backends installed for the user, which is based on
the config file keys found present
Parameters
==========
backend: a specific backend to list. If defined, just list parameters.
'''
settings = read_client_secrets()
# B... |
def pull(self, images, file_name=None, save=True, **kwargs):
'''pull an image from a dropbox. 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 tha... |
def push(self, path, name, tag=None):
'''push an image to your Dropbox
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... |
def _update_base(self, image):
''' update a base based on an image name, meaning detecting a particular
registry and if necessary, updating the self.base. When the image
name is parsed, the base will be given to remove the registry.
'''
base = None
# Google Conta... |
def _set_base(self, default_base=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:
SREGISTRY_DOCKERHUB_BASE: defaults to index.docker.io
SREGISTRY_DOCKER... |
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... |
def share(self, query, share_to):
'''share will use the client to get an image based on a query, and then
the link with an email or endpoint (share_to) of choice.
'''
images = self._container_query(query, quiet=True)
if len(images) == 0:
bot.error('Cannot find a remote image matching %s'... |
def pull(self, images, file_name=None, save=True, **kwargs):
'''pull an image from google drive, based on a query (uri or id)
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 con... |
def basic_auth_header(username, password):
'''generate a base64 encoded header to ask for a token. This means
base64 encoding a username and password and adding to the
Authorization header to identify the client.
Parameters
==========
username: the username
password:... |
def generate_signature(payload, secret):
'''use an endpoint specific payload and client secret to generate
a signature for the request'''
payload = _encode(payload)
secret = _encode(secret)
return hmac.new(secret, digestmod=hashlib.sha256,
msg=payload).hexdigest() |
def generate_credential(s):
'''basic_auth_header will return a base64 encoded header object to
:param username: the username
'''
if sys.version_info[0] >= 3:
s = bytes(s, 'utf-8')
credentials = base64.b64encode(s).decode('utf-8')
else:
credentials = base64.b64encode(s)
re... |
def generate_header_signature(secret, payload, request_type):
'''Authorize a client based on encrypting the payload with the client
secret, timestamp, and other metadata
'''
# Use the payload to generate a digest push|collection|name|tag|user
timestamp = generate_timestamp()
credential = ... |
def delete(self, url,
headers=None,
return_json=True,
default_headers=True):
'''delete request, use with caution
'''
bot.debug('DELETE %s' %url)
return self._call(url,
headers=headers,
func=requests.delete,
... |
def head(self, url):
'''head request, typically used for status code retrieval, etc.
'''
bot.debug('HEAD %s' %url)
return self._call(url, func=requests.head) |
def healthy(self, url):
'''determine if a resource is healthy based on an accepted response (200)
or redirect (301)
Parameters
==========
url: the URL to check status for, based on the status_code of HEAD
'''
response = requests.get(url)
status_code = response.status_code
... |
def post(self,url,
headers=None,
data=None,
return_json=True,
default_headers=True):
'''post will use requests to get a particular url
'''
bot.debug("POST %s" %url)
return self._call(url,
headers=headers,
... |
def get(self,url,
headers=None,
token=None,
data=None,
return_json=True,
default_headers=True,
quiet=False):
'''get will use requests to get a particular url
'''
bot.debug("GET %s" %url)
return self._call(url,
... |
def paginate_get(self, url,
headers=None,
return_json=True,
start_page=None):
'''paginate_call is a wrapper for get to paginate results
'''
geturl = '%s&page=1' %(url)
if start_page is not None:
geturl = '%s&page=%s' %(url,start_page)
re... |
def verify(self):
'''
verify will return a True or False to determine to verify the
requests call or not. If False, we should the user a warning message,
as this should not be done in production!
'''
from sregistry.defaults import DISABLE_SSL_CHECK
if DISABLE_SSL_CHECK is True:
... |
def call(self, url, func, data=None,
headers=None,
return_json=True,
stream=False,
retry=True,
default_headers=True,
quiet=False):
'''call will issue the cal... |
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... |
def pull(self, images, file_name=None, save=True, **kwargs):
'''pull an image from a s3 storage
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 bas... |
def remove(self, image, force=False):
'''delete an image to Singularity Registry'''
q = parse_image_name(remove_uri(image))
# If the registry is provided in the uri, use it
if q['registry'] == None:
q['registry'] = self.base
# If the base doesn't start with http or https, add it
q = s... |
def get_lookup():
'''get version by way of sregistry.version, returns a
lookup dictionary with several global variables without
needing to import singularity
'''
lookup = dict()
version_file = os.path.join('sregistry', 'version.py')
with open(version_file) as filey:
exec(filey.read(... |
def get_reqs(lookup=None, key='INSTALL_REQUIRES'):
'''get requirements, mean reading in requirements and versions from
the lookup obtained with get_lookup'''
if lookup == None:
lookup = get_lookup()
install_requires = []
for module in lookup[key]:
module_name = module[0]
mo... |
def get_singularity_version(singularity_version=None):
'''get_singularity_version will determine the singularity version for a
build first, an environmental variable is looked at, followed by
using the system version.
Parameters
==========
singularity_version: if not defined, lo... |
def check_install(software=None, quiet=True):
'''check_install will attempt to run the singularity command, and
return True if installed. The command line utils will not run
without this check.
Parameters
==========
software: the software to check if installed
quiet: shou... |
def get_installdir():
'''get_installdir returns the installation directory of the application
'''
return os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
def get_thumbnail():
'''return the robot.png thumbnail from the database folder.
if the user has exported a different image, use that instead.
'''
from sregistry.defaults import SREGISTRY_THUMBNAIL
if SREGISTRY_THUMBNAIL is not None:
if os.path.exists(SREGISTRY_THUMBNAIL):
ret... |
def run_command(cmd, sudo=False):
'''run_command uses subprocess to send a command to the terminal.
Parameters
==========
cmd: the command to send, should be a list for subprocess
error_message: the error message to give to user if fails,
if none specified, will alert that command failed.
... |
def _speak(self):
'''if you want to add an extra print (of a parameter, for example)
for the user when the client initalizes, write it here, eg:
bot.info('[setting] value')
'''
if hasattr(self, 'account'):
bot.info('connected to %s' %self.account.name.display_na... |
def _get_metadata(self, image_file=None, dbx_metadata=None):
'''this is a wrapper around the main client.get_metadata to first parse
a Dropbox FileMetadata into a dicionary, then pass it on to the
primary get_metadata function.
Parameters
==========
image... |
def _update_secrets(self):
'''update secrets will look for a dropbox token in the environment at
SREGISTRY_DROPBOX_TOKEN and if found, create a client. If not,
an error message is returned and the client exits.
'''
# Retrieve the user token. Exit if not found
toke... |
def print_output(response, output_file=None):
'''print the output to the console for the user. If the user wants the content
also printed to an output file, do that.
Parameters
==========
response: the response from the builder, with metadata added
output_file: if defined, write ... |
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 Client as cli
if len(args.commands) > 0:
for name in args.commands:
cli.destroy(name)
sys.exit(0) |
def templates(args, template_name=None):
'''list a specific template (if a name is provided) or all templates
available.
Parameters
==========
args: the argparse object to look for a template name
template_name: if not set, show all
'''
from sregistry.main import get_cli... |
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 sre... |
def get_collections(self):
'''get a listing of collections that the user has access to.
'''
collections = []
for container in self.conn.get_account()[1]:
collections.append(container['name'])
return collections |
def _get_or_create_collection(self, name):
'''get or create a collection, meaning that if the get returns
None, create and return the response to the user.
Parameters
==========
name: the name of the collection to get (and create)
'''
try:
... |
def _update_secrets(self):
'''update secrets will look for a user and token in the environment
If we find the values, cache and continue. Otherwise, exit with error
'''
# Get the swift authentication type first. That will determine what we
# will need to collect for proper a... |
def _update_secrets(self):
'''The user is required to have an application secrets file in his
or her environment. The information isn't saved to the secrets
file, but the client exists with error if the variable isn't found.
'''
env = 'GOOGLE_APPLICATION_CREDENTIALS'
... |
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()
... |
def _get_bucket(self, bucket_name):
'''get a bucket based on a bucket name. If it doesn't exist, create it.
Parameters
==========
bucket_name: the name of the bucket to get (or create). It should
not contain google, and should be all lowercase with -
... |
def get_client(image=None, quiet=False, **kwargs):
'''
get the correct client depending on the driver of interest. The
selected client can be chosen based on the environment variable
SREGISTRY_CLIENT, and later changed based on the image uri parsed
If there is no preference, the default ... |
def pull(self, images, file_name=None, save=True, force=False, **kwargs):
''' pull an image from an endpoint
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 ... |
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 em... |
def update_token(self, response):
'''update_token uses HTTP basic authentication to get a token for
Docker registry API V2 operations. We get here if a 401 is
returned for a request.
Parameters
==========
response: the http request response to parse for the challenge.
https://docs.dock... |
def get_manifests(self, repo_name, digest=None):
'''get_manifests calls get_manifest for each of the schema versions,
including v2 and v1. Version 1 includes image layers and metadata,
and version 2 must be parsed for a specific manifest, and the 2nd
call includes the layers. If a digest is not... |
def get_manifest_selfLink(self, repo_name, digest=None):
''' get a selfLink for the manifest, for use by the client get_manifest
function, along with the parents pull
Parameters
==========
repo_name: reference to the <username>/<repository>:<tag> to obtain
digest: a tag or shas... |
def get_manifest(self, repo_name, digest=None, version="v1"):
'''
get_manifest should return an image manifest
for a particular repo and tag. The image details
are extracted when the client is generated.
Parameters
==========
repo_name: reference to the <username>/<reposi... |
def download_layers(self, repo_name, digest=None, destination=None):
''' download layers is a wrapper to do the following for a client loaded
with a manifest for an image:
1. use the manifests to retrieve list of digests (get_digests)
2. atomically download the list to destination (ge... |
def get_download_cache(self, destination, subfolder='docker'):
'''determine the user preference for atomic download of layers. If
the user has set a singularity cache directory, honor it. Otherwise,
use the Singularity default.
'''
# First priority after user specification is Singularity Cache... |
def get_digests(self):
'''return a list of layers from a manifest.
The function is intended to work with both version
1 and 2 of the schema. All layers (including redundant)
are returned. By default, we try version 2 first,
then fall back to version 1.
For version 1 manifests: ex... |
def get_layer(self, image_id, repo_name, download_folder=None):
'''download an image layer (.tar.gz) to a specified download folder.
Parameters
==========
download_folder: download to this folder. If not set, uses temp.
repo_name: the image name (library/ubuntu) to retrieve
'''
... |
def get_size(self, add_padding=True, round_up=True, return_mb=True):
'''get_size will return the image size (must use v.2.0 manifest)
Parameters
==========
add_padding: if true, return reported size * 5
round_up: if true, round up to nearest integer
return_mb: if true, de... |
def get_config(self, key="Entrypoint", delim=None):
'''get_config returns a particular key (default is Entrypoint)
from a VERSION 1 manifest obtained with get_manifest.
Parameters
==========
key: the key to return from the manifest config
delim: Given a list, the delim to us... |
def get_environment_tar(self):
'''return the environment.tar generated with the Singularity software.
We first try the Linux Filesystem expected location in /usr/libexec
If not found, we detect the system archicture
dirname $(singularity selftest 2>&1 | grep 'lib' | awk '{print $4}' | sed -e '... |
def create_metadata_tar(self, destination=None, metadata_folder=".singularity.d"):
'''create a metadata tar (runscript and environment) to add to the
downloaded image. This function uses all functions in this section
to obtain key--> values from the manifest config, and write
to a .tar.gz
... |
def extract_env(self):
'''extract the environment from the manifest, or return None.
Used by functions env_extract_image, and env_extract_tar
'''
environ = self._get_config('Env')
if environ is not None:
if not isinstance(environ, list):
environ = [environ]
lines = []... |
def extract_runscript(self):
'''extract the runscript (EntryPoint) as first priority, unless the
user has specified to use the CMD. If Entrypoint is not defined,
we default to None:
1. IF SREGISTRY_DOCKERHUB_CMD is set, use Cmd
2. If not set, or Cmd is None/blank, try Entrypoint
... |
def _update_base(self):
'''update the base, including the URL for GitLab and the API endpoint.
'''
self.base = self._get_and_update_setting('SREGISTRY_GITLAB_BASE',
"https://gitlab.com/")
self.api_base = "%s/api/v4" % self.base.strip('/')
... |
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 |
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... |
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... |
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... |
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... |
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... |
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 |
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) |
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... |
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... |
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.
... |
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... |
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 ... |
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... |
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) |
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 ... |
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... |
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 ... |
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,... |
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
==========
... |
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... |
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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.