lancium.api.Image
Image
This is an object that represents a computational environment. Used to create a Singularity container.
Initialize an Image object.
ARGS:
path (string)
: Image pathname (string)
: Image namedescription
(string): description of jobsource_type
(string): Image typesource_url
(string): url to source of Imagesource
(string): path to source filebuild_script
(string): build script for dataenvironment
(list of dict): environment variables to be added to imagestatus
(string): status of Image
Helper Method -- Handles status checking for server response objects
ARGS:
res (response object)
: response object from the servername (string)
: Image namedata (json)
: json of payload for the api callcode (int)
: status code to check forerror_handling (boolean)
: flag for whether to do internal handlingkey ('str')
: key for response object
RETURNS: Nothing unless the request is a status code 422 in which case it returns list with the server response and a boolean stating that it is a directory.
Helper Method -- Handles argument checking
ARGS:
source_type (string)
: Image type (singularity_image, singularity_file, docker_image, docker_file)source_url (string)
: url to source filesource (string)
: path to source filebuild_script (string)
: path to the build script for a singularity_file or docker_file
RETURNS: Nothing.
Retrieve all Images.
GET /images
ARGS:
**kwargs (dictionary)
: can contain auth key to perform this method using a different account. {'auth': ANOTHER_API_KEY}
Returns: list: list of Images
from lancium.api.Image import Image
imgs = Image().all()
print(imgs)
### OUTPUT BELOW
'[<lancium.api.Image.Image object at 0x7f737491e8c0>,..., <lancium.api.Image.Image object at 0x7f737491f430>]'
Create a new image.
POST /images
Args:
path (string)
: Image pathname (string)
: Image namedescription (string)
: description of imageSource_type (string)
: Image type [docker_file, docker_image, singularity_image, singularity_file)source_url (string)
: url ot source filesource (string)
: path to source image filebuild_script (string)
: path to build script for docker_file and singualrity_fileenvironment (list of dict)
: environment variables to be added to imagekwargs(dictionary)
: can contain auth key if you would like to perform this method using a different account. {'auth': ANOTHER_API_KEY}
Returns: Image: Image object
import os
from lancium.api.Image import Image
with open(os.path.abspath('pythonDocker.txt')) as build_script:
contents = build_script.read()
params = {'build_script': contents}
imgs = Image().create(path='testing123', name='testing123', source_type='docker_file',**params)
### IMAGE OUTPUT BELOW
[
{
"path": "testing123",
"name": "testing123",
"source_type": "docker_file",
"build_script": "contents of build-script",
"status": "building",
"created_at": "2022-07-07T16:53:37.237Z",
"updated_at": "2022-07-07T16:53:39.000Z"
}
]
Retrieve specific image(s) by path.
GET /images/
Args:
path (string)
: path to image(s)kwargs (dictionary)
: can contain auth to perform this method using a different account. ('auth': ANOTHER_API_KEY)
Return: list: list of Images
from lancium.api.Image import Image
imgs = Image().get('testing123')
print(imgs[0].path)
print(imgs[0].name)
print(imgs[0].source_type)
### OUTPUT BELOW
'testing123'
'testing123'
'docker_file'
Updates an existing image.
PUT /images/
ARGS:
path (string)
: Image pathname (string)
: Image namedescription (string)
: description of imagesource_type (string)
: Image type [docker_file, docker_image, singularity_image, singularity_file)source_url (string)
: url ot source filesource (string)
: path to source image filebuidl_script (string)
: path to build script for docker_file and singualrity_fileenvironment (list of dict)
: environment variables to be added to image
RETURNS: None: None
from lancium.api.Image import Image
imgs = Image().get('testing123')
testing123 = imgs[0]
update = {'name': 'testing321'}
testing123.update(**update)
imgs2 = Image().get('testing123')
print(imgs2[0].name)
### OUTPUT BELOW
'testing321'
Refresh a specific image to reflect database.
GET /images/
Args: None (None)
RETURNS: None: None
from lancium.api.Image import Image
from lancium.errors.common import *
img = Image.get('ubuntu')[0]
img.name = 'not_ubuntu'
print(img.name)
img.refresh()
print(img.name)
###OUTPUT BELOW
not ubuntu
ubuntu
Upload image.
PATCH /images/
Args:
file_path (string)
: file to uploadcallback (func, optional)
: called after each chunk is successfully uploaded, accepts arguments in the format of (file_size, file_start, total chunks, current chunk)
Returns: Response object: response object in json format
Rebuild existing image.
POST /images/
ARGS: None (None)
RETURNS: None: None
from lancium.api.Image import Image
imgs = Image().get('testing123')
testing321 = imgs[0]
testing321.rebuild()
### IMAGE BELOW
[
{
"path": "testing123",
"name": "testing123",
"source_type": "docker_file",
"build_script": "build script",
"status": "building",
"created_at": "2022-07-07T16:53:37.237Z",
"updated_at": "2022-07-07T18:26:37.541Z",
"built_at": "2022-07-07T17:08:51.243Z"
}
]
Delete image.
DELETE /images/
ARGS:
path (string)
: path to image object within Lanciumkwargs (dictionary)
: can contain auth key if you would like to perform this method using a different account. {'auth': ANOTHER_API_KEY}
RETURNS: None: None
from lancium.api.Image import Image
from lancium.errors.common import *
Image.delete('test/mlperf2')
try:
Image.get('test/mlperf2')
except:
print('not found')
### OUTPUT BELOW
not found
Delete current image
DELETE /images/
Args: None (None)
Returns: None: None
from lancium.api.Image import Image
from lancium.errors.common import *
img = Image.get('zzzz')[0]
img.destroy()
try:
Image.get('zzzz')
except:
print('not found')
###OUTPUT BELOW
not found