
Description: - Added data types to function arguments and return values. - Added blank lines between summary and description in docstrings to match style guidelines. - Removed extra blank lines after docstrings. - Added a missing import for SSHConnection in sma_keywords.py. - Capitalized the first word in each docstring to comply with style guide rules. - Improved docstring for PTP4LStatusObject constructor with detailed attribute descriptions Change-Id: Idada0b0b0c3f895a16f4b439beaaaf071597a16a Change-Id: I8e7756d32eb56a2aa85b277a91b26cc6280d1c56 Signed-off-by: aabhinav <ayyapasetti.abhinav@windriver.com>
107 lines
4.0 KiB
Python
107 lines
4.0 KiB
Python
from typing import Any, Dict, List
|
|
|
|
from keywords.ptp.setup.object.ptp_host_interface_setup import PTPHostInterfaceSetup
|
|
|
|
|
|
class ClockSetup:
|
|
"""
|
|
Class models a clock setup
|
|
"""
|
|
|
|
def __init__(self, setup_dict: Dict[str, Any], ptp_host_ifs_dict: Dict[str, PTPHostInterfaceSetup]):
|
|
"""
|
|
Constructor.
|
|
|
|
Args:
|
|
setup_dict (Dict[str, Any]): The dictionary read from the JSON setup template file associated with this clock setup.
|
|
ptp_host_ifs_dict (Dict[str, PTPHostInterfaceSetup]): The dictionary that maps the name of thePTPHostInterfaceSetup to its associated object.
|
|
|
|
Raises:
|
|
Exception: If the setup_dict does not contain required keys or if the ptp_host_ifs_dict does not contain required PTPHostInterfaceSetup entries.
|
|
Exception: If the setup_dict does not contain required instance hostnames.
|
|
Exception: If the setup_dict does not contain required instance parameters.
|
|
Exception: If the setup_dict does not contain required ptp_interface_names.
|
|
Exception: If the setup_dict does not contain required ptp_host_if entries.
|
|
"""
|
|
if "name" not in setup_dict:
|
|
raise Exception("Every clock entry should have a name.")
|
|
self.name = setup_dict["name"]
|
|
|
|
if "instance_hostnames" not in setup_dict:
|
|
raise Exception(f"The clock entry {self.name} must have instance_hostnames defined.")
|
|
self.instance_hostnames = setup_dict["instance_hostnames"]
|
|
|
|
if "instance_parameters" not in setup_dict:
|
|
raise Exception(f"The clock entry {self.name} must have instance_parameters defined.")
|
|
self.instance_parameters = setup_dict["instance_parameters"]
|
|
|
|
if "ptp_interface_names" not in setup_dict:
|
|
raise Exception(f"The clock entry {self.name} must have ptp_interface_names defined.")
|
|
|
|
ptp_interfaces = []
|
|
for ptp_interface_name in setup_dict["ptp_interface_names"]:
|
|
if ptp_interface_name not in ptp_host_ifs_dict:
|
|
raise Exception(f"The ptp_host_if entry {ptp_interface_name} must be defined.")
|
|
ptp_interfaces.append(ptp_host_ifs_dict[ptp_interface_name])
|
|
self.ptp_interfaces = ptp_interfaces
|
|
|
|
def __str__(self) -> str:
|
|
"""
|
|
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 clock setup.
|
|
|
|
Returns:
|
|
str: The name of this clock setup.
|
|
"""
|
|
return self.name
|
|
|
|
def get_instance_hostnames(self) -> list[str]:
|
|
"""
|
|
Gets the list of instance hostnames.
|
|
|
|
Returns:
|
|
list[str]: The list of instance hostnames.
|
|
"""
|
|
return self.instance_hostnames
|
|
|
|
def get_instance_parameters(self) -> str:
|
|
"""
|
|
Gets the instance parameters as a string.
|
|
|
|
Returns:
|
|
str: The instance parameters as a string
|
|
"""
|
|
return self.instance_parameters
|
|
|
|
def get_ptp_interfaces(self) -> List[PTPHostInterfaceSetup]:
|
|
"""
|
|
Gets the list of PTP interfaces.
|
|
|
|
Returns:
|
|
List[PTPHostInterfaceSetup]: The list of PTP interfaces.
|
|
"""
|
|
return self.ptp_interfaces
|
|
|
|
def get_ptp_interface(self, ptp_host_if_name: str) -> PTPHostInterfaceSetup:
|
|
"""
|
|
Gets the PTP interface associated with the name ptp_host_if_name.
|
|
|
|
Args:
|
|
ptp_host_if_name (str): Name of the ptp_host_if associated with this clock setup with the provided name.
|
|
|
|
Returns:
|
|
PTPHostInterfaceSetup: PTPHostInterfaceSetup with the name passed in.
|
|
"""
|
|
for ptp_interface in self.ptp_interfaces:
|
|
if ptp_interface.get_name() == ptp_host_if_name:
|
|
return ptp_interface
|
|
raise Exception(f"There is no ptp host interface with the name {ptp_host_if_name} associated with the clock setup {self.get_name()}")
|