Skip to content

Kathara.model.Lab

Tommaso Caiazzi edited this page Mar 18, 2024 · 13 revisions

module Kathara.model.Lab

Global Variables

  • LAB_METADATA

class Lab

A Kathara network scenario, containing information about devices and collision domains.

Attributes:

  • name (str): The name of the network scenario.
  • description (str): A short description of the network scenario.
  • version (str): The version of the network scenario.
  • author (str): The author of the network scenario.
  • email (str): The email of the author of the network scenario.
  • web (str): The web address of the author of the network scenario.
  • hash (str): The hash identifier of the network scenario.
  • machines (Dict[str, Kathara.model.Machine]): The devices of the network scenario. Keys are device names, Values are Kathara device objects.
  • links (Dict[str, Kathara.model.Link]): The collision domains of the network scenario. Keys are collision domains names, Values are Kathara collision domain objects.
  • general_options (Dict[str, Any]): The general options of the network scenario.
  • global_machine_metadata (Dict[str, Any]): Metadata to apply to all the devices of the network scenario at the startup.
  • has_dependencies (bool): True if there are dependencies among the devices boot.
  • shared_path (str): Path to shared folder of the network scenario, if the network scenario has a real OS path.
  • fs (fs.FS): The filesystem of the network scenario. Contains files and configurations associated to it.

method Lab.__init__

__init__(name: Optional[str], path: Optional[str] = None) → None

Create a new instance of a Kathara network scenario.

Args:

  • name (str): The name of the network scenario.
  • path (str): The path to the network scenario directory, if exists.

Returns: None


property Lab.name


method Lab.add_global_machine_metadata

add_global_machine_metadata(name: str, value: Any) → None

Add a global machine metadata to the network scenario.

Args:

  • name (str): The name of the meta.
  • value (Any): The value of the meta.

Returns: None


method Lab.add_option

add_option(name: str, value: Any) → None

Add an option to the network scenario.

Args:

  • name (str): The name of the option.
  • value (Any): The value of the option.

Returns: None


method Lab.apply_dependencies

apply_dependencies(dependencies: List[str]) → None

Order the list of devices of the network scenario to satisfy the boot dependencies.

Args:

  • dependencies (List[str]): If not empty, dependencies are applied.

Returns: None


method Lab.assign_meta_to_machine

assign_meta_to_machine(
    machine_name: str,
    meta_name: str,
    meta_value: str
) → Optional[Any]

Assign meta information to the specified device.

Args:

  • machine_name (str): The name of the device.
  • meta_name (str): The name of the meta property.
  • meta_value (str): The value of the meta property.

Returns:

  • Optional[Any]: Previous value if meta was already assigned, None otherwise.

Raises:

  • MachineOptionError: If invalid values are specified for meta properties.

method Lab.attach_external_links

attach_external_links(
    external_links: Dict[str, List[Kathara.model.ExternalLink.ExternalLink]]
) → None

Attach external collision domains to the network scenario.

Args:

  • external_links (Dict[Kathara.model.Link, List[Kathara.model.ExternalLink]]): Keys are Link objects, values are ExternalLink objects.

Returns: None

Raises:

  • LinkNotFoundError: If the external collision domain specified is not associated to the network scenario.

method Lab.check_integrity

check_integrity() → None

Check if the network interfaces numbers of all the devices in the network scenario are correctly assigned.

Returns: None

Raises:

  • NonSequentialMachineInterfaceError: If there is a missing interface number in any device of the lab.

method Lab.connect_machine_obj_to_link

connect_machine_obj_to_link(
    machine: 'MachinePackage.Machine',
    link_name: str,
    machine_iface_number: int = None,
    mac_address: Optional[str] = None
) → InterfacePackage.Interface

Connect the specified device object to the specified collision domain.

Args:

  • machine (Kathara.model.Machine): The device object.
  • link_name (str): The collision domain name.
  • machine_iface_number (int): The number of the device interface to connect. If it is None, the first free number is used.
  • mac_address (Optional[str]): The MAC address to assign to the interface.

Returns:

  • Kathara.model.Interface.Interface: The interface object associated to the new interface..

Raises:

  • Exception: If an already used interface number is specified.

method Lab.connect_machine_to_link

connect_machine_to_link(
    machine_name: str,
    link_name: str,
    machine_iface_number: int = None,
    mac_address: Optional[str] = None
) → Tuple[ForwardRef('MachinePackage.Machine'), ForwardRef('InterfacePackage.Interface')]

Connect the specified device to the specified collision domain.

Args:

  • machine_name (str): The device name.
  • link_name (str): The collision domain name.
  • machine_iface_number (int): The number of the device interface to connect. If it is None, the first free number is used.
  • mac_address (Optional[str]): The MAC address to assign to the interface.

Returns:

  • Tuple[Kathara.model.Machine.Machine, Kathara.model.Interface.Interface]: A tuple containing the Kathara device and the interface object specified by their names.

Raises:

  • Exception: If an already used interface number is specified.

method Lab.create_shared_folder

create_shared_folder() → None

If the network scenario has a directory, create the network scenario shared folder.

Returns: None

Raises:

  • IOError: If the shared folder is a Symlink, delete it.
  • OSError: If there is a permission error.

method Lab.get_link

get_link(name: str) → LinkPackage.Link

Get the specified collision domain.

Args:

  • name (str): The name of the collision domain.

Returns:

  • Kathara.model.Link: A Kathara collision domain.

Raises:

  • LinkNotFoundError: If the specified link is not in the network scenario.

method Lab.get_links_from_machine_objs

get_links_from_machine_objs(
    machines: Union[List[ForwardRef('MachinePackage.Machine')], Set[ForwardRef('MachinePackage.Machine')]]
) → Set[str]

Return the name of the collision domains connected to the devices.

Args:

  • machines (Union[List[str], Set[str]]): A set or a list with selected devices names.

Returns:

  • Set[str]: A set of names of collision domains.

method Lab.get_links_from_machines

get_links_from_machines(machines: Union[List[str], Set[str]]) → Set[str]

Return the name of the collision domains connected to the devices.

Args:

  • machines (Union[List[str], Set[str]]): A set or a list with selected devices names.

Returns:

  • Set[str]: A set of names of collision domains.

method Lab.get_machine

get_machine(name: str) → MachinePackage.Machine

Get the specified device.

Args:

  • name (str): The name of the device

Returns:

  • Kathara.model.Machine: A Kathara device.

Raises:

  • MachineNotFoundError: If the device is not in the network scenario.

method Lab.get_or_new_link

get_or_new_link(name: str) → LinkPackage.Link

Get the specified collision domain. If it not exists, create and add it to the collision domains list.

Args:

  • name (str): The name of the collision domain.

Returns:

  • Kathara.model.Link: A Kathara collision domain.

method Lab.get_or_new_machine

get_or_new_machine(name: str, **kwargs) → MachinePackage.Machine

Get the specified device. If it not exists, create and add it to the devices list.

Args:

  • name (str): The name of the device
  • **kwargs: Contains device meta information. Keys are meta property names, values are meta property values.

Returns:

  • Kathara.model.Machine: A Kathara device.

method Lab.has_host_path

has_host_path() → bool

Check if the network scenario has a directory on the host.

Returns:

  • bool: True if network scenario has a path on the host filesystem, else False.

method Lab.has_link

has_link(link_name: str) → bool

Check if the specified collision domain is in the network scenario.

Args:

  • link_name (str): The name of the collision domain to search.

Returns:

  • bool: True if the collision domain is in the network scenario, else False.

method Lab.has_links

has_links(link_names: Set[str]) → bool

Check if the specified collision domains are in the network scenario.

Args:

  • link_names (Set[str]): A set of strings containing the names of the collision domains to search.

Returns:

  • bool: True if the collision domains are all in the network scenario, else False.

method Lab.has_machine

has_machine(machine_name: str) → bool

Check if the specified device is in the network scenario.

Args:

  • machine_name (str): The name of the device to search.

Returns:

  • bool: True if the device is in the network scenario, else False.

method Lab.has_machines

has_machines(machine_names: Set[str]) → bool

Check if the specified devices are in the network scenario.

Args:

  • machine_names (Set[str]): A set of strings containing the names of the devices to search.

Returns:

  • bool: True if the devices are all in the network scenario, else False.

method Lab.new_link

new_link(name: str) → LinkPackage.Link

Create the collision domain and add it to the collision domains list.

Args:

  • name (str): The name of the collision domain.

Returns:

  • Kathara.model.Link: A Kathara collision domain.

Raises:

  • LinkAlreadyExistsError: If the specified link is already in the network scenario.

method Lab.new_machine

new_machine(name: str, **kwargs) → MachinePackage.Machine

Create and add the device to the devices list.

Args:

  • name (str): The name of the device
  • **kwargs: Contains device meta information. Keys are meta property names, values are meta property values.

Returns:

  • Kathara.model.Machine: A Kathara device.

Raises:

  • MachineAlreadyExistsError: If the device is already in the network scenario.

This file was automatically generated via lazydocs.

Clone this wiki locally