Qarnot Python SDK¶
qarnot is a Python library designed to interact with Qarnot cloud computing service. It allows users to launch, manage and monitor payloads running on distributed computing nodes deployed in Qarnot’s digital heaters.
You can find samples and detailed information on http://computing.qarnot.com.
Reference Docs¶
Installation¶
We recommend you to set up a Python virtual environment. To do so with Python2 you need virtualenv, you should be able to install it using for example one of the following commands:
$ apt-get install python-virtualenv
$ easy_install virtualenv
$ pip install virtualenv
Or for Python3:
$ apt-get install python3-venv
$ pip3 install virtualenv
Once virtualenv is installed you can create your own environment by running the following commands in the project directory:
$ virtualenv venv
New python executable in venv/bin/python
Installing setuptools, pip, wheel...done.
Or with Python3;
$ python3 -m venv venv
Then each time you want to use your virtual environment you have to activate it by running this command:
$ . venv/bin/activate
Finally you have to install in your environment the Qarnot SDK:
pip install qarnot
If you plan to send large files to the API, we advise you to install the optional requests-toolbelt dependency in order not to overuse your memory:
pip install requests-toolbelt
You are now ready to use the Qarnot SDK.
Basic usage¶
Configuration¶
A basic usage of the Qarnot require a configuration file (eg: qarnot.conf).
Here is a basic one, check Connection
for details.
1 2 3 4 5 6 | [cluster]
# url of the REST API
url=https://api.qarnot.com
[client]
# auth string of the client
token=token
|
Script¶
And here is a little sample to start a task running your myscript.py Python script.
1 2 3 4 5 6 7 | import qarnot
conn = qarnot.connection.Connection('qarnot.conf')
task = conn.create_task('hello world', 'ubuntu')
task.constants['DOCKER_CMD'] = 'echo hello world from ${FRAME_ID}!'
task.run()
print(task.stdout())
|
SDK Documentation¶
Connection¶
Module describing a connection.
-
class
qarnot.connection.
Connection
(fileconf=None, client_token=None, cluster_url=None, cluster_unsafe=False, cluster_timeout=None, storage_url=None, storage_unsafe=False, retry_count=5, retry_wait=1.0, cluster_custom_certificate=None, storage_custom_certificate=None)[source]¶ Bases:
object
Represents the couple cluster/user to which submit tasks.
-
__init__
(fileconf=None, client_token=None, cluster_url=None, cluster_unsafe=False, cluster_timeout=None, storage_url=None, storage_unsafe=False, retry_count=5, retry_wait=1.0, cluster_custom_certificate=None, storage_custom_certificate=None)[source]¶ Create a connection to a cluster with given config file, options or environment variables. Available environment variable are QARNOT_CLUSTER_URL, QARNOT_CLUSTER_UNSAFE, QARNOT_CLUSTER_TIMEOUT and QARNOT_CLIENT_TOKEN.
Parameters: - fileconf (str or dict) – path to a qarnot configuration file or a corresponding dict
- client_token (str) – API Token
- cluster_url (str) – (optional) Cluster url.
- cluster_unsafe (bool) – (optional) Disable certificate check
- cluster_timeout (int) – (optional) Timeout value for every request
- storage_url (str) – (optional) Storage service url.
- storage_unsafe (bool) – (optional) Disable certificate check
- retry_count (int) – (optional) ConnectionError retry count. Default to 5.
- retry_wait (float) – (optional) Retry on error wait time, progressive. (wait * (retry_count - retry_num). Default to 1s
Configuration sample:
[cluster] # url of the REST API url=https://localhost # No SSL verification ? unsafe=False [client] # auth string of the client token=login [storage] url=https://storage unsafe=False
-
s3client
¶ Pre-configured s3 client object.
Return type: list( S3.Client
)Returns: A list of ObjectSummary resources
-
s3resource
¶ Pre-configured s3 resource object.
Return type: list( S3.ServiceResource
)Returns: A list of ObjectSummary resources
-
user_info
¶ Get information of the current user on the cluster.
Return type: Returns: Requested information.
Raises: - qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
buckets
()[source]¶ Get the list of buckets.
Return type: list(class:~qarnot.bucket.Bucket). Returns: List of buckets
-
pools
(summary=True, tags_intersect=None)[source]¶ Get the list of pools stored on this cluster for this user.
Parameters: Return type: List of
Pool
.Returns: Pools stored on the cluster owned by the user.
Raises: - qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
tasks
(tags=None, summary=True, tags_intersect=None)[source]¶ Get the list of tasks stored on this cluster for this user.
Parameters: Return type: List of
Task
.Returns: Tasks stored on the cluster owned by the user.
Raises: - qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
jobs
()[source]¶ Get the list of jobs stored on this cluster for this user.
Raises: - qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
retrieve_pool
(uuid)[source]¶ Retrieve a
qarnot.pool.Pool
from its uuidParameters: uuid (str) – Desired pool uuid
Return type: Returns: Existing pool defined by the given uuid
Raises: - qarnot.exceptions.MissingPoolException – pool does not exist
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
retrieve_task
(uuid)[source]¶ Retrieve a
qarnot.task.Task
from its uuidParameters: uuid (str) – Desired task uuid
Return type: Returns: Existing task defined by the given uuid
Raises: - qarnot.exceptions.MissingTaskException – task does not exist
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
retrieve_job
(uuid)[source]¶ Retrieve a
qarnot.job.Job
from its uuidParameters: uuid (str) – Desired job uuid
Return type: Returns: Existing job defined by the given uuid
Raises: - qarnot.exceptions.MissingJobException – job does not exist
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
retrieve_or_create_bucket
(uuid)[source]¶ Retrieve a
Bucket
from its description, or create a new one.Parameters: uuid (str) – the bucket uuid (name) Return type: Bucket
Returns: Existing or newly created bucket defined by the given name
-
retrieve_bucket
(uuid)[source]¶ Retrieve a
Bucket
from its uuid (name)Parameters: uuid (str) – Desired bucket uuid (name) Return type: Bucket
Returns: Existing bucket defined by the given uuid (name) Raises: botocore.exceptions.ClientError: Bucket does not exist, or invalid credentials
-
create_pool
(name, profile, instancecount=1, shortname=None)[source]¶ Create a new
Pool
.Parameters: Return type: Returns: The created
Pool
.Note
See available profiles with
profiles()
.
-
create_elastic_pool
(name, profile, minimum_total_slots=0, maximum_total_slots=1, minimum_idle_slots=0, minimum_idle_time_seconds=0, resize_factor=1, resize_period=90, shortname=None)[source]¶ Create a new
Pool
.Parameters: - name (str) – given name of the pool
- profile (str) – which profile to use with this pool
- minimum_total_slots (int) – minimum number of instances to run for the pool
- maximum_total_slots (int) – maximum number of instances to run for the pool
- minimum_idle_slots (int) – the number of instances that can be idle before considering shrinking the pool
- minimum_idle_time_seconds (int) – the number of seconds before considering shrinking the pool
- resize_factor (float) – the speed with which we grow the pool to meet the demand
- resize_period (int) – the time between the load checks that decide if the pool grows or shrinks
- shortname (str) – optional unique friendly shortname of the pool
Return type: Returns: The created
Pool
.Note
See available profiles with
profiles()
.
-
create_task
(name, profile_or_pool=None, instancecount_or_range=1, shortname=None, job=None)[source]¶ Create a new
Task
.Parameters: - name (str) – given name of the task
- profile_or_pool (str or
Pool
or None) – which profile to use with this task, or which Pool to run task, or which job to attach it to - instancecount_or_range (int or str) – number of instances, or ranges on which to run task. Defaults to 1.
- shortname (str) – optional unique friendly shortname of the task
- job (
Job
) – which job to attach the task to
Return type: Returns: The created
Task
.Note
See available profiles with
profiles()
.
-
submit_tasks
(tasks)[source]¶ Submit a list of
Task
.:param List of
Task
. :raises qarnot.exceptions.QarnotGenericException: API general error, see message for detailsNote
Will ensure all added files are on the resource bucket regardless of their uploading mode.
-
profiles
()[source]¶ Get list of profiles available on the cluster.
Return type: list of
Profile
Raises: - qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
retrieve_profile
(name)[source]¶ Get details of a profile from its name.
Return type: Raises: - qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
-
create_bucket
(name)[source]¶ Create a new
Bucket
. If the bucket already exist, retrieve the existing bucket.Parameters: name (str) – bucket name Return type: qarnot.bucket.Bucket
Returns: The created or existing Bucket
.
-
Compute¶
Task¶
Module to handle a task.
-
class
qarnot.task.
Task
(connection, name, profile_or_pool=None, instancecount_or_range=1, shortname=None, job=None)[source]¶ Bases:
object
Represents a Qarnot task.
Note
A
Task
must be created withqarnot.connection.Connection.create_task()
or retrieved withqarnot.connection.Connection.tasks()
orqarnot.connection.Connection.retrieve_task()
.-
__init__
(connection, name, profile_or_pool=None, instancecount_or_range=1, shortname=None, job=None)[source]¶ Create a new
Task
.Parameters: - connection (
qarnot.connection.Connection
) – the cluster on which to send the task - name (
str
) – given name of the task - profile_or_pool (str or
Pool
or None) – which profile to use with this task, or which Pool to run task, - instancecount_or_range (int or str) – number of instances or ranges on which to run task
- shortname (
str
) – userfriendly task name - job (
Job
) – which job to attach the task to
- connection (
-
run
(output_dir=None, job_timeout=None, live_progress=False, results_progress=None)[source]¶ Submit a task, wait for the results and download them if required.
Parameters: - output_dir (str) – (optional) path to a directory that will contain the results
- job_timeout (float) – (optional) Number of seconds before the task
abort()
if it is not already finished - live_progress (bool) – (optional) display a live progress
- results_progress (bool or function(float, float, str)) – (optional) can be a callback (read,total,filename) or True to display a progress bar
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.MaxTaskException – Task quota reached
- qarnot.exceptions.NotEnoughCreditsException – Not enough credits
- qarnot.exceptions.UnauthorizedException – invalid credentials
Note
Will ensure all added file are on the resource bucket regardless of their uploading mode.
Note
If this function is interrupted (script killed for example), but the task is submitted, the task will still be executed remotely (results will not be downloaded)
Warning
Will override output_dir content.
-
resume
(output_dir, job_timeout=None, live_progress=False, results_progress=None)[source]¶ Resume waiting for this task if it is still in submitted mode. Equivalent to
wait()
+download_results()
.Parameters: - output_dir (str) – path to a directory that will contain the results
- job_timeout (float) – Number of seconds before the task
abort()
if it is not already finished - live_progress (bool) – display a live progress
- results_progress (bool or function(float, float, str)) – can be a callback (read,total,filename) or True to display a progress bar
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
Do nothing if the task has not been submitted.
Warning
Will override output_dir content.
-
submit
()[source]¶ Submit task to the cluster if it is not already submitted.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.MaxTaskException – Task quota reached
- qarnot.exceptions.NotEnoughCreditsException – Not enough credits
- qarnot.exceptions.UnauthorizedException – invalid credentials
Note
Will ensure all added files are on the resource bucket regardless of their uploading mode.
Note
To get the results, call
download_results()
once the job is done.
-
abort
()[source]¶ Abort this task if running.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
update_resources
()[source]¶ Update resources for a running task.
- The typical workflow is as follows:
- Upload new files on your resource bucket,
- Call this method,
- The new files will appear on all the compute nodes in the $DOCKER_WORKDIR folder
Note: There is no way to know when the files are effectively transfered. This information is available on the compute node only. Note: The update is additive only: files deleted from the bucket will NOT be deleted from the task’s resources directory.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
delete
(purge_resources=False, purge_results=False)[source]¶ Delete this task on the server.
Parameters: Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
update
(flushcache=False)[source]¶ Update the task object from the REST Api. The flushcache parameter can be used to force the update, otherwise a cached version of the object will be served when accessing properties of the object. Some methods will flush the cache, like
submit()
,abort()
,wait()
andinstant()
. Cache behavior is configurable withauto_update
andupdate_cache_time
.Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not represent a valid one
-
classmethod
from_json
(connection, json_task, is_summary=False)[source]¶ Create a Task object from a json task.
Parameters: - connection (qarnot.connection.Connection) – the cluster connection
- json_task (dict) – Dictionary representing the task
Returns: The created
Task
.
-
commit
()[source]¶ Replicate local changes on the current object instance to the REST API
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
Note
When updating buckets’ properties, auto update will be disabled until commit is called.
-
wait
(timeout=None, live_progress=False)[source]¶ Wait for this task until it is completed.
Parameters: Return type: Returns: Is the task finished
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not represent a valid one
-
snapshot
(interval)[source]¶ Start snapshooting results. If called, this task’s results will be periodically updated, instead of only being available at the end.
Snapshots will be taken every interval second from the time the task is submitted.
Parameters: interval (int) – the interval in seconds at which to take snapshots
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not represent a valid one
Note
To get the temporary results, call
download_results()
.
-
instant
()[source]¶ Make a snapshot of the current task.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
To get the temporary results, call
download_results()
.
-
state
¶ Type: str
Getter: return this task’s state State of the task.
- Value is in
- UnSubmitted
- Submitted
- PartiallyDispatched
- FullyDispatched
- PartiallyExecuting
- FullyExecuting
- UploadingResults
- DownloadingResults
- Cancelled
- Success
- Failure
Warning
this is the state of the task when the object was retrieved, call
update()
for up to date value.
-
resources
¶ Type: list( Bucket
)Getter: Returns this task’s resources bucket Setter: Sets this task’s resources bucket Represents resource files.
-
results
¶ Type: Bucket
Getter: Returns this task’s results bucket Setter: Sets this task’s results bucket Represents results files.
-
download_results
(output_dir, progress=None)[source]¶ Download results in given output_dir.
Parameters: Raises: - qarnot.exceptions.MissingBucketException – the bucket is not on the server
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
Warning
Will override output_dir content.
-
stdout
()[source]¶ Get the standard output of the task since the submission of the task.
Return type: Returns: The standard output.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
The buffer is circular, if stdout is too big, prefer calling
fresh_stdout()
regularly.
-
fresh_stdout
()[source]¶ Get what has been written on the standard output since last time this function was called or since the task has been submitted.
Return type: Returns: The new output since last call.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
stderr
()[source]¶ Get the standard error of the task since the submission of the task.
Return type: Returns: The standard error.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
Note
The buffer is circular, if stderr is too big, prefer calling
fresh_stderr()
regularly.
-
fresh_stderr
()[source]¶ Get what has been written on the standard error since last time this function was called or since the task has been submitted.
Return type: Returns: The new error messages since last call.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – task does not exist
-
uuid
¶ Type: str
Getter: Returns this task’s uuid The task’s uuid.
Automatically set when a task is submitted.
-
name
¶ Type: str
Getter: Returns this task’s name Setter: Sets this task’s name The task’s name.
Can be set until task is submitted.
-
shortname
¶ Type: str
Getter: Returns this task’s shortname Setter: Sets this task’s shortname The task’s shortname, must be DNS compliant and unique, if not provided, will default to
uuid
.Can be set until task is submitted.
Type: :class:list(str) Getter: Returns this task’s tags Setter: Sets this task’s tags Custom tags.
-
pool
¶ Type: Pool
Getter: Returns this task’s pool Setter: Sets this task’s pool The pool to run the task in.
Can be set until
run()
is called.Warning
This property is mutually exclusive with
profile
-
profile
¶ Type: str
Getter: Returns this task’s profile Setter: Sets this task’s profile The profile to run the task with.
Can be set until
run()
orsubmit()
is called.Warning
This property is mutually exclusive with
pool
-
instancecount
¶ Type: int
Getter: Returns this task’s instance count Setter: Sets this task’s instance count Number of instances needed for the task.
Can be set until
run()
orsubmit()
is called.Raises: AttributeError – if advanced_range
is not None when setting this propertyWarning
This property is mutually exclusive with
advanced_range
-
running_core_count
¶ Type: int
Getter: Returns this task’s running core count Number of core running inside the task.
-
running_instance_count
¶ Type: int
Getter: Returns this task’s running instance count Number of instances running inside the task.
-
advanced_range
¶ Type: str
Getter: Returns this task’s advanced range Setter: Sets this task’s advanced range Advanced instances range selection.
Allows to select which instances will be computed. Should be None or match the following extended regular expression “([0-9]+|[0-9]+-[0-9]+)(,([0-9]+|[0-9]+-[0-9]+))+” eg: 1,3-8,9,12-19
Can be set until
run()
is called.Raises: AttributeError – if instancecount
is not 0 when setting this propertyWarning
This property is mutually exclusive with
instancecount
-
snapshot_whitelist
¶ Type: str
Getter: Returns this task’s snapshot whitelist Setter: Sets this task’s snapshot whitelist Snapshot white list (regex) for
snapshot()
andinstant()
Can be set until task is submitted.
-
snapshot_blacklist
¶ Type: str
Getter: Returns this task’s snapshot blacklist Setter: Sets this task’s snapshot blacklist Snapshot black list (regex) for
snapshot()
instant()
Can be set until task is submitted.
-
results_whitelist
¶ Type: str
Getter: Returns this task’s results whitelist Setter: Sets this task’s results whitelist Results whitelist (regex)
Can be set until task is submitted.
-
results_blacklist
¶ Type: str
Getter: Returns this task’s results blacklist Setter: Sets this task’s results blacklist Results blacklist (regex)
Can be set until task is submitted.
-
status
¶ Type: qarnot.status.Status
Getter: Returns this task’s status Status of the task
-
completed_instances
¶ Type: list( CompletedInstance
)Getter: Return this task’s completed instances
-
creation_date
¶ Type: str
Getter: Returns this task’s creation date Creation date of the task (UTC Time)
-
errors
¶ Type: list( Error
)Getter: Returns this task’s errors if any. Error reason if any, empty string if none
-
constants
¶ Type: dictionary{ str
:str
}Getter: Returns this task’s constants dictionary. Setter: set the task’s constants dictionary. Update the constants if needed Constants are the parametrazer of the profils. Use them to adjust your profile parametter.
-
constraints
¶ Type: dictionary{ str
:str
}Getter: Returns this task’s constraints dictionary. Setter: set the task’s constraints dictionary. Update the constraints if needed advance usage
-
wait_for_pool_resources_synchronization
¶ Type: bool
or NoneGetter: Returns this task’s wait_for_pool_resources_synchronization. Setter: set the task’s wait_for_pool_resources_synchronization. Raises: qarnot.exceptions.AttributeError – can’t set this attribute on a launched task
-
auto_update
¶ Type: bool
Getter: Returns this task’s auto update state Setter: Sets this task’s auto update state Auto update state, default to True When auto update is disabled properties will always return cached value for the object and a call to
update()
will be required to get latest values from the REST Api.
-
update_cache_time
¶ Type: int
Getter: Returns this task’s auto update state Setter: Sets this task’s auto update state Cache expiration time, default to 5s
-
auto_delete
¶ Autodelete this Task if it is finished and your max number of task is reach
Can be set until
run()
orsubmit()
is called.Type: bool
Getter: Returns is this task must autodelete Setter: Sets this task’s autodelete Default_value: “False” Raises: AttributeError – if you try to reset the auto_delete after the task is submit
-
completion_ttl
¶ The task will be auto delete completion_ttl after it is finished
Can be set until
run()
orsubmit()
is called.Getter: Returns this task’s completed time to live. Type: str
Setter: Sets this task’s this task’s completed time to live. Type: str
ordatetime.timedelta
Default_value: “” Raises: AttributeError – if you try to set it after the task is submitted The completion_ttl must be a timedelta or a time span format string (example: ‘d.hh:mm:ss’ or ‘hh:mm:ss’)
-
-
class
qarnot.task.
CompletedInstance
(json)[source]¶ Bases:
object
Completed Instance Information
Note
Read-only class
-
results
= None¶ Type: :class:list(str) Instance produced results
-
Job¶
Module to handle a job.
-
class
qarnot.job.
Job
(connection, name, pool=None, shortname=None, use_dependencies=False)[source]¶ Bases:
object
Represents a Qarnot job.
Note
A
Job
must be created withqarnot.connection.Connection.create_job()
or retrieved withqarnot.connection.Connection.jobs()
orqarnot.connection.Connection.retrieve_job()
.-
__init__
(connection, name, pool=None, shortname=None, use_dependencies=False)[source]¶ Create a new
Job
.Parameters: - connection (
qarnot.connection.Connection
) – the cluster on which to send the job - name (
str
) – given name of the job - pool (
Pool
or None) – which Pool to submit the job in, - shortname (
str
) – userfriendly job name - use_dependencies – allow dependencies between tasks in this job
- connection (
-
auto_update
¶ Type: bool
Getter: Returns this job’s auto update state Setter: Sets this job’s auto update state Auto update state, default to True When auto update is disabled properties will always return cached value for the object and a call to
update()
will be required to get latest values from the REST Api.
-
update_cache_time
¶ Type: int
Getter: Returns this job’s auto update state Setter: Sets this job’s auto update state Cache expiration time, default to 5s
-
state
¶ Type: str
Getter: return this job’s state State of the job.
- Value is in
- UnSubmitted
- Active,
- Terminating,
- Completed,
- Deleting
Warning
this is the state of the job when the object was retrieved, call
update()
for up to date value.
-
use_dependencies
¶ Type: bool
Getter: task’s job can have dependencies Setter: Set if there is task’s job dependencies Can be set until
submit()
is called.
-
uuid
¶ Type: str
Getter: Returns this job’s uuid The job’s uuid.
Automatically set when a job is submitted.
-
name
¶ Type: str
Getter: Returns this job’s name Setter: Sets this job’s name The job’s name.
Can be set until job is submitted.
-
shortname
¶ Type: str
Getter: Returns this job’s shortname Setter: Sets this job’s shortname The job’s shortname, must be DNS compliant and unique, if not provided, will default to
uuid
.Can be set until job is submitted.
-
max_wall_time
¶ Type: str
Getter: Returns this job’s maximum wall time Setter: Sets this job’s maximum wall time The job’s maximum wall time. It is a time span string. Format example: ‘d.hh:mm:ss’ or ‘hh:mm:ss’
Can be set until job is submitted.
-
pool
¶ Type: Pool
Getter: Returns this job’s pool Setter: Sets this job’s pool The pool to run the job in.
Can be set until
submit()
is called.
-
classmethod
from_json
(connection, payload)[source]¶ Create a Job object from a json job.
Parameters: - connection (qarnot.connection.Connection) – the cluster connection
- json_job (dict) – Dictionary representing the job
Returns: The created
Job
.
-
submit
()[source]¶ Submit job to the cluster if it is not already submitted.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.MaxJobException – Job quota reached
- qarnot.exceptions.NotEnoughCreditsException – Not enough credits
- qarnot.exceptions.UnauthorizedException – invalid credentials
-
update
(flushcache=False)[source]¶ Update the job object from the REST Api. The flushcache parameter can be used to force the update, otherwise a cached version of the object will be served when accessing properties of the object. Cache behavior is configurable with
auto_update
andupdate_cache_time
.Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingJobException – job does not exist
-
terminate
()[source]¶ Terminate this job on the server and abort all remaining tasks in the job.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingJobException – job does not exist
-
delete
(forceAbort=False)[source]¶ Delete this job on the server.
The forceAbort parameter can be used to force running task in the job to be aborted,
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.UnauthorizedException – job still contains running tasks
- qarnot.exceptions.MissingJobException – job does not exist
-
auto_delete
¶ Autodelete this job if it is finished and your max number of job is reach
Can be set until
submit()
is called.Type: bool
Getter: Returns is this job must autodelete Setter: Sets this job’s autodelete Default_value: “False” Raises: AttributeError – if you try to reset the auto_delete after the job is submit
-
completion_ttl
¶ The job will be auto delete completion_ttl after it is finished
Can be set until
submit()
is called.Getter: Returns this job’s completed time to live. Type: str
Setter: Sets this job’s this job’s completed time to live. Type: str
ordatetime.timedelta
Default_value: “” Raises: AttributeError – if you try to set it after the job is submitted The completion_ttl must be a timedelta or a time span format string (example: ‘d.hh:mm:ss’ or ‘hh:mm:ss’)
-
Pool¶
Module to handle a pool.
-
class
qarnot.pool.
Pool
(connection, name, profile, instancecount=1, shortname=None)[source]¶ Bases:
object
Represents a Qarnot pool.
Note
A
Pool
must be created withqarnot.connection.Connection.create_pool()
or retrieved withqarnot.connection.Connection.pools()
orqarnot.connection.Connection.retrieve_pool()
.-
__init__
(connection, name, profile, instancecount=1, shortname=None)[source]¶ Create a new
Pool
.Parameters:
-
classmethod
from_json
(connection, json_pool, is_summary=False)[source]¶ Create a Pool object from a json pool.
Parameters: - connection (qarnot.connection.Connection) – the cluster connection
- json_pool (dict) – Dictionary representing the pool
Returns: The created
Pool
.
-
submit
()[source]¶ Submit pool to the cluster if it is not already submitted.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.MaxPoolException – Pool quota reached
- qarnot.exceptions.NotEnoughCreditsException – Not enough credits
- qarnot.exceptions.UnauthorizedException – invalid credentials
Note
Will ensure all added files are on the resource bucket regardless of their uploading mode.
-
update
(flushcache=False)[source]¶ Update the pool object from the REST Api. The flushcache parameter can be used to force the update, otherwise a cached version of the object will be served when accessing properties of the object. Cache behavior is configurable with
auto_update
andupdate_cache_time
.Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – pool does not represent a valid one
-
commit
()[source]¶ Replicate local changes on the current object instance to the REST API
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
This function need to be call to apply the local elastic pool setting modifications. .. note:: When updating buckets’ properties, auto update will be disabled until commit is called.
-
setup_elastic
(minimum_total_slots=0, maximum_total_slots=1, minimum_idle_slots=0, minimum_idle_time_seconds=0, resize_factor=1, resize_period=90)[source]¶ Setup the pool elastic properties
Parameters: - minimum_total_slots (int) – Minimum slot number for the pool in elastic mode. Defaults to 0.
- maximum_total_slots (int) – Maximum slot number for the pool in elastic mode. Defaults to 1.
- minimum_idle_slots (int) – Minimum idling slot number. Defaults to 0.
- minimum_idle_time_seconds (int) – Wait time in seconds before closing an unused slot if the number of unused slots are upper than the minimum_idle_slots. Defaults to 0.
- resize_factor (float) – Growing factor of the pool. It must be a number between 0 and 1. Defaults to 1.
- resize_period (int) – Refresh rate of resizing the pool in elastic mode. Defaults to 90.
-
delete
(purge_resources=False)[source]¶ Delete this pool on the server.
Parameters: purge_resources (bool) – parameter value is used to determine if the bucket is also deleted. Defaults to False.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingTaskException – pool does not exist
-
close
()[source]¶ Close this pool if running.
Raises: - qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
- qarnot.exceptions.MissingPoolException – pool does not exist
-
uuid
¶ Type: str
Getter: Returns this pool’s uuid The pool’s uuid.
Automatically set when a pool is submitted.
-
state
¶ Type: str
Getter: return this pool’s state State of the pool.
- Value is in
- UnSubmitted
- Submitted
- PartiallyDispatched
- FullyDispatched
- PartiallyExecuting
- FullyExecuting
- Closing
- Closed
- Failure
- PendingDelete
Warning
this is the state of the pool when the object was retrieved, call
update()
for up to date value.
-
resources
¶ Type: list( Bucket
)Getter: Returns this pool’s resources bucket Setter: Sets this pool’s resources bucket Represents resource files.
-
name
¶ Type: str
Getter: Returns this pool’s name Setter: Sets this pool’s name The pool’s name.
Can be set until pool is submitted.
-
shortname
¶ Type: str
Getter: Returns this pool’s shortname Setter: Sets this pool’s shortname The pool’s shortname, must be DNS compliant and unique, if not provided, will default to
uuid
.Can be set until pool is submitted.
Type: :class:list(str) Getter: Returns this pool’s tags Setter: Sets this pool’s tags Custom tags.
-
profile
¶ Type: str
Getter: Returns this pool’s profile Setter: Sets this pool’s profile The profile to run the pool with.
Can be set until
submit()
is called.
-
instancecount
¶ Type: int
Getter: Returns this pool’s instance count Setter: Sets this pool’s instance count Number of instances needed for the pool.
Can be set until
submit()
is called.
-
running_core_count
¶ Type: int
Getter: Returns this pool’s running core count Number of core running inside the pool.
-
running_instance_count
¶ Type: int
Getter: Returns this pool’s running instance count Number of instances running inside the pool.
-
errors
¶ Type: list( str
)Getter: Returns this pool’s error list Error reason if any, empty string if none
-
creation_date
¶ Type: str
Getter: Returns this pool’s creation date Creation date of the pool (UTC Time)
-
status
¶ Type: qarnot.status.Status
Getter: Returns this pool’s status Status of the task
-
auto_update
¶ Type: bool
Getter: Returns this pool’s auto update state Setter: Sets this pool’s auto update state Auto update state, default to True When auto update is disabled properties will always return cached value for the object and a call to
update()
will be required to get latest values from the REST Api.
-
update_cache_time
¶ Type: int
Getter: Returns this pool’s auto update state Setter: Sets this pool’s auto update state Cache expiration time, default to 5s
-
is_elastic
¶ Type: bool
Getter: Returns this pool’s is_elastic Setter: Sets this pool’s is_elastic Define if you use a static or an elastic pool.
-
elastic_minimum_slots
¶ Type: int
Getter: Returns this pool’s elastic_minimum_slots Setter: Sets this pool’s elastic_minimum_slots The minimum slot number of the elastic pool. Define the minimum number of pool instances stay open during the pool execution.
-
elastic_maximum_slots
¶ Type: int
Getter: Returns this pool’s elastic_maximum_slots Setter: Sets this pool’s elastic_maximum_slots The maximum slot number of the elastic pool. Define the maximum number of pool instances opened during the pool execution.
-
elastic_minimum_idle_slots
¶ Type: int
Getter: Returns this pool’s elastic_minimum_idle_slots Setter: Sets this pool’s elastic_minimum_idle_slots The minimum idle number of the elastic pool. Define the minimum number of the idle pool instances stay opened during the pool execution. It should be lower to elastic_minimum_slots to be usefull
-
elastic_minimum_idle_time
¶ Type: int
Getter: Returns this pool’s elastic_minimum_idle_time Setter: Sets this pool’s elastic_minimum_idle_time Wait time in seconds before closing an unused slot if the number of unused slots are upper than the minimum_idle_slots.
-
elastic_resize_factor
¶ Type: float
Getter: Returns this pool’s elastic_resize_factor Setter: Sets this pool’s elastic_resize_factor The resize factor of the pool. It represent the resize factor of the slots. It’s a decimal number upper than 0 and and equal or lower the 1
-
elastic_resize_period
¶ Type: int
Getter: Returns this pool’s elastic_resize_period Setter: Sets this pool’s elastic_resize_period The resize period of the elastic pool in second. This is the refresh rate of resizing the elastic pool.
-
preparation_command_line
¶ Type: str
:Getter: Returns this pool’s command line. Setter: set the pool’s command line. Update the pool command line if needed The command line is a command running before each task execution.
-
constants
¶ Type: dictionary{ str
:str
}Getter: Returns this pool’s constants dictionary. Setter: set the pool’s constants dictionary. Update the constants if needed Constants are the parametrazer of the profils. Use them to adjust your profile parametter.
-
constraints
¶ Type: dictionary{ str
:str
}Getter: Returns this pool’s constraints dictionary. Setter: set the pool’s constraints dictionary. Update the constraints if needed advance usage
-
tasks_default_wait_for_pool_resources_synchronization
¶ Type: bool
Getter: Returns this task’s tasks_default_wait_for_pool_resources_synchronization. Setter: set the task’s tasks_default_wait_for_pool_resources_synchronization. Raises: qarnot.exceptions.AttributeError – can’t set this attribute on a launched task
-
auto_delete
¶ Autodelete this pool if it is finished and your max number of pool is reach
Can be set until
submit()
is called.Type: bool
Getter: Returns is this pool must autodelete Setter: Sets this pool’s autodelete Default_value: “False” Raises: AttributeError – if you try to reset the auto_delete after the pool is submit
-
completion_ttl
¶ The pool will be auto delete completion_ttl after it is finished
Can be set until
submit()
is called.Getter: Returns this pool’s completed time to live. Type: str
Setter: Sets this pool’s this pool’s completed time to live. Type: str
ordatetime.timedelta
Default_value: “” Raises: AttributeError – if you try to set it after the pool is submitted The completion_ttl must be a timedelta or a time span format string (example: ‘d.hh:mm:ss’ or ‘hh:mm:ss’)
-
Status¶
-
class
qarnot.status.
Status
(json)[source]¶ Bases:
object
The status object of the running pools and tasks. To retrieve the status of a pool, use:
- my_pool.status
- To retrieve the status of a task, use:
- my_task.status
Note
Read-only class
-
running_instances_info
= None¶ Type: RunningInstancesInfo
Running instances information.
-
class
qarnot.status.
RunningInstancesInfo
(json)[source]¶ Bases:
object
Running Instances Information
Note
Read-only class
-
per_running_instance_info
= None¶ Type: list( PerRunningInstanceInfo
)Per running instances information.
-
-
class
qarnot.status.
PerRunningInstanceInfo
(json)[source]¶ Bases:
object
Per Running Instance Information
Note
Read-only class
-
active_forward
= None¶ type: list(
TaskActiveForward
)Active forwards list.
-
vpn_connections
= None¶ type: list(
TaskVpnConnection
)Vpn connection list.
-
-
class
qarnot.status.
TaskActiveForward
(json)[source]¶ Bases:
object
Task Active Forward
Note
Read-only class
Storage¶
Storage¶
Storage prototype
-
class
qarnot.storage.
Storage
[source]¶ Bases:
object
Common architecture for storage providers
-
get_all_files
(output_dir, progress=None)[source]¶ Get all files from the storage.
Parameters: Raises: - qarnot.exceptions.MissingBucketException – the bucket is not on the server
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
Warning
Will override output_dir content.
-
list_files
()[source]¶ List files on the storage.
- … note:
- File object returned must have a key property.
Returns: List of the files on the storage.
-
get_file
(remote, local=None, progress=None)[source]¶ Get a file from the storage. Create needed subfolders.
Parameters: Return type: Returns: The name of the output file.
Raises: ValueError – no such file
-
add_directory
(local, remote)[source]¶ Add a directory to the storage. Does not follow symlinks. File hierarchy is preserved.
Parameters: Raises: IOError – not a valid directory
-
add_file
(local_or_file, remote)[source]¶ Add a local file or a Python File on the storage.
Note
You can also use object[remote] = local
Parameters:
-
delete_file
(remote)[source]¶ Delete a file from the storage.
Parameters: remote (str) – the name of the remote file
-
Bucket¶
Module for bucket object.
-
class
qarnot.bucket.
Bucket
(connection, name, create=True)[source]¶ Bases:
qarnot.storage.Storage
Represents a resource/result bucket.
This class is the interface to manage resources or results from a
qarnot.bucket.Bucket
.Note
A
Bucket
must be created withqarnot.connection.Connection.create_bucket()
or retrieved withqarnot.connection.Connection.buckets()
,qarnot.connection.Connection.retrieve_bucket()
, orqarnot.connection.Connection.retrieve_or_create_bucket()
.Note
Paths given as ‘remote’ arguments, (or as path arguments for
Bucket.directory()
) must be valid unix-like paths.-
__init__
(connection, name, create=True)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
-
list_files
()[source]¶ List files in the bucket
Return type: list( S3.ObjectSummary
)Returns: A list of ObjectSummary resources
-
directory
(directory='')[source]¶ List files in a directory of the bucket according to prefix.
Return type: list( S3.ObjectSummary
)Returns: A list of ObjectSummary resources
-
sync_directory
(directory, verbose=False, remote=None)[source]¶ Synchronize a local directory with the remote buckets.
Parameters: Warning
Local changes are reflected on the server, a file present on the bucket but not in the local directory will be deleted from the bucket.
A file present in the directory but not in the bucket will be uploaded.
Note
The following parameters are used to determine whether synchronization is required :
- name
- size
- sha1sum
-
sync_files
(files, verbose=False, remote=None)[source]¶ Synchronize files with the remote buckets.
Parameters: Dictionary key is the remote file path while value is the local file path.
Warning
Local changes are reflected on the server, a file present on the bucket but not in the local directory will be deleted from the bucket.
A file present in the directory but not in the bucket will be uploaded.
Note
The following parameters are used to determine whether synchronization is required :
- name
- size
- sha1sum
-
add_file
(local_or_file, remote=None)[source]¶ Add a local file or a Python File on the storage.
Note
You can also use object[remote] = local
Parameters:
-
get_all_files
(output_dir, progress=None)[source]¶ Get all files from the storage.
Parameters: Raises: - qarnot.exceptions.MissingBucketException – the bucket is not on the server
- qarnot.exceptions.QarnotGenericException – API general error, see message for details
- qarnot.exceptions.UnauthorizedException – invalid credentials
Warning
Will override output_dir content.
-
get_file
(remote, local=None, progress=None)[source]¶ Get a file from the storage. Create needed subfolders.
Parameters: Return type: Returns: The name of the output file.
Raises: ValueError – no such file
-
add_directory
(local, remote='')[source]¶ Add a directory to the storage. Does not follow symlinks. File hierarchy is preserved.
Parameters: Raises: IOError – not a valid directory
-
update
(flush=False)[source]¶ Update object from remote endpoint
Parameters: flush (bool) – bypass cache
-
delete_file
(remote)[source]¶ Delete a file from the storage.
Parameters: remote (str) – the name of the remote file
-
uuid
¶ Bucket identifier
-
description
¶ Bucket identifier
-
Exceptions¶
Exceptions.
-
exception
qarnot.exceptions.
QarnotGenericException
(msg)[source]¶ Bases:
qarnot.exceptions.QarnotException
General Connection exception
Bases:
qarnot.exceptions.QarnotException
API bucket storage is disabled.
Bases:
qarnot.exceptions.QarnotException
Invalid token.
-
exception
qarnot.exceptions.
MissingTaskException
[source]¶ Bases:
qarnot.exceptions.QarnotException
Non existent task.
-
exception
qarnot.exceptions.
MissingBucketException
[source]¶ Bases:
qarnot.exceptions.QarnotException
Non existent bucket.
-
exception
qarnot.exceptions.
MissingPoolException
[source]¶ Bases:
qarnot.exceptions.QarnotException
Non existent pool.
-
exception
qarnot.exceptions.
MaxTaskException
[source]¶ Bases:
qarnot.exceptions.QarnotException
Max number of tasks reached.
-
exception
qarnot.exceptions.
MaxPoolException
[source]¶ Bases:
qarnot.exceptions.QarnotException
Max number of pools reached.
-
exception
qarnot.exceptions.
NotEnoughCreditsException
[source]¶ Bases:
qarnot.exceptions.QarnotException
Not enough credits exception.