Skip to content

Commit

Permalink
Merge pull request #391 from fabric-testbed/rel1.8
Browse files Browse the repository at this point in the history
Rel1.8 - changes
  • Loading branch information
kthare10 authored Jan 10, 2025
2 parents b752af4 + d273721 commit f9e4c9f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 38 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ 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.8.0 - 01/07/2025

### Added
- Advance Scheduling Improvements (Issue [#388](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/388))
- Support for P4 switches (Issue [#392](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/392))

### Fixed
- Ensure slice key and bastion key names are not identical (Issue [#389](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/389))
Expand Down
2 changes: 2 additions & 0 deletions fabrictestbed_extensions/fablib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,5 @@ class Constants:
CMP_FPGA_Xilinx_U280 = "FPGA_Xilinx_U280"
CMP_FPGA_Xilinx_SN1022 = "FPGA_Xilinx_SN1022"
P4_DedicatedPort = "P4_DedicatedPort"

FABRIC_USER = "fabric"
8 changes: 7 additions & 1 deletion fabrictestbed_extensions/fablib/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
from IPython.core.display_functions import display
from tabulate import tabulate

from fabrictestbed_extensions.fablib.constants import Constants
from fabrictestbed_extensions.fablib.network_service import NetworkService

if TYPE_CHECKING:
Expand Down Expand Up @@ -752,8 +753,13 @@ def set_username(self, username: str = None):
:param username: Optional username parameter. The username
likely should be picked to match the image type.
"""
if self.get_fim_node().type == NodeType.Switch and not username:
self.username = Constants.FABRIC_USER
return
if username is not None:
self.username = username
elif "default_centos10_stream" == self.get_image():
self.username = "cloud-user"
elif "default_centos9_stream" == self.get_image():
self.username = "cloud-user"
elif "centos" in self.get_image():
Expand Down Expand Up @@ -2352,7 +2358,7 @@ def ip_addr_list(self, output="json", update=False):
result of ``ip addr list``.
"""
try:
if self.ip_addr_list_json is not None and update == False:
if self.ip_addr_list_json is not None and not update:
return self.ip_addr_list_json
else:
if output == "json":
Expand Down
64 changes: 31 additions & 33 deletions fabrictestbed_extensions/fablib/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from typing import TYPE_CHECKING, Tuple

import pandas as pd
from fim.user import Labels
from fim.user import Labels, NodeType
from fss_utils.sshkey import FABRICSSHKey
from IPython.core.display_functions import display

Expand Down Expand Up @@ -1806,7 +1806,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 @@ -2345,7 +2345,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 @@ -2382,12 +2383,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 @@ -2405,26 +2411,26 @@ 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 @@ -2452,24 +2458,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
3 changes: 2 additions & 1 deletion fabrictestbed_extensions/fablib/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from IPython.core.display_functions import display
from tabulate import tabulate

from fabrictestbed_extensions.fablib.constants import Constants
from fabrictestbed_extensions.fablib.interface import Interface
from fabrictestbed_extensions.fablib.node import Node

Expand Down Expand Up @@ -69,7 +70,7 @@ def __init__(
super(Switch, self).__init__(
slice=slice, node=node, validate=validate, raise_exception=raise_exception
)
self.username = "rare"
self.username = Constants.FABRIC_USER

def __str__(self):
"""
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.0"
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.9",
"fabrictestbed==1.8.0",
"paramiko",
"jinja2>=3.0.0",
"pandas",
Expand Down

0 comments on commit f9e4c9f

Please sign in to comment.