-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List default execution scripts #399
Draft
FedericoNegri
wants to merge
2
commits into
main
Choose a base branch
from
feat/list-exec-scripts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -68,6 +68,7 @@ def __init__(self, client: Client): | |||||
"""Initialize JMS API.""" | ||||||
self.client = client | ||||||
self._fs_url = None | ||||||
self._api_info = None | ||||||
|
||||||
@property | ||||||
def url(self) -> str: | ||||||
|
@@ -81,14 +82,26 @@ def fs_url(self) -> str: | |||||
self._fs_url = _find_available_fs_url(self.get_storage()) | ||||||
return self._fs_url | ||||||
|
||||||
def get_api_info(self): | ||||||
def get_api_info(self) -> dict: | ||||||
"""Get information of the JMS API that the client is connected to. | ||||||
|
||||||
Information includes the version and build date. | ||||||
""" | ||||||
r = self.client.session.get(self.url) | ||||||
return r.json() | ||||||
|
||||||
@property | ||||||
def api_info(self) -> dict: | ||||||
"""Information of the JMS API that the client is connected to.""" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if self._api_info is None: | ||||||
self._api_info = self.get_api_info() | ||||||
return self._api_info | ||||||
|
||||||
@property | ||||||
def execution_script_default_bucket(self) -> str: | ||||||
"""Default bucket for execution scripts.""" | ||||||
return self.api_info["settings"]["execution_script_default_bucket"] | ||||||
|
||||||
################################################################ | ||||||
# Projects | ||||||
def get_projects(self, as_objects=True, **query_params) -> List[Project]: | ||||||
|
@@ -245,6 +258,20 @@ def update_task_definition_template_permissions( | |||||
as_objects, | ||||||
) | ||||||
|
||||||
# Execution Scripts | ||||||
def list_default_execution_scripts(self) -> list[str]: | ||||||
"""List default execution scripts. | ||||||
|
||||||
Returns a list of available default execution scripts that can be passed | ||||||
as input to the :meth:`ProjectApi.copy_default_execution_script` method. | ||||||
""" | ||||||
r = self.client.session.get(f"{self.fs_url}/list/{self.execution_script_default_bucket}") | ||||||
file_list = [ | ||||||
f.replace(f"ansfs://{self.execution_script_default_bucket}/", "") | ||||||
for f in r.json()["file_list"] | ||||||
] | ||||||
return file_list | ||||||
|
||||||
################################################################ | ||||||
# Operations | ||||||
def get_operations(self, as_objects=True, **query_params) -> List[Operation]: | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -104,12 +104,20 @@ def __init__(self, client: Client, project_id: str): | |||||
self.project_id = project_id | ||||||
self._fs_url = None | ||||||
self._fs_project_id = None | ||||||
self._jms_api = None | ||||||
|
||||||
@property | ||||||
def jms_api_url(self) -> str: | ||||||
"""Get the JMS API URL.""" | ||||||
return f"{self.client.url}/jms/api/v1" | ||||||
|
||||||
@property | ||||||
def jms_api(self) -> JmsApi: | ||||||
"""Get the JMS API object.""" | ||||||
if self._jms_api is None: | ||||||
self._jms_api = JmsApi(self.client) | ||||||
return self._jms_api | ||||||
|
||||||
@property | ||||||
def url(self) -> str: | ||||||
"""URL of the API.""" | ||||||
|
@@ -119,7 +127,7 @@ def url(self) -> str: | |||||
def fs_url(self) -> str: | ||||||
"""URL of the file storage gateway.""" | ||||||
if self._fs_url is None: | ||||||
self._fs_url = JmsApi(self.client).fs_url | ||||||
self._fs_url = self.jms_api.fs_url | ||||||
return self._fs_url | ||||||
|
||||||
@property | ||||||
|
@@ -593,16 +601,18 @@ def delete_license_contexts(self): | |||||
"""Delete license contexts.""" | ||||||
rest_name = LicenseContext.Meta.rest_name | ||||||
url = f"{self.jms_api_url}/projects/{self.id}/{rest_name}" | ||||||
r = self.client.session.delete(url) | ||||||
_ = self.client.session.delete(url) | ||||||
|
||||||
################################################################ | ||||||
def copy_default_execution_script(self, filename: str) -> File: | ||||||
"""Copy a default execution script to the current project. | ||||||
|
||||||
Example: | ||||||
|
||||||
>>> file = project_api.copy_default_execution_script("exec_mapdl.py") | ||||||
>>> file = project_api.copy_default_execution_script("mapdl-v241-exec_mapdl.py") | ||||||
|
||||||
You can use the method :meth:`JmsApi.list_default_execution_scripts` to query | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Noun indicating the type of object should follow the tagged code entity. |
||||||
the list of available default execution scripts. | ||||||
""" | ||||||
|
||||||
# create file resource | ||||||
|
@@ -611,9 +621,7 @@ def copy_default_execution_script(self, filename: str) -> File: | |||||
file = self.create_files([file])[0] | ||||||
|
||||||
# query location of default execution scripts from server | ||||||
jms_api = JmsApi(self.client) | ||||||
info = jms_api.get_api_info() | ||||||
execution_script_default_bucket = info["settings"]["execution_script_default_bucket"] | ||||||
execution_script_default_bucket = self.jms_api.execution_script_default_bucket | ||||||
|
||||||
# server side copy of the file to project bucket | ||||||
checksum = _fs_copy_file( | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"of the JMS API" didn't read well. Hope "on the JMS API" is OK.