Files
test/keywords/ptp/setup/object/ptp_host_interface_setup.py
Guntaka Umashankar Reddy ade9a3df1c Removed hardcoded hosts and pci-slot
Implementation of ptp_parameters_parser.py

Change-Id: I12d6606870f0e85705f3264d054a79bf66e59523
Signed-off-by: Guntaka Umashankar Reddy <umashankarguntaka.reddy@windriver.com>
2025-05-08 15:59:10 +00:00

81 lines
2.7 KiB
Python

from typing import Any, Dict, List
class PTPHostInterfaceSetup:
"""
This class models a PTP Host interface setup.
"""
def __init__(self, setup_dict: Dict[str, Any]):
"""
Constructor.
Args:
setup_dict (Dict[str, Any]): The dictionary read from the JSON setup template file associated with this ptp host interface setup.
"""
if "name" not in setup_dict:
raise Exception("Every ptp host interface entry should have a name.")
self.name = setup_dict["name"]
if "ptp_interface_parameter" not in setup_dict:
raise Exception(f"The ptp host interface entry {self.name} must have ptp_interface_parameter defined.")
self.ptp_interface_parameter = setup_dict["ptp_interface_parameter"]
if "controller_0_interfaces" not in setup_dict:
raise Exception(f"The ptp host interface entry {self.name} must have controller_0_interfaces defined.")
self.controller_0_interfaces = setup_dict["controller_0_interfaces"]
if "controller_1_interfaces" not in setup_dict:
raise Exception(f"The ptp host interface entry {self.name} must have controller_1_interfaces defined.")
self.controller_1_interfaces = setup_dict["controller_1_interfaces"]
self.compute_0_interfaces = None
if "compute_0_interfaces" in setup_dict:
self.compute_0_interfaces = setup_dict.get("compute_0_interfaces")
def __str__(self):
"""
String representation of this object.
Returns:
str: String representation of this object.
"""
return self.get_name()
def get_name(self) -> str:
"""
Gets the name of this ptp host interface setup.
Returns:
str: The name of this ptp host interface setup.
"""
return self.name
def get_ptp_interface_parameter(self) -> str:
"""
Gets the ptp_interface_parameter of this ptp host interface setup.
Returns:
str: The ptp_interface_parameter of this ptp host interface setup.
"""
return self.ptp_interface_parameter
def get_interfaces_for_hostname(self, hostname: str) -> List[str]:
"""
Gets the interfaces for the given hostname in this PTP host interface setup.
Args:
hostname (str): The name of the host.
Returns:
List[str]: The interfaces for the given hostname in this PTP host interface setup.
"""
interfaces_to_hostname_mapping = {
"controller-0": self.controller_0_interfaces,
"controller-1": self.controller_1_interfaces,
"compute-0": self.compute_0_interfaces,
}
return interfaces_to_hostname_mapping.get(hostname)