Skip to content

Kathara.foundation.manager.IManager

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

module Kathara.foundation.manager.IManager


class IManager

Interface to be implemented in the virtualization managers


method IManager.check_image

check_image(image_name: str) → None

Check if the specified image is valid.

Args:

  • image_name (str): The name of the image

Returns: None

Raises:

  • ConnectionError: If the image is not locally available and there is no connection to a remote image repository.
  • ImageNotFoundError: If the image is not found.

method IManager.connect_machine_to_link

connect_machine_to_link(
    machine: Kathara.model.Machine.Machine,
    link: Kathara.model.Link.Link,
    mac_address: Optional[str] = None
) → None

Connect a Kathara device to a collision domain.

Args:

  • machine (Kathara.model.Machine): A Kathara machine object.
  • link (Kathara.model.Link): A Kathara collision domain object.
  • mac_address (Optional[str]): The MAC address to assign to the interface.

Returns: None

Raises:

  • LabNotFoundError: If the device specified is not associated to any network scenario.
  • LabNotFoundError: If the collision domain is not associated to any network scenario.
  • MachineCollisionDomainConflictError: If the device is already connected to the collision domain.

method IManager.connect_tty

connect_tty(
    machine_name: str,
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    shell: str = None,
    logs: bool = False,
    wait: Union[bool, Tuple[int, float]] = True
) → None

Connect to a device in a running network scenario, using the specified shell.

Args:

  • machine_name (str): The name of the device to connect.
  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab. If None, lab_name or lab should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab. If None, lab_hash or lab should be set.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name. If None, lab_hash or lab_name should be set.
  • shell (str): The name of the shell to use for connecting.
  • logs (bool): If True, print startup logs on stdout.
  • wait (Union[bool, Tuple[int, float]]): If True, wait indefinitely until the end of the startup commands execution before connecting. If a tuple is provided, the first value indicates the number of retries before stopping waiting and the second value indicates the time interval to wait for each retry. Default is True.

Returns: None

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.

method IManager.connect_tty_obj

connect_tty_obj(
    machine: Kathara.model.Machine.Machine,
    shell: str = None,
    logs: bool = False,
    wait: Union[bool, Tuple[int, float]] = True
) → None

Connect to a device in a running network scenario, using the specified shell.

Args:

  • machine (Machine): The device to connect.
  • shell (str): The name of the shell to use for connecting.
  • logs (bool): If True, print startup logs on stdout.
  • wait (Union[bool, Tuple[int, float]]): If True, wait indefinitely until the end of the startup commands execution before connecting. If a tuple is provided, the first value indicates the number of retries before stopping waiting and the second value indicates the time interval to wait for each retry. Default is True.

Returns: None

Raises:

  • LabNotFoundError: If the specified device is not associated to any network scenario.

method IManager.copy_files

copy_files(
    machine: Kathara.model.Machine.Machine,
    guest_to_host: Dict[str, Union[str, io.IOBase]]
) → None

Copy files on a running device in the specified paths.

Args:

  • machine (Kathara.model.Machine): A running device object. It must have the api_object field populated.
  • guest_to_host (Dict[str, Union[str, io.IOBase]]): A dict containing the device path as key and a fileobj to copy in path as value or a path to a file.

Returns: None


method IManager.deploy_lab

deploy_lab(
    lab: Kathara.model.Lab.Lab,
    selected_machines: Set[str] = None
) → None

Deploy a Kathara network scenario.

Args:

  • lab (Kathara.model.Lab): A Kathara network scenario.
  • selected_machines (Set[str]): If not None, deploy only the specified devices.

Returns: None


method IManager.deploy_link

deploy_link(link: Kathara.model.Link.Link) → None

Deploy a Kathara collision domain.

Args:

  • link (Kathara.model.Link): A Kathara collision domain object.

Returns: None

Raises:

  • LabNotFoundError: If the collision domain is not associated to any network scenario.

method IManager.deploy_machine

deploy_machine(machine: Kathara.model.Machine.Machine) → None

Deploy a Kathara device.

Args:

  • machine (Kathara.model.Machine): A Kathara machine object.

Returns: None

Raises:

  • LabNotFoundError: If the specified device is not associated to any network scenario.

method IManager.disconnect_machine_from_link

disconnect_machine_from_link(
    machine: Kathara.model.Machine.Machine,
    link: Kathara.model.Link.Link
) → None

Disconnect a Kathara device from a collision domain.

Args:

  • machine (Kathara.model.Machine): A Kathara machine object.
  • link (Kathara.model.Link): The Kathara collision domain from which disconnect the device.

Returns: None

Raises:

  • LabNotFoundError: If the device specified is not associated to any network scenario.
  • LabNotFoundError: If the collision domain is not associated to any network scenario.
  • MachineCollisionDomainConflictError: If the device is not connected to the collision domain.

method IManager.exec

exec(
    machine_name: str,
    command: Union[List[str], str],
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    wait: Union[bool, Tuple[int, float]] = False,
    stream: bool = True
) → Union[Generator[Tuple[bytes, bytes], NoneType, NoneType], Tuple[bytes, bytes, int]]

Exec a command on a device in a running network scenario.

Args:

  • machine_name (str): The name of the device to connect.
  • command (Union[List[str], str]): The command to exec on the device.
  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab. If None, lab_name or lab should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab. If None, lab_hash or lab should be set.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name. If None, lab_hash or lab_name should be set.
  • wait (Union[bool, Tuple[int, float]]): If True, wait indefinitely until the end of the startup commands execution before executing the command. If a tuple is provided, the first value indicates the number of retries before stopping waiting and the second value indicates the time interval to wait for each retry. Default is False.
  • stream (bool): If True, return a generator object containing the command output. If False, returns a tuple containing the complete stdout, the stderr, and the return code of the command.

Returns:

  • Union[Generator[Tuple[bytes, bytes]], Tuple[bytes, bytes, int]]: A generator of tuples containing the stdout and stderr in bytes or a tuple containing the stdout, the stderr and the return code of the command.

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.
  • MachineNotRunningError: If the specified device is not running.
  • MachineBinaryError: If the binary of the command is not found.

method IManager.exec_obj

exec_obj(
    machine: Kathara.model.Machine.Machine,
    command: Union[List[str], str],
    wait: Union[bool, Tuple[int, float]] = False,
    stream: bool = True
) → Union[Generator[Tuple[bytes, bytes], NoneType, NoneType], Tuple[bytes, bytes, int]]

Exec a command on a device in a running network scenario.

Args:

  • machine (Machine): The device to connect.
  • command (Union[List[str], str]): The command to exec on the device.
  • wait (Union[bool, Tuple[int, float]]): If True, wait indefinitely until the end of the startup commands execution before executing the command. If a tuple is provided, the first value indicates the number of retries before stopping waiting and the second value indicates the time interval to wait for each retry. Default is False.
  • stream (bool): If True, return a generator object containing the command output. If False, returns a tuple containing the complete stdout, the stderr, and the return code of the command.

Returns:

  • Union[Generator[Tuple[bytes, bytes]], Tuple[bytes, bytes, int]]: A generator of tuples containing the stdout and stderr in bytes or a tuple containing the stdout, the stderr and the return code of the command.

Raises:

  • LabNotFoundError: If the specified device is not associated to any network scenario.
  • MachineNotRunningError: If the specified device is not running.
  • MachineBinaryError: If the binary of the command is not found.

method IManager.get_formatted_manager_name

get_formatted_manager_name() → str

Return a formatted string containing the current manager name.

Returns:

  • str: A formatted string containing the current manager name.

method IManager.get_lab_from_api

get_lab_from_api(
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None
) → Lab

Return the network scenario (specified by the hash or name), building it from API objects.

Args:

  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name. If None, lab_name should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash. If None, lab_hash should be set.

Returns:

  • Lab: The built network scenario.

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.

method IManager.get_link_api_object

get_link_api_object(
    link_name: str,
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    all_users: bool = False
) → Any

Return the corresponding API object of a collision domain in a network scenario.

Args:

  • link_name (str): The name of the collision domain.
  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab. If None, lab_name or lab should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab. If None, lab_hash or lab should be set.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name. If None, lab_hash or lab_name should be set.
  • all_users (bool): If True, return information about collision domains of all users.

Returns:

  • Any: API object of the collision domain specific for the current manager.

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.
  • LinkNotFoundError: If the collision domain is not found.

method IManager.get_link_stats

get_link_stats(
    link_name: str,
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    all_users: bool = False
) → Generator[Optional[Kathara.foundation.manager.stats.ILinkStats.ILinkStats], NoneType, NoneType]

Return information of the specified deployed network in a specified network scenario.

Args:

  • link_name (str): The name of the collision domain for which statistics are requested.
  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab. If None, lab_name or lab should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab. If None, lab_hash or lab should be set.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name. If None, lab_hash or lab_name should be set.
  • all_users (bool): If True, return information about the networks of all users.

Returns:

  • Generator[Optional[ILinkStats], None, None]: A generator containing the ILinkStats object with the network info. Returns None if the network is not found.

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.

method IManager.get_link_stats_obj

get_link_stats_obj(
    link: Kathara.model.Link.Link,
    all_users: bool = False
) → Generator[Optional[Kathara.foundation.manager.stats.ILinkStats.ILinkStats], NoneType, NoneType]

Return information of the specified deployed network in a specified network scenario.

Args:

  • link (Link): The collision domain for which statistics are requested.
  • all_users (bool): If True, return information about the networks of all users.

Returns:

  • Generator[Optional[ILinkStats], None, None]: A generator containing the ILinkStats object with the network info. Returns None if the network is not found.

Raises:

  • LabNotFoundError: If the specified device is not associated to any network scenario.

method IManager.get_links_api_objects

get_links_api_objects(
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    all_users: bool = False
) → List[Any]

Return API objects of collision domains in a network scenario.

Args:

  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name.
  • all_users (bool): If True, return information about collision domains of all users.

Returns:

  • List[Any]: API objects of collision domains, specific for the current manager.

method IManager.get_links_stats

get_links_stats(
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    link_name: str = None,
    all_users: bool = False
) → Generator[Dict[str, Kathara.foundation.manager.stats.ILinkStats.ILinkStats], NoneType, NoneType]

Return information about deployed networks.

Args:

  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name.
  • link_name (str): If specified return all the networks with link_name.
  • all_users (bool): If True, return information about the networks of all users.

Returns:

  • Generator[Dict[str, ILinkStats], None, None]: A generator containing dicts that has API Object identifier as keys and ILinksStats objects as values.

method IManager.get_machine_api_object

get_machine_api_object(
    machine_name: str,
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    all_users: bool = False
) → Any

Return the corresponding API object of a running device in a network scenario.

Args:

  • machine_name (str): The name of the device.
  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab. If None, lab_name or lab should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab. If None, lab_hash or lab should be set.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name. If None, lab_hash or lab_name should be set.
  • all_users (bool): If True, return information about devices of all users.

Returns:

  • Any: API object of the device specific for the current manager.

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.
  • MachineNotFoundError: If the specified device is not found.

method IManager.get_machine_stats

get_machine_stats(
    machine_name: str,
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    all_users: bool = False
) → Generator[Optional[Kathara.foundation.manager.stats.IMachineStats.IMachineStats], NoneType, NoneType]

Return information of the specified device in a specified network scenario.

Args:

  • machine_name (str): The name of the device for which statistics are requested.
  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab. If None, lab_name or lab should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab. If None, lab_hash or lab should be set.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name. If None, lab_hash or lab_name should be set.
  • all_users (bool): If True, search the device among all the users devices.

Returns:

  • Generator[Optional[IMachineStats], None, None]: A generator containing the IMachineStats object with the device info. Returns None if the device is not found.

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.

method IManager.get_machine_stats_obj

get_machine_stats_obj(
    machine: Kathara.model.Machine.Machine,
    all_users: bool = False
) → Generator[Optional[Kathara.foundation.manager.stats.IMachineStats.IMachineStats], NoneType, NoneType]

Return information of the specified device in a specified network scenario.

Args:

  • machine (Machine): The device for which statistics are requested.
  • all_users (bool): If True, search the device among all the users devices.

Returns:

  • Generator[Optional[IMachineStats], None, None]: A generator containing the IMachineStats object with the device info. Returns None if the device is not found.

Raises:

  • LabNotFoundError: If the specified device is not associated to any network scenario.
  • MachineNotRunningError: If the specified device is not running.

method IManager.get_machines_api_objects

get_machines_api_objects(
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    all_users: bool = False
) → List[Any]

Return API objects of running devices.

Args:

  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name.
  • all_users (bool): If True, return information about devices of all users.

Returns:

  • List[Any]: API objects of devices, specific for the current manager.

method IManager.get_machines_stats

get_machines_stats(
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    machine_name: str = None,
    all_users: bool = False
) → Generator[Dict[str, Kathara.foundation.manager.stats.IMachineStats.IMachineStats], NoneType, NoneType]

Return information about the running devices.

Args:

  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name.
  • machine_name (str): If specified return all the devices with machine_name.
  • all_users (bool): If True, return information about the device of all users.

Returns:

  • Generator[Dict[str, IMachineStats], None, None]: A generator containing dicts that has API Object identifier as keys and IMachineStats objects as values.

method IManager.get_release_version

get_release_version() → str

Return the current manager version.

Returns:

  • str: The current manager version.

method IManager.undeploy_lab

undeploy_lab(
    lab_hash: Optional[str] = None,
    lab_name: Optional[str] = None,
    lab: Optional[Kathara.model.Lab.Lab] = None,
    selected_machines: Optional[Set[str]] = None
) → None

Undeploy a Kathara network scenario.

Args:

  • lab_hash (Optional[str]): The hash of the network scenario. Can be used as an alternative to lab_name and lab. If None, lab_name or lab should be set.
  • lab_name (Optional[str]): The name of the network scenario. Can be used as an alternative to lab_hash and lab. If None, lab_hash or lab should be set.
  • lab (Optional[Kathara.model.Lab]): The network scenario object. Can be used as an alternative to lab_hash and lab_name. If None, lab_hash or lab_name should be set.
  • selected_machines (Optional[Set[str]]): If not None, undeploy only the specified devices.

Returns: None

Raises:

  • InvocationError: If a running network scenario hash or name is not specified.

method IManager.undeploy_link

undeploy_link(link: Kathara.model.Link.Link) → None

Undeploy a Kathara collision domain.

Args:

  • link (Kathara.model.Link): A Kathara collision domain object.

Returns: None

Raises:

  • LabNotFoundError: If the collision domain is not associated to any network scenario.

method IManager.undeploy_machine

undeploy_machine(machine: Kathara.model.Machine.Machine) → None

Undeploy a Kathara device.

Args:

  • machine (Kathara.model.Machine): A Kathara machine object.

Returns: None

Raises:

  • LabNotFoundError: If the device specified is not associated to any network scenario.

method IManager.update_lab_from_api

update_lab_from_api(lab: Kathara.model.Lab.Lab) → None

Update the passed network scenario from API objects.

Args:

  • lab (Lab): The network scenario to update.

method IManager.wipe

wipe(all_users: bool = False) → None

Undeploy all the running network scenarios.

Args:

  • all_users (bool): If false, undeploy only the current user network scenarios. If true, undeploy the running network scenarios of all users.

Returns: None


This file was automatically generated via lazydocs.

Clone this wiki locally