Skip to content

Commit

Permalink
Merge pull request #353 from fabric-testbed/list-resources-update
Browse files Browse the repository at this point in the history
List resources update
  • Loading branch information
kthare10 authored Jul 22, 2024
2 parents 06e7247 + c824fb0 commit fbc3468
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 12 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# Unreleased
# [1.7.1] - 07/19/2024

### Fixed
- Use cached resource information unless fresh information explicitly requested (Issue [#352](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/352))

# [1.7.0] - 07/18/2024

### Fixed
- Error *may* be inaccurate or wrong when I issue an invalid configuration. (Issue [#304](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/304))
Expand Down
2 changes: 2 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ FABLib functionality is made available in these modules:
node
component
interface
switch.rst
network_service
facility_port.rst
resources.rst
site.rst


Indices and tables
Expand Down
17 changes: 17 additions & 0 deletions docs/source/site.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
site
====

.. automodule:: fabrictestbed_extensions.fablib.site
:members:

.. autoclass:: fabrictestbed_extensions.fablib.site.Site
:members:
:special-members: __str__

.. autoclass:: fabrictestbed_extensions.fablib.site.Switch
:members:
:special-members: __str__

.. autoclass:: fabrictestbed_extensions.fablib.site.Host
:members:
:special-members: __str__
10 changes: 10 additions & 0 deletions docs/source/switch.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
switch
======

.. automodule:: fabrictestbed_extensions.fablib.switch
:members:

.. autoclass:: fabrictestbed_extensions.fablib.switch.Switch
:members:
:no-index:
:special-members: __str__
51 changes: 45 additions & 6 deletions fabrictestbed_extensions/fablib/fablib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ def list_sites(
fields: str = None,
quiet: bool = False,
filter_function=None,
update: bool = True,
update: bool = False,
pretty_names: bool = True,
force_refresh: bool = False,
latlon: bool = True,
Expand Down Expand Up @@ -1289,8 +1289,10 @@ def list_facility_ports(
fields: str = None,
quiet: bool = False,
filter_function=None,
update: bool = True,
update: bool = False,
pretty_names=True,
start: datetime = None,
end: datetime = None,
) -> object:
"""
Lists all the facility ports and their attributes.
Expand All @@ -1312,20 +1314,34 @@ def list_facility_ports(
:param output: output format
:type output: str
:param fields: list of fields (table columns) to show
:type fields: List[str]
:param quiet: True to specify printing/display
:type quiet: bool
:param filter_function: lambda function
:type filter_function: lambda
:param update:
:type update: bool
:param pretty_names:
:type pretty_names: bool
:param start: start time in UTC format: %Y-%m-%d %H:%M:%S %z
:type: datetime
:param end: end time in UTC format: %Y-%m-%d %H:%M:%S %z
:type: datetime
:return: table in format specified by output parameter
:rtype: Object
"""
return self.get_facility_ports(update=update).list_facility_ports(
return self.get_facility_ports(
update=update, start=start, end=end
).list_facility_ports(
output=output,
fields=fields,
quiet=quiet,
Expand Down Expand Up @@ -1447,26 +1463,46 @@ def get_links(self, update: bool = True) -> Links:

return self.links

def get_facility_ports(self, update: bool = True) -> FacilityPorts:
def get_facility_ports(
self,
update: bool = False,
start: datetime = None,
end: datetime = None,
) -> FacilityPorts:
"""
Get the facility ports.
Optionally update the available resources by querying the FABRIC
services. Otherwise, this method returns the existing information.
:param update:
:param start: start time in UTC format: %Y-%m-%d %H:%M:%S %z
:type: datetime
:param end: end time in UTC format: %Y-%m-%d %H:%M:%S %z
:type: datetime
:return: Links
"""
if not update:
if start or end:
update = True
self.last_resources_filtered_by_time = True
elif self.last_resources_filtered_by_time:
update = True
self.last_resources_filtered_by_time = False

if self.facility_ports is None:
self.facility_ports = FacilityPorts(self)
elif update:
self.facility_ports.update()
self.facility_ports.update(start=start, end=end)

return self.facility_ports

def get_resources(
self,
update: bool = True,
update: bool = False,
force_refresh: bool = False,
start: datetime = None,
end: datetime = None,
Expand Down Expand Up @@ -1751,6 +1787,9 @@ def get_available_resources(
:return: Available Resources object
"""
if start and end and (end - start) < datetime.timedelta(minutes=60):
raise Exception("Time range should be at least 60 minutes long!")

from fabrictestbed_extensions.fablib.resources import Resources

if self.resources is None:
Expand Down
20 changes: 16 additions & 4 deletions fabrictestbed_extensions/fablib/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2185,6 +2185,7 @@ def submit(
:return: slice_id
"""
slice_reservations = None

if not wait:
progress = False
Expand All @@ -2200,19 +2201,21 @@ def submit(
lease_start_time_str = lease_start_time.strftime("%Y-%m-%d %H:%M:%S %z")

lease_end_time = None
lease_end_time_str = None
if lease_in_days:
start_time = (
lease_start_time if lease_end_time else datetime.now(timezone.utc)
)
lease_end_time = (start_time + timedelta(days=lease_in_days)).strftime(
lease_end_time = start_time + timedelta(days=lease_in_days)
lease_end_time_str = (start_time + timedelta(days=lease_in_days)).strftime(
"%Y-%m-%d %H:%M:%S %z"
)

# Request slice from Orchestrator
if self._is_modify():
if lease_in_days:
return_status, result = self.fablib_manager.get_slice_manager().renew(
slice_object=self.sm_slice, new_lease_end_time=lease_end_time
slice_object=self.sm_slice, new_lease_end_time=lease_end_time_str
)
else:
(
Expand Down Expand Up @@ -2240,14 +2243,23 @@ def submit(
# this will throw an informative exception
FABRICSSHKey.get_key_length(ssh_key)

if (
lease_start_time
and lease_end_time
and (lease_end_time - lease_start_time) < timedelta(minutes=60)
):
raise Exception(
"Requested Lease Time range should be at least 60 minutes long!"
)

(
return_status,
slice_reservations,
) = self.fablib_manager.get_slice_manager().create(
slice_name=self.slice_name,
slice_graph=slice_graph,
ssh_key=ssh_keys,
lease_end_time=lease_end_time,
lease_end_time=lease_end_time_str,
lease_start_time=lease_start_time_str,
)
if return_status == Status.OK:
Expand Down Expand Up @@ -2297,7 +2309,7 @@ def submit(
else:
print("Running post boot config ... ", end="")

if advance_allocation and post_boot_config:
if not advance_allocation and post_boot_config:
self.post_boot_config()
else:
self.update()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"

[project]
name = "fabrictestbed-extensions"
version = "1.7.0"
version = "1.7.2"
description = "FABRIC Python Client Library and CLI Extensions"
authors = [
{ name = "Paul Ruth", email = "[email protected]" },
Expand Down

0 comments on commit fbc3468

Please sign in to comment.