Package: oscar-python
Python OSCAR clientThis package provides a client to interact with OSCAR (https://oscar.grycap.net) clusters and services. It is available on Pypi with the nameoscar-python.ContentsPython OSCAR clientContentsClientInitialize a client with basic authenticationInitialize a client OIDC authenticationSample usageClient methodsCluster methodsService methodsLogs methodsStorage usageClientInitialize a client with basic authenticationoptions_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 authenticationIf you want to use OIDC tokens to authenticate with EGI Check-In, you can use theOIDC Agentto create an account configuration for the EGI issuer (https://aai.egi.eu/auth/realms/egi/) and then initialize the client specifying theshortnameof 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 parameteroidc_tokeninstead.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.Sample usageSample code that creates a client and gets information about the clusterfromoscar_python.clientimportClientoptions_basic_auth={'cluster_id':'cluster-id','endpoint':'https://cluster-endpoint','user':'username','password':'password','ssl':'True'}client=Client(options=options)# get the cluster informationtry:info=client.get_cluster_info()print(info.text)exceptExceptionaserr:print("Failed with: ",err)Sample code to create a simple service with thecowsay exampleand make a synchronous invocation.fromoscar_python.clientimportClientoptions_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"}')ifresponse.status_code==200:print(response.text)exceptExceptionaserr:print("Failed with: ",err)Client methodsCluster methodsget_cluster_info# get the cluster informationinfo=client.get_cluster_info()# returns an HTTP response or an HTTPErrorget_cluster_config# get the cluster configconfig=client.get_cluster_config()# returns an http response or an HTTPErrorService methodsget_service# get the definition of a serviceservice=client.get_service("service_name")# returns an http response or an HTTPErrorlist_services# get a list of all the services deployedservices=client.list_services()# returns an http response or an HTTPErrorNote: Bothpath_to_fdland the script path inside the fdl must be absolute.create_service# create a serviceerr=client.create_service("path_to_fdl"|"JSON_definition")# returns nothing if the service is created or an error if something goes wrongupdate_service# update a serviceerr=client.update_service("service_name","path_to_fdl"|"JSON_definition")# returns nothing if the service is created or an error if something goes wrongremove_service# remove a serviceresponse=client.remove_service("service_name")# returns an http responserun_serviceinput,outputandtimeoutare optional parameters.# make a synchronous executionresponse=client.run_service("service_name",input="input",output="out.png",timeout=100)# returns an http responseLogs methodsget_job_logs# get logs of a joblogs=client.get_job_logs("service_name","job_id")# returns an http responselist_jobs# get a list of jobs in a servicelog_list=client.list_jobs("service_name")# returns an http responseremove_job# remove a job of a serviceresponse=client.remove_job("service_name","job_id")# returns an http responseremove_all_jobs# remove all jobs in a serviceresponse=client.remove_all_jobs("service_name")# returns an http responseStorage usageYou can create a storage object to operate over the different storage providers defined on a service with the methodcreate_storage_clientas follows:storage_service=client.create_storage_client("service_name")# returns a storage objectNote: Thestorage_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_pathThis 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 providerfiles=storage_service.list_files_from_path("storage_provider")# returns jsonupload_file# upload a file from a local path to a remote pathresponse=storage_service.upload_file("storage_provider","local_path","remote_path")download_file# download a file from a remote path to a local pathresponse=storage_service.download_file("storage_provider","local_path","remote_path")