diff --git a/CHANGELOG.md b/CHANGELOG.md index 69257c50..c91f1e4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,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)) - +- FabNet user specified subnets (Issue [#361](https://github.com/fabric-testbed/fabrictestbed-extensions/issues/361)) ## [1.7.3] - 08/05/2024 ### Fixed diff --git a/fabrictestbed_extensions/fablib/interface.py b/fabrictestbed_extensions/fablib/interface.py index fe37cf84..669a74e9 100644 --- a/fabrictestbed_extensions/fablib/interface.py +++ b/fabrictestbed_extensions/fablib/interface.py @@ -755,12 +755,15 @@ def get_model(self) -> str: :return: the model of this interface's component :rtype: str """ - if self.model: - return self.model - elif self.node: - return self.node.get_model() - else: - return self.get_component().get_model() + try: + if self.model: + return self.model + elif self.node: + return self.node.get_model() + else: + return self.get_component().get_model() + except Exception: + return "" def get_site(self) -> str: """ diff --git a/fabrictestbed_extensions/fablib/network_service.py b/fabrictestbed_extensions/fablib/network_service.py index 3361b271..9d0f4947 100644 --- a/fabrictestbed_extensions/fablib/network_service.py +++ b/fabrictestbed_extensions/fablib/network_service.py @@ -36,7 +36,7 @@ from typing import TYPE_CHECKING, List, Union from fim.slivers.path_info import Path -from fim.user import ERO +from fim.user import ERO, Gateway from tabulate import tabulate if TYPE_CHECKING: @@ -368,6 +368,7 @@ def new_l3network( type: str = None, user_data={}, technology: str = None, + subnet: ipaddress.ip_network = None, ): """ Not inteded for API use. See slice.add_l3network @@ -398,6 +399,7 @@ def new_l3network( interfaces=interfaces, user_data=user_data, technology=technology, + subnet=subnet, ) @staticmethod @@ -478,6 +480,7 @@ def __new_network_service( interfaces: List[Interface] = [], user_data: dict = {}, technology: str = None, + subnet: ipaddress.ip_network = None, ): """ Not intended for API use. See slice.add_l2network @@ -487,14 +490,23 @@ def __new_network_service( :param slice: the fabric slice to build the network service with :type slice: Slice + :param name: the name of the new network service :type name: str + :param nstype: the type of network service to create :type nstype: ServiceType + :param interfaces: a list of interfaces to :type interfaces: List + :param technology: Specify the technology used should be set to AL2S when using for AL2S peering; otherwise None :type technology: str + + :param subnet: Request a specific subnet for FabNetv4, FabNetv6 or FabNetv6Ext services. + It's ignored for any other services. + :type ipaddress.ip_network + :return: the new fablib network service :rtype: NetworkService """ @@ -509,6 +521,22 @@ def __new_network_service( name=name, nstype=nstype, interfaces=fim_interfaces, technology=technology ) + if subnet: + if nstype == ServiceType.FABNetv4: + fim_network_service.gateway = Gateway( + lab=Labels( + ipv4_subnet=subnet.with_prefixlen, + ipv4=str(next(subnet.hosts())), + ) + ) + elif nstype in [ServiceType.FABNetv6, ServiceType.FABNetv6Ext]: + fim_network_service.gateway = Gateway( + lab=Labels( + ipv6_subnet=subnet.with_prefixlen, + ipv6=str(next(subnet.hosts())), + ) + ) + network_service = NetworkService( slice=slice, fim_network_service=fim_network_service ) @@ -1088,11 +1116,13 @@ def get_interfaces(self) -> List[Interface]: ) except: logging.warning(f"interface not found: {interface.name}") + """ Commenting this code as not sure why this was added for now. from fabrictestbed_extensions.fablib.interface import Interface self.interfaces.append( Interface(fim_interface=interface, node=self) ) + """ return self.interfaces diff --git a/fabrictestbed_extensions/fablib/slice.py b/fabrictestbed_extensions/fablib/slice.py index dbf8c169..38229b36 100644 --- a/fabrictestbed_extensions/fablib/slice.py +++ b/fabrictestbed_extensions/fablib/slice.py @@ -59,7 +59,7 @@ from typing import TYPE_CHECKING, Tuple import pandas as pd -from fim.user import Capacities, Labels, NodeType +from fim.user import Labels from fss_utils.sshkey import FABRICSSHKey from IPython.core.display_functions import display @@ -1022,6 +1022,7 @@ def add_l3network( type: str = "IPv4", user_data: dict = {}, technology: str = None, + subnet: ipaddress.ip_network = None, ) -> NetworkService: """ Adds a new L3 network service to this slice. @@ -1069,11 +1070,15 @@ def add_l3network( :type type: String :param user_data - :type user_data: dict + :param technology: Specify the technology used should be set to AL2S when using for AL2S peering; otherwise None :type technology: str + :param subnet: Request a specific subnet for FabNetv4, FabNetv6 or FabNetv6Ext services. + It's ignored for any other services. + :type ipaddress.ip_network + :return: a new L3 network service :rtype: NetworkService """ @@ -1087,6 +1092,7 @@ def add_l3network( type=type, user_data=user_data, technology=technology, + subnet=subnet, ) def add_facility_port(