Skip to content

Commit

Permalink
update create api to pass start, end and lifetime for future slices
Browse files Browse the repository at this point in the history
  • Loading branch information
kthare10 committed Oct 30, 2024
1 parent e73f641 commit 5a48935
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 34 deletions.
54 changes: 22 additions & 32 deletions fabrictestbed_extensions/fablib/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ def renew(self, end_date: str = None, days: int = None, **kwargs):
days = (end - datetime.now(timezone.utc)).days

# Directly pass the kwargs to submit
self.submit(lease_in_days=days, post_boot_config=False, **kwargs)
self.submit(lease_in_hours=(days * 24), post_boot_config=False, **kwargs)

def build_error_exception_string(self) -> str:
"""
Expand Down Expand Up @@ -2235,7 +2235,8 @@ def submit(
wait_ssh: bool = True,
extra_ssh_keys: List[str] = None,
lease_start_time: datetime = None,
lease_in_days: int = None,
lease_end_time: datetime = None,
lease_in_hours: int = None,
validate: bool = False,
) -> str:
"""
Expand Down Expand Up @@ -2272,12 +2273,17 @@ def submit(
:param extra_ssh_keys: Optional list of additional SSH public keys to be installed in the slivers of this slice
:type extra_ssh_keys: List[str]
:param lease_start_time: Optional lease start in UTC time format: %Y-%m-%d %H:%M:%S %z
:param lease_start_time: Optional lease start time in UTC format: %Y-%m-%d %H:%M:%S %z.
Specifies the beginning of the time range to search for available resources valid for `lease_in_hours`.
:type lease_start_time: datetime
:param lease_in_days: Optional lease duration in days, by default the slice is active for 24 hours i.e 1 day,
only used for create.
:type lease_in_days: int
:param lease_end_time: Optional lease end time in UTC format: %Y-%m-%d %H:%M:%S %z.
Specifies the end of the time range to search for available resources valid for `lease_in_hours`.
:type lease_end_time: datetime
:param lease_in_hours: Optional lease duration in hours. By default, the slice remains active for 24 hours (1 day).
This parameter is only applicable during creation.
:type lease_in_hours: int
:param validate: Validate node can be allocated w.r.t available resources
:type validate: bool
Expand All @@ -2295,26 +2301,18 @@ def submit(
# Generate Slice Graph
slice_graph = self.get_fim_topology().serialize()

lease_start_time_str = None
if lease_start_time:
lease_start_time_str = lease_start_time.strftime("%Y-%m-%d %H:%M:%S %z")
start_time_str = lease_start_time.strftime("%Y-%m-%d %H:%M:%S %z") if lease_start_time else None
end_time_str = lease_end_time.strftime("%Y-%m-%d %H:%M:%S %z") if lease_end_time else None

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)
lease_end_time_str = (start_time + timedelta(days=lease_in_days)).strftime(
"%Y-%m-%d %H:%M:%S %z"
)
# Create slice now or Renew slice
if lease_in_hours and not lease_start_time and not lease_end_time:
end_time_str = (datetime.now(timezone.utc) + timedelta(hours=lease_in_hours)).strftime("%Y-%m-%d %H:%M:%S %z")

# Request slice from Orchestrator
if self._is_modify():
if lease_in_days:
if lease_in_hours:
return_status, result = self.fablib_manager.get_manager().renew(
slice_object=self.sm_slice, new_lease_end_time=lease_end_time_str
slice_object=self.sm_slice, new_lease_end_time=end_time_str
)
else:
(
Expand Down Expand Up @@ -2342,24 +2340,16 @@ 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_manager().create(
slice_name=self.slice_name,
slice_graph=slice_graph,
ssh_key=ssh_keys,
lease_end_time=lease_end_time_str,
lease_start_time=lease_start_time_str,
lease_end_time=end_time_str,
lease_start_time=start_time_str,
lifetime=lease_in_hours
)
if return_status == Status.OK:
logging.info(
Expand Down
4 changes: 2 additions & 2 deletions 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.4"
version = "1.8.0b1"
description = "FABRIC Python Client Library and CLI Extensions"
authors = [
{ name = "Paul Ruth", email = "[email protected]" },
Expand All @@ -20,7 +20,7 @@ dependencies = [
"ipyleaflet",
"ipycytoscape",
"tabulate",
"fabrictestbed==1.7.8",
"fabrictestbed==1.8.0b1",
"paramiko",
"jinja2>=3.0.0",
"pandas",
Expand Down

0 comments on commit 5a48935

Please sign in to comment.