Python client for OSCAR clusters
Project description
Python OSCAR client
This package provides a client to interact with OSCAR (https://oscar.grycap.net) clusters and services. It is available on Pypi with the name oscar-python.
Contents
Client
Initialize a client with basic authentication
options_basic_auth = {'cluster_id':'cluster-id',
'endpoint':'https://cluster-endpoint',
'user':'username',
'password':'password',
'ssl':'True'}
client = Client(options = options_basic_auth)
Initialize a client OIDC authentication
If you want to use OIDC tokens to authenticate with EGI Check-In, you can use the OIDC Agent to create an account configuration for the EGI issuer (https://aai.egi.eu/auth/realms/egi/) and then initialize the client specifying the shortname of your account like follows.
options_oidc_auth = {'cluster_id':'cluster-id',
'endpoint':'https://cluster-endpoint',
'shortname':'oidc-agent-shortname',
'ssl':'True'}
client = Client(options = options_oidc_auth)
If you already have a valid token, you can use the parameter oidc_token instead.
options_oidc_auth = {'cluster_id':'cluster-id',
'endpoint':'https://cluster-endpoint',
'oidc_token':'token',
'ssl':'True'}
client = Client(options = options_oidc_auth)
An example of using a generated token is if you want to use EGI Notebooks. Since you can't use oidc-agent on the Notebook, you can make use of the generated token that EGI provides on path /var/run/secrets/egi.eu/access_token.
If you have a valid refresh token (long live token), you can use the parameter refresh_token instead.
options_oidc_auth = {'cluster_id':'cluster-id',
'endpoint':'https://cluster-endpoint',
'refresh_token':'token',
'ssl':'True'}
client = Client(options = options_oidc_auth)
You can get a refresh token from EGI Check-In using the Token Portal.
In case of using other OIDC provider you must provide two additional parameters token_endpoint
and scopes:
options_oidc_auth = {'cluster_id':'cluster-id',
'endpoint':'https://cluster-endpoint',
'refresh_token':'token',
'scopes': ["openid", "profile", "email"],
'token_endpoint': "http://issuer.com/token",
'client_id': "your_client_id"
'ssl':'True'}
client = Client(options = options_oidc_auth)
Sample usage
- Sample code that creates a client and gets information about the cluster
from oscar_python.client import Client
options_basic_auth = {'cluster_id':'cluster-id',
'endpoint':'https://cluster-endpoint',
'user':'username',
'password':'password',
'ssl':'True'}
client = Client(options = options)
# get the cluster information
try:
info = client.get_cluster_info()
print(info.text)
except Exception as err:
print("Failed with: ", err)
- Sample code to create a simple service with the cowsay example and make a synchronous invocation.
from oscar_python.client import Client
options_basic_auth = {'cluster_id':'cluster-id',
'endpoint':'https://cluster-endpoint',
'user':'username',
'password':'password',
'ssl':'True'}
client = Client(options = options)
try:
client.create_service("/absolute_path/cowsay.yaml")
response = client.run_service("cowsay", input = '{"message": "Hi there"}')
if response.status_code == 200:
print(response.text)
except Exception as err:
print("Failed with: ", err)
Client methods
Cluster methods
get_cluster_info
# get the cluster information
info = client.get_cluster_info() # returns an HTTP response or an HTTPError
get_cluster_config
# get the cluster config
config = client.get_cluster_config() # returns an http response or an HTTPError
Service methods
get_service
# get the definition of a service
service = client.get_service("service_name") # returns an http response or an HTTPError
list_services
# get a list of all the services deployed
services = client.list_services() # returns an http response or an HTTPError
Note : Both
path_to_fdland the script path inside the fdl must be absolute.
create_service
# create a service
err = client.create_service("path_to_fdl" | "JSON_definition") # returns nothing if the service is created or an error if something goes wrong
update_service
# update a service
err = client.update_service("service_name","path_to_fdl" | "JSON_definition") # returns nothing if the service is created or an error if something goes wrong
remove_service
# remove a service
response = client.remove_service("service_name") # returns an http response
run_service
input, output and timeout are optional parameters.
# make a synchronous execution
response = client.run_service("service_name", input="input", output="out.png", timeout=100) # returns an http response
# make an asynchronous execution
response = client.run_service("service_name", input="input", async_call=True) # returns an http response
Logs methods
get_job_logs
# get logs of a job
logs = client.get_job_logs("service_name", "job_id") # returns an http response
list_jobs
# get a list of jobs in a service
log_list = client.list_jobs("service_name") # returns an http response
# to get more jobs use the page parameter
log_list = client.list_jobs("service_name",page="token_to_next_page") # returns an http response
remove_job
# remove a job of a service
response = client.remove_job("service_name", "job_id") # returns an http response
remove_all_jobs
# remove all jobs in a service
response = client.remove_all_jobs("service_name") # returns an http response
Storage usage
You can create a storage object to operate over the different storage providers defined on a service with the method create_storage_client. This constructor returns a storage object with methos to interact with the storage providers.
The default constructor, seen as follows, will create a provider to interact with the default MinIO instance through the user's credentials.
storage_service = client.create_storage_client() # returns a storage object
Additionally, if you need to interact with specific storage providers defined on a service, the constructor accepts a svc parameter where you can state the service name from which to search for additional credentials.
storage_service = client.create_storage_client("service_name") # returns a storage object
Note : The
storage_providerparameter on the storage methods follows the format:["storage_provider_type"].["storage_provider_name"]wherestorage_provider_typeis one of the suported storage providers (minIO, S3, Onedata or webdav) andstorage_provider_nameis the identifier (ex: minio.default)
list_files_from_path
This method returns a JSON with the info except for OneData, which returns an HTTP response.
# get a list of the files of one of the service storage provider
files = storage_service.list_files_from_path("storage_provider", "remote_path") # returns json
upload_file
# upload a file from a local path to a remote path
response = storage_service.upload_file("storage_provider", "local_path", "remote_path")
download_file
# download a file from a remote path to a local path
response = storage_service.download_file("storage_provider", "local_path", "remote_path")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oscar_python-1.3.4b1.tar.gz.
File metadata
- Download URL: oscar_python-1.3.4b1.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8ea529d73fe521413daeaad3ba62d669d4b7d28ba8e41ac116f3f12f7090c05
|
|
| MD5 |
b0971373d3d881f47e563656f3ff87a0
|
|
| BLAKE2b-256 |
460a78c0a28b1b48594ad6c27be855d52b25800773a31d5602cfb1d4b90cebd2
|
Provenance
The following attestation bundles were made for oscar_python-1.3.4b1.tar.gz:
Publisher:
release-build.yaml on grycap/oscar_python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oscar_python-1.3.4b1.tar.gz -
Subject digest:
e8ea529d73fe521413daeaad3ba62d669d4b7d28ba8e41ac116f3f12f7090c05 - Sigstore transparency entry: 855029787
- Sigstore integration time:
-
Permalink:
grycap/oscar_python@1dd064cdaffa5350d25cff79c4bb6c3dc542b940 -
Branch / Tag:
refs/tags/v1.3.4-beta1 - Owner: https://github.com/grycap
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-build.yaml@1dd064cdaffa5350d25cff79c4bb6c3dc542b940 -
Trigger Event:
release
-
Statement type:
File details
Details for the file oscar_python-1.3.4b1-py3-none-any.whl.
File metadata
- Download URL: oscar_python-1.3.4b1-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ce7b61d07c038cd7ea0e57d4406bcec82a2dc99c9cbb618db464eb96f0b1767
|
|
| MD5 |
85baaaf07547e4e915d8a1d15ca2074f
|
|
| BLAKE2b-256 |
ff5b4024696f56e0ab0f1c37405b219dbdb7a960918b595ea5eee9cdcef3beeb
|
Provenance
The following attestation bundles were made for oscar_python-1.3.4b1-py3-none-any.whl:
Publisher:
release-build.yaml on grycap/oscar_python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oscar_python-1.3.4b1-py3-none-any.whl -
Subject digest:
6ce7b61d07c038cd7ea0e57d4406bcec82a2dc99c9cbb618db464eb96f0b1767 - Sigstore transparency entry: 855029790
- Sigstore integration time:
-
Permalink:
grycap/oscar_python@1dd064cdaffa5350d25cff79c4bb6c3dc542b940 -
Branch / Tag:
refs/tags/v1.3.4-beta1 - Owner: https://github.com/grycap
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-build.yaml@1dd064cdaffa5350d25cff79c4bb6c3dc542b940 -
Trigger Event:
release
-
Statement type: