Apps#
- class saagieapi.apps.Apps(saagie_api)#
Bases:
object
- static check_alerting(alerting: Dict = None, emails: List = None, logins: List = None, status_list: List = None) Dict #
Check if the alerting is enabled for the given app and if so, check alerting and status_list. If any parameter is missing, it will be set to the current value.
- Parameters:
- Returns:
Dict containing alert config
- Return type:
- Raises:
RunTimeError – When the statut list is not valid
- static check_exposed_ports(exposed_ports: List[Dict])#
Check if exposed ports are valid
- Parameters:
exposed_ports (List[Dict]) – List of exposed ports, each item of the list should be a dict and each dict must have ‘number’ (int), ‘scope’ (‘GLOBAL’ or ‘PROJECT’), and ‘isRewriteUrl’ (Boolean) as key, and only contain valid keys
- Returns:
True if all exposed port are in a valid format False otherwise
- Return type:
- count_history_statuses(history_id, version_number, start_time)#
Get count of statues history of the app
- Parameters:
- Returns:
count of statuses history
- Return type:
Examples
>>> saagieapi.apps.count_history_statuses( ... history_id="history_app_id", ... version_number="version_number", ... start_time="start_date" ... ) { 'countAppHistoryStatuses': 6 }
- create_from_catalog(project_id: str, context: str, technology_id: str = None, technology_catalog: str = 'Saagie', technology_name: str = None) Dict #
Create an app in a specific project. If technology_id is provided, the catalog and name will be ignored.
- Parameters:
- Returns:
Dict of app information
- Return type:
Examples
>>> saagieapi.apps.create_from_catalog( ... project_id="your_project_id", ... context="7.15.1", ... technology_name="kibana" ... ) { 'installApp': { 'id': 'a6de6956-4038-493e-bbd3-f7b3616df39e', 'name': 'Kibana' } }
- create_from_scratch(project_id: str, app_name: str, image: str = '', description: str = '', exposed_ports: List[Dict] = None, storage_paths: List[Dict] = None, release_note: str = '', docker_credentials_id: str = None, emails: List = None, logins: List = None, status_list: List = None, resources: Dict = None, technology_id: str = None, technology_context: str = None) Dict #
Create an app in a specific project.
- Parameters:
project_id (str) – ID of the project.
app_name (str) – Name of the app.
description (str) – Description of the app.
image (str) – Tag of the Docker Image. Incompatible with parameters technology_id & technology_context. Example: ‘hello-world:nanoserver-ltc2022’.
docker_credentials_id (str) – Credentials’s ID for the image if the image is not public. Incompatible with parameters technology_id & technology_context.
exposed_ports (list of dict) –
List of dictionaries of exposed ports. Each dict should contain ‘port’ as key. Example: [{“basePathVariableName”: “SAAGIE_BASE_PATH”,
”isRewriteUrl”: True, “scope”: “PROJECT”, “number”: 5000, “name”: “Test Port”}].
storage_paths (list of dict, optional) –
List of dictionaries indicating the volume path to the persistent storage and: - the id of the volume to be associated with the app.
Example: [{“path”: “/home”, “volumeId”: “cb70ad1d-7883-48ac-8740-2c8e5c5166ee”}]
or the information needed to create the volume. Example: [{“path”: “/home”, “volume”: {“name”: “storage name”,
”size”: “64 MB”, “description”: “storage description”}}].
release_note (str, optional) – Release note for the app version.
emails (list of str, optional) – Emails to receive alerts for the app. Each item should be a valid email.
logins (list of str, optional) – Logins to receive alerts for the app. Each item should be a valid login.
status_list (list of str, optional) – Receive an email when the app status changes to a specific status. Each item of the list should be one of these following values: “STARTING”, “STARTED”, “ROLLING_BACK”, “UPGRADING”, “RECOVERING”, “RESTARTING”, “STOPPING”, “STOPPED”, “FAILED”.
resources (dict, optional) – Resources CPU, RAM & GPU limited and guaranteed for the app.
technology_id (str, optional) – Technology id of the app. Incompatible with parameters image & docker_credentials_id.
technology_context (str, optional) – Context version of the app. Incompatible with parameters image & docker_credentials_id.
- Returns:
Dict of app information.
- Return type:
Examples
>>> saagieapi.apps.create_from_scratch( ... project_id="project_id", ... app_name="App Example Scratch", ... image="saagie/ttyd-saagie:1.0", ... exposed_ports=[ ... { ... "basePathVariableName": "SAAGIE_BASE_PATH", ... "isRewriteUrl": True, ... "scope": "PROJECT", ... "number": 7681, ... "name": "ttyd" ... } ... ] ... ) { 'createApp': { 'id': '1221f83e-52de-4beb-89a0-1505de4e875f' } }
- delete(app_id: str) Dict #
Delete a given app
- Parameters:
app_id (str) – UUID of your app (see README on how to find it)
- Returns:
Dict of deleted app
- Return type:
Examples
>>> saagieapi.apps.delete(app_id="a6de6956-4038-493e-bbd3-f7b3616df39e") { 'deleteApp': { 'id': 'a6de6956-4038-493e-bbd3-f7b3616df39e' } }
- edit(app_id: str, app_name: str = None, description: str = None, emails: List = None, logins: List = None, status_list: List = None) Dict #
Edit an app. Each optional parameter can be set to change the value of the corresponding field.
- Parameters:
app_id (str) – UUID of your app
app_name (str, optional) – App name If not filled, defaults to current value, else it will change the app’s name
description (str, optional) – Description of app if not filled, defaults to current value, else it will change the description of the app
emails (List[String], optional) – Emails to receive alerts for the app, each item should be a valid email, If you want to remove alerting, please set emails to [] or list() if not filled, defaults to current value
logins (List[String], optional) – Logins to receive alerts for the app, each item should be a valid login, If you want to remove alerting, please set logins to [] or list() if not filled, defaults to current value
status_list (List[String], optional) – Receive an email when the app status change to a specific status. Each item of the list should be one of these following values: “STARTING”,”STARTED”, “ROLLING_BACK”,”UPGRADING”,”RECOVERING”,”RESTARTING”,”STOPPING”,”STOPPED”,”FAILED”
- Returns:
Dict of app information
- Return type:
Examples
>>> saagieapi.apps.edit( ... app_id="a6de6956-4038-493e-bbd3-f7b3616df39e", ... app_name="App_Example_Catalog_modify", ... emails=["hello.world@gmail.com"], ... status_list=["FAILED"] ... ) { 'editApp': { 'id': 'a6de6956-4038-493e-bbd3-f7b3616df39e' } }
- export(app_id: str, output_folder: str, error_folder: str | None = '', versions_only_current: bool = False) bool #
Export the app in a folder
- Parameters:
app_id (str) – App ID
output_folder (str) – Path to store the exported app
error_folder (str, optional) – Path to store the error
error_folder – Path to store the app ID in case of error. If not set, app ID is not write
versions_only_current (bool, optional) – Whether to only fetch the current version of each app
- Returns:
True if app is exported False otherwise
- Return type:
Examples
>>> saagieapi.apps.export( ... app_id="befeacff-8b3b-4269-bf6d-73b5f369313a", ... output_folder="./output/app/", ... error_folder="./output/error/", ... versions_only_current=True ... ) True
- get_history_statuses(history_id, version_number, start_time)#
Get statuses history of the app
- Parameters:
- Returns:
Dict of app’s statuses history
- Return type:
Examples
>>> saagieapi.apps.get_history_statuses( ... history_id="history_app_id", ... version_number="version_number", ... start_time="start_date" ... ) { 'appHistoryStatuses': [ {'status': 'STARTING', 'recordAt': '2023-08-01T08:38:34.859Z'}, {'status': 'STARTED', 'recordAt': '2023-08-01T08:38:38.845Z'}, {'status': 'FAILED', 'recordAt': '2023-08-01T08:38:39.875Z'}, {'status': 'RECOVERING', 'recordAt': '2023-08-01T08:38:39.875Z'}, {'status': 'STOPPING', 'recordAt': '2023-08-01T08:38:41.094Z'}, {'status': 'STOPPED', 'recordAt': '2023-08-01T08:38:41.241Z'} ] }
- get_id(app_name: str, project_name: str) str #
Get the app id with the app name and project name
- Parameters:
- Returns:
App UUID
- Return type:
Examples
>>> saagieapi.apps.get_id( ... app_name="my-app", ... project_name="my-project" ... ) "860b8dc8-e634-4c98-b2e7-f9ec32ab4771"
- get_info(app_id: str, versions_only_current: bool = True, pprint_result: bool | None = None) Dict #
Get app with given UUID.
- Parameters:
- Returns:
Dict of app information
- Return type:
Examples
>>> saagieapi.apps.get_info(app_id="your_app_id") { 'app': { 'id': 'b6e846d7-d871-46db-b858-7d39d6b60123', 'name': 'Jupyter lab', 'creationDate': '2022-05-09T14:12:31.819Z', 'technology': { 'id': '7d3f247c-b5a9-4a34-a0a2-f6b209bc2b63' }, 'project': { 'id': '96a74193-303d-43cf-adb2-a7300d5bb9df', 'name': 'Saagie testing tool ' }, 'description': '', 'currentVersion': { 'number': 1, 'creator': 'toto.hi', 'creationDate': '2022-05-09T14:12:31.819Z', 'releaseNote': 'First version of Jupyter Notebook with Spark 3.1 into Saagie.', 'dockerInfo': None, 'runtimeContextId': 'jupyter-spark-3.1', 'ports': [ { 'name': 'Notebook', 'number': 8888, 'isRewriteUrl': False, 'basePathVariableName': 'SAAGIE_BASE_PATH', 'scope': 'PROJECT', 'internalUrl': 'http://app-b6e846d7-d871-46db-b858-7d39d6b60146:8888' }, { 'name': 'SparkUI', 'number': 8080, 'isRewriteUrl': False, 'basePathVariableName': 'SPARK_UI_PATH', 'scope': 'PROJECT', 'internalUrl': 'http://app-b6e846d7-d871-46db-b858-7d39d6b60146:8080' } ], 'volumesWithPath': [ { 'path': '/notebooks-dir', 'volume': { 'id': 'c163216a-b024-4cb1-8aae-0664bf2f58b4', 'name': 'storage Jupyter lab', 'creator': 'toto.hi', 'description': 'Automatically created by migration from app c163216a-b024-4cb1-8aae-0664bf2f58b4', 'size': '128 MB', 'projectId': '96a74193-303d-43cf-adb2-a7300d5bb9df', 'creationDate': '2022-05-09T14:12:31.819Z', 'linkedApp': { 'id': 'b6e846d7-d871-46db-b858-7d39d6b60146', 'name': 'Jupyter lab' } } } ], 'isMajor': False }, 'history': { 'id': '4f60dd23-4ec2-4996-b4da-d95376d72387', 'currentStatus': 'STARTED', 'currentExecutionId': 'f2d81d93-e1ae-4b09-a77e-4e50c13971ce', 'currentDockerInfo': { 'image': 'saagie/jupyter-python-nbk:pyspark-3.1.1-1.111.0', 'dockerCredentialsId': None }, 'startTime': '2022-09-21T09:47:27.342Z', 'events': [ { 'event': { 'recordAt': '2022-06-21T12:57:22.734Z', 'executionId': '7eb4649c-2bcf-4062-a7d2-528a9d950e6d', 'versionNumber': 1, 'author': 'user.test' } }, { 'event': { 'recordAt': '2022-06-21T12:57:22.9Z', 'executionId': '7eb4649c-2bcf-4062-a7d2-528a9d950e6d', 'status': 'STARTING' } }, { 'event': { 'recordAt': '2022-06-21T12:57:35.443Z', 'executionId': '7eb4649c-2bcf-4062-a7d2-528a9d950e6d', 'status': 'STARTED' } }, { 'event': { 'recordAt': '2022-06-24T14:28:01.647Z', 'executionId': '7eb4649c-2bcf-4062-a7d2-528a9d950e6d', 'author': 'user.test' } }, { 'event': { 'recordAt': '2022-06-24T14:28:01.726Z', 'executionId': '7eb4649c-2bcf-4062-a7d2-528a9d950e6d', 'status': 'STOPPING' } }, { 'event': { 'recordAt': '2022-06-24T14:28:01.81Z', 'executionId': '7eb4649c-2bcf-4062-a7d2-528a9d950e6d', 'status': 'STOPPED' } }, { 'event': { 'recordAt': '2022-06-29T07:41:41.713Z', 'executionId': '9e525435-684f-470e-9818-fb865776da09', 'versionNumber': 1, 'author': 'user.test' } }, { 'event': { 'recordAt': '2022-06-29T07:41:41.912Z', 'executionId': '9e525435-684f-470e-9818-fb865776da09', 'status': 'STARTING' } }, { 'event': { 'recordAt': '2022-06-29T07:48:22.359Z', 'executionId': '9e525435-684f-470e-9818-fb865776da09', 'status': 'STARTED' } } ]}, 'isGenericApp': False, 'alerting': None, 'resources': None, 'linkedVolumes': [ { 'size': '128 MB' } ] } }
- get_runtime_label_by_id(technology_id: str, runtime_id: str) str #
Get the label of runtime
- Parameters:
- Returns:
String of runtime label
- Return type:
Examples
>>> saagie_client.apps.get_runtime_label_by_id( ... technology_id="11d63963-0a74-4821-b17b-8fcec1234567", ... runtime_id="jupyter-spark-3.1" ... ) 'Jupyter Spark 3.1'
- get_stats(history_id, version_number, start_time)#
Get stats of the app
- Parameters:
- Returns:
Dict of app’s stats
- Return type:
Examples
>>> saagieapi.apps.get_stats( ... history_id="history_app_id", ... version_number="version_number", ... start_time="start_date" ... ) { 'appStats': { 'uptimePercentage': 0.04, 'downtimePercentage': 99.96, 'recoveredCount': 0 } }
- import_from_json(json_file: str, project_id: str) bool #
Import an app from JSON format
- Parameters:
- Returns:
True if app is imported False otherwise
- Return type:
Examples
>>> saagieapi.apps.import_from_json( ... json_file="/path/to/the/json/file.json", ... project_id="860b8dc8-e634-4c98-b2e7-f9ec32ab4771" ... ) True
- list_for_project(project_id: str, minimal: bool | None = False, versions_only_current: bool = False, pprint_result: bool | None = None) Dict #
List apps of project. NB: You can only list apps if you have at least the viewer role on the project.
- Parameters:
project_id (str) – UUID of your project (see README on how to find it)
minimal (bool, optional) – Whether to only return the app’s name and id, default to False
versions_only_current (bool, optional) – Whether to only fetch the current version of each app
pprint_result (bool, optional) – Whether to pretty print the result of the query, default to saagie_api.pprint_global
- Returns:
Dict of app information
- Return type:
Examples
>>> saagieapi.apps.list_for_project(project_id="your_project_id") { 'project': { 'apps': [ { 'id': 'd0d6a466-10d9-4120-8101-56e46563e05a', 'name': 'Jupyter Notebook', 'description': '', 'creationDate': '2022-02-23T08:50:24.326Z', 'creator': 'user.test', 'versions': [ { 'number': 1, 'creationDate': '2022-02-23T08:50:24.327Z', 'releaseNote': '', 'dockerInfo': None, 'runtimeContextId': 'jupyter-notebook-v2', 'creator': 'user.test', 'ports': [ { 'name': 'Notebook', 'number': 8888, 'isRewriteUrl': False, 'basePathVariableName': 'SAAGIE_BASE_PATH', 'scope': 'PROJECT', 'internalUrl': 'http://app-d0d6a466-10d9-4120-8101-56e46563e05a:8888' } ], 'isMajor': False, 'volumesWithPath': [ { 'path': '/notebooks-dir', 'volume': { 'id': '68a50c6b-3737-4b68-b033-464eedd02eb1', 'name': 'storage jupyter notebook', 'creator': 'user.test', 'description': 'Automatically created by migration from app 68a50c6b-3737-4b68-b033-464eedd02eb1', 'size': '128 MB', 'projectId': '96a12345-303d-43cf-adb2-a7300d5bb9df', 'creationDate': '2022-02-23T08:50:24.327Z', 'linkedApp': { 'id': 'd0d6a466-10d9-4120-8101-56e46563e05a', 'name': 'jupyter notebook' } } } ] } ], 'currentVersion': { 'number': 1, 'creationDate': '2022-02-23T08:50:24.327Z', 'releaseNote': '', 'dockerInfo': None, 'runtimeContextId': 'jupyter-notebook-v2', 'creator': 'user.test', 'ports': [ { 'name': 'Notebook', 'number': 8888, 'isRewriteUrl': False, 'basePathVariableName': 'SAAGIE_BASE_PATH', 'scope': 'PROJECT', 'internalUrl': 'http://app-d0d6a466-10d9-4120-8101-56e46563e05a:8888' } ], 'isMajor': False, 'volumesWithPath': [ { 'path': '/notebooks-dir', 'volume': { 'id': '68a50c6b-3737-4b68-b033-464eedd02eb1', 'name': 'storage jupyter notebook', 'creator': 'user.test', 'description': 'Automatically created by migration from app 68a50c6b-3737-4b68-b033-464eedd02eb1', 'size': '128 MB', 'projectId': '96a12345-303d-43cf-adb2-a7300d5bb9df', 'creationDate': '2022-02-23T08:50:24.327Z', 'linkedApp': { 'id': 'd0d6a466-10d9-4120-8101-56e46563e05a', 'name': 'jupyter notebook' } } } ] }, 'technology': { 'id': '7d3f247c-b5a9-4a34-a0a2-f6b209bc2b63' }, 'linkedVolumes': [ { 'id': '68a50c6b-3737-4b68-b033-464eedd02eb1', 'name': 'storage jupyter notebook', 'creator': 'user.test', 'description': 'Automatically created by migration from app 68a50c6b-3737-4b68-b033-464eedd02eb1', 'size': '128 MB', 'creationDate': '2022-02-23T08:50:24.327Z' } ], 'isGenericApp': False, 'history': { 'id': 'affea4dd-d894-4742-bbd2-dd3a09c92020', 'events': [ { 'event': { 'recordAt': '2022-06-29T07:40:19.754Z', 'executionId': '5980d8cf-7cb6-4340-bd84-d3d17bdb5ab6' }, 'transitionTime': '2022-06-29T07:40:19.754Z' }, { 'event': { 'recordAt': '2022-06-29T07:40:19.974Z', 'executionId': '5980d8cf-7cb6-4340-bd84-d3d17bdb5ab6' }, 'transitionTime': '2022-06-29T07:40:19.974Z' } ], 'runningVersionNumber': 1, 'currentDockerInfo': { 'image': 'saagie/jupyter-python-nbk:v2-1.95.0', 'dockerCredentialsId': None }, 'currentStatus': 'STOPPED', 'currentExecutionId': 'f29c940f-4622-4263-8cec-41ae68513885', 'startTime': '2022-06-29T08:14:49.205Z', 'stopTime': '2022-06-29T08:19:59.946Z' }, 'alerting': None, 'resources': None } ] } }
- list_for_project_minimal(project_id: str) Dict #
List only app names and ids in the given project . NB: You can only list apps if you have at least the viewer role on the project
- Parameters:
project_id (str) – UUID of your project (see README on how to find it)
- Returns:
Dict of apps ids and names
- Return type:
Examples
>>> saagieapi.apps.list_for_project_minimal(project_id="your_project_id") { 'project': { 'apps': [ { 'id': 'd0d6a466-10d9-4120-8101-56e46563e05a', 'name': 'Jupyter Notebook' } ] } }
- rollback(app_id: str, version_number: str)#
Rollback a given app to the given version
- Parameters:
- Returns:
Dict of rollback app
- Return type:
Examples
>>> saagie_api.apps.rollback(app_id="39c56012-0f59-4f51-9852-29a182eff13a", version_number=1) { "rollbackAppVersion": { "id": "39c56012-0f59-4f51-9852-29a182eff13a", "versions": [ { "number": 2 }, { "number": 1 } ], "currentVersion": { "number": 1 } } }
- run(app_id: str) Dict #
Run a given app
- Parameters:
app_id (str) – UUID of your app (see README on how to find it)
- Returns:
Dict of the given app information
- Return type:
Examples
>>> saagieapi.apps.run(app_id="a6de6956-4038-493e-bbd3-f7b3616df39e") { 'runApp': { 'id': 'a6de6956-4038-493e-bbd3-f7b3616df39e', 'versions': [ { 'number': 1 } ], 'history': { 'id': 'ba494615-88b7-4c54-ad57-34a90461c407', 'currentDockerInfo': { 'image': 'saagie/kibana:7.15.1-1.108.0', 'dockerCredentialsId': None }, 'runningVersionNumber': 1, 'currentStatus': 'STOPPED' } } }
- stop(app_id: str) Dict #
Stop a given app instance
Examples
>>> saagie_api.apps.stop(app_id="a6de6956-4038-493e-bbd3-f7b3616df39e") { 'stopApp': { 'id': 'a6de6956-4038-493e-bbd3-f7b3616df39e', 'history': { 'id': 'ba494615-88b7-4c54-ad57-34a90461c407', 'runningVersionNumber': 1, 'currentStatus': 'STARTED' } } }
- upgrade(app_id: str, release_note: str = '', exposed_ports: List[Dict] = None, storage_paths: List[Dict] = None, technology_context: str = None, image: str = None, docker_credentials_id: str = None) Dict #
Update the app
- Parameters:
app_id (str) – App ID
release_note (str, optional) – Release note for the app version
exposed_ports (List[dict], optional) –
List of dict of exposed ports If not filled, it takes exposed_ports of previous version Each dict should contains ‘port’ as key Ex: [{“basePathVariableName”:”SAAGIE_BASE_PATH”,
”isRewriteUrl”:True, “scope”:”PROJECT”, “number”:5000, “name”:”Test Port”}]
storage_paths (List[Dict], optional) –
List of dict indicating the volume path to the persistent storage and : - the id of the volume to be associated with the app.
- Ex: [{“path”: “/home”,
”volumeId”: “cb70ad1d-7883-48ac-8740-2c8e5c5166ee”}]
technology_context (str, optional) – Context version of the app Incompatible with parameters image & docker_credentials_id If not filled, it takes technology_context of previous version
image (str, optional) – tag of the Docker Image Incompatible with parameter technology_context If not filled, it takes image of previous version ex: hello-world:nanoserver-ltc2022
docker_credentials_id (str, optional) – Credentials’s ID for the image if the image is not public Incompatible with parameter technology_context
- Returns:
Dict of app version information
- Return type:
Examples
>>> saagie_client.apps.upgrade( ... app_id="97ec670f-8b11-479f-9cd2-c8904ef45b7f", ... exposed_ports=[ ... { ... "basePathVariableName": "SAAGIE_BASE_PATH", ... "isRewriteUrl": True, ... "scope": "PROJECT", ... "number": 80, ... "name": "Test Port" ... } ... ], ... storage_paths=[ ... { ... "path": "/home", ... "volumeId": "00f5d5d4-1975-478b-81f3-2003b7cff4c2" ... } ... ] ... ) { 'addAppVersion': { 'number': 2, 'releaseNote': '', 'dockerInfo': None, 'ports': [ { 'number': 80, 'name': 'Test Port', 'basePathVariableName': 'SAAGIE_BASE_PATH', 'isRewriteUrl': True, 'scope': 'PROJECT' } ], 'volumesWithPath': [ { 'path': '/home', 'volume': { 'id': '62f5d5d4-9546-478b-81f3-1970b7cff4c2', 'name': 'storage 64MB', 'size': '64 MB', 'creator': 'titi.tata' } } ] } }