Skip to content

Commit

Permalink
changelog, black, isort
Browse files Browse the repository at this point in the history
  • Loading branch information
kthare10 committed Aug 27, 2024
1 parent 75eaa40 commit 1065ebd
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 83 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Missing docstrings in network_service module (Issue [#313](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/314))
- Artifact Manager Support (Issue [#358](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/358))


## [1.7.3] - 08/05/2024
Expand Down
5 changes: 2 additions & 3 deletions fabrictestbed_extensions/fablib/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Artifact:
"versions": "Versions",
"created": "Created",
"modified": "Modified",
"tags": "Tags"
"tags": "Tags",
}

def __init__(self, artifact_info: dict, fablib_manager):
Expand Down Expand Up @@ -95,7 +95,7 @@ def to_dict(self) -> dict:
"title": self.artifact_info.get("title"),
"uuid": self.artifact_info.get("uuid"),
"description_short": self.artifact_info.get("description_short"),
#"description_long": self.artifact_info.get("description_long"),
# "description_long": self.artifact_info.get("description_long"),
"project_name": self.artifact_info.get("project_name"),
"authors": ", ".join(authors),
"versions": "\n".join(versions),
Expand All @@ -105,4 +105,3 @@ def to_dict(self) -> dict:
}

return d

90 changes: 58 additions & 32 deletions fabrictestbed_extensions/fablib/fablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2593,9 +2593,16 @@ def validate_node(self, node: Node, allocated: dict = None) -> Tuple[bool, str]:
logging.error(traceback.format_exc())
return False, str(e)

def create_artifact(self, artifact_title: str, description_short: str, description_long: str, authors: List[str],
tags: List[str], visibility: Visibility = Visibility.Author,
update_existing: bool = True) -> Artifact:
def create_artifact(
self,
artifact_title: str,
description_short: str,
description_long: str,
authors: List[str],
tags: List[str],
visibility: Visibility = Visibility.Author,
update_existing: bool = True,
) -> Artifact:
"""
Create a new artifact or update an existing one.
Expand All @@ -2609,11 +2616,15 @@ def create_artifact(self, artifact_title: str, description_short: str, descripti
:return: Dictionary containing the artifact details
:raises FabricManagerException: If there is an error in creating or updating the artifact.
"""
artifact_info = self.get_manager().create_artifact(artifact_title=artifact_title,
description_short=description_short,
description_long=description_long, authors=authors,
tags=tags, visibility=visibility,
update_existing=update_existing)
artifact_info = self.get_manager().create_artifact(
artifact_title=artifact_title,
description_short=description_short,
description_long=description_long,
authors=authors,
tags=tags,
visibility=visibility,
update_existing=update_existing,
)
return Artifact(artifact_info=artifact_info, fablib_manager=self)

def get_artifacts(
Expand All @@ -2637,8 +2648,7 @@ def get_artifacts(
start = time.time()

if artifact_id:
artifact = self.get_manager().get_artifact(artifact_title=artifact_title)
artifacts = [artifact]
artifacts = self.get_manager().list_artifacts(artifact_id=artifact_id)
elif artifact_title:
artifacts = self.get_manager().list_artifacts(search=artifact_title)
elif tag:
Expand All @@ -2654,18 +2664,16 @@ def get_artifacts(

return_artifacts = []
for a in artifacts:
return_artifacts.append(
Artifact(artifact_info=a, fablib_manager=self)
)
return_artifacts.append(Artifact(artifact_info=a, fablib_manager=self))
return return_artifacts

def list_artifacts(
self,
output=None,
fields=None,
quiet=False,
filter_function=None,
pretty_names=True,
self,
output=None,
fields=None,
quiet=False,
filter_function=None,
pretty_names=True,
) -> object:
"""
List artifacts based on a search query.
Expand All @@ -2690,7 +2698,7 @@ def list_artifacts(
output=output,
quiet=quiet,
filter_function=filter_function,
pretty_names_dict=Artifact.pretty_names if pretty_names else None
pretty_names_dict=Artifact.pretty_names if pretty_names else None,
)

return table
Expand All @@ -2708,7 +2716,9 @@ def delete_artifact(self, artifact_id: str = None, artifact_title: str = None):
:raises ValueError: If neither `artifact_id` nor `artifact_title` is provided.
:raises FabricManagerException: If an error occurs during the deletion process.
"""
self.get_manager().delete_artifact(artifact_id=artifact_id, artifact_title=artifact_title)
self.get_manager().delete_artifact(
artifact_id=artifact_id, artifact_title=artifact_title
)

def get_tags(self):
"""
Expand All @@ -2722,12 +2732,15 @@ def get_tags(self):
"""
return self.get_manager().get_tags()

def upload_file_to_artifact(self, file_to_upload: str, artifact_id: str = None, artifact_title: str = None) -> dict:
def upload_file_to_artifact(
self, file_to_upload: str, artifact_id: str = None, artifact_title: str = None
) -> dict:
"""
Upload a file to an existing artifact.
This method uploads a file to an artifact identified by either its `artifact_id` or `artifact_title`.
If `artifact_id` is not provided, the method will search for the artifact using `artifact_title` before uploading the file.
If `artifact_id` is not provided, the method will search for the artifact using `artifact_title`
before uploading the file.
:param file_to_upload: The path to the file that should be uploaded.
:param artifact_id: The unique identifier of the artifact to which the file will be uploaded.
Expand All @@ -2736,16 +2749,25 @@ def upload_file_to_artifact(self, file_to_upload: str, artifact_id: str = None,
:raises ValueError: If neither `artifact_id` nor `artifact_title` is provided.
:raises FabricManagerException: If an error occurs during the upload process.
"""
return self.get_manager().upload_file_to_artifact(file_to_upload=file_to_upload,
artifact_id=artifact_id,
artifact_title=artifact_title)
return self.get_manager().upload_file_to_artifact(
file_to_upload=file_to_upload,
artifact_id=artifact_id,
artifact_title=artifact_title,
)

def download_artifact(self, download_dir: str, artifact_id: str = None, artifact_title: str = None,
version: str = None, version_urn: str = None) -> str:
def download_artifact(
self,
download_dir: str,
artifact_id: str = None,
artifact_title: str = None,
version: str = None,
version_urn: str = None,
) -> str:
"""
Download an artifact to a specified directory.
This method downloads an artifact identified by either its `artifact_id` or `artifact_title` to the specified `download_dir`.
This method downloads an artifact identified by either its `artifact_id` or `artifact_title` to the
specified `download_dir`.
If `artifact_id` is not provided, the method will search for the artifact using `artifact_title`.
:param download_dir: The directory where the artifact will be downloaded.
Expand All @@ -2757,6 +2779,10 @@ def download_artifact(self, download_dir: str, artifact_id: str = None, artifact
:raises ValueError: If neither `artifact_id` nor `artifact_title` is provided.
:raises FabricManagerException: If an error occurs during the download process.
"""
return self.get_manager().download_artifact(download_dir=download_dir, artifact_id=artifact_id,
artifact_title=artifact_title, version=version,
version_urn=version_urn)
return self.get_manager().download_artifact(
download_dir=download_dir,
artifact_id=artifact_id,
artifact_title=artifact_title,
version=version,
version_urn=version_urn,
)
4 changes: 1 addition & 3 deletions fabrictestbed_extensions/fablib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3736,9 +3736,7 @@ def __ssh_key_helper(

# Fetch the public key from portal
if sliver_key_name is not None:
ssh_keys = (
self.get_fablib_manager().get_manager().get_ssh_keys(email=email)
)
ssh_keys = self.get_fablib_manager().get_manager().get_ssh_keys(email=email)
found = None
if ssh_keys is not None and len(ssh_keys):
for item in ssh_keys:
Expand Down
Loading

0 comments on commit 1065ebd

Please sign in to comment.