Skip to content

Kathara.manager.Kathara

Tommaso Caiazzi edited this page Jun 17, 2024 · 13 revisions

module Kathara.manager.Kathara

Global Variables

  • AVAILABLE_MANAGERS

class Kathara

Facade class for interacting with Kathara. It is a proxy for the selected Manager.

method Kathara.__init__

__init__() → None

method Kathara.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 Kathara.connect_machine_to_link

connect_machine_to_link(
    machine: 'Machine',
    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 Kathara.connect_tty

connect_tty(
    machine_name: 'str',
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[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 Kathara.connect_tty_obj

connect_tty_obj(
    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 Kathara.copy_files

copy_files(
    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 Kathara.deploy_lab

deploy_lab(
    lab: 'Lab',
    selected_machines: 'Optional[Set[str]]' = None,
    excluded_machines: 'Optional[Set[str]]' = None
) → None

Deploy a Kathara network scenario.

Args:

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

Returns: None


method Kathara.deploy_link

deploy_link(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 Kathara.deploy_machine

deploy_machine(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 Kathara.disconnect_machine_from_link

disconnect_machine_from_link(machine: 'Machine', 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 Kathara.exec

exec(
    machine_name: 'str',
    command: 'Union[List[str], str]',
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[Lab]' = None,
    wait: 'Union[bool, Tuple[int, float]]' = False,
    stream: 'bool' = True
) → Union[Generator[Tuple[bytes, bytes], None, None], 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 Kathara.exec_obj

exec_obj(
    machine: 'Machine',
    command: 'Union[List[str], str]',
    wait: 'Union[bool, Tuple[int, float]]' = False,
    stream: 'bool' = True
) → Union[Generator[Tuple[bytes, bytes], None, None], 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 Kathara.get_available_managers_name

get_available_managers_name() → Dict[str, str]

Return a dict containing the available manager names.

Returns:

  • Dict[str, str]: keys are the manager names, values are the formatted manager names.

method Kathara.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 Kathara.get_instance

get_instance() → Kathara

Get an instance of Kathara.

Returns:

  • Kathara: instance of Kathara.

Raises:

  • InstantiationError: If two instances of the class are created.

method Kathara.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 Kathara.get_link_api_object

get_link_api_object(
    link_name: 'str',
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[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 Kathara.get_link_stats

get_link_stats(
    link_name: 'str',
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[Lab]' = None,
    all_users: 'bool' = False
) → Generator[Optional[ILinkStats], None, None]

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.
  • PrivilegeError: If all_users is True and the user does not have root privileges.

method Kathara.get_link_stats_obj

get_link_stats_obj(
    link: 'Link',
    all_users: 'bool' = False
) → Generator[Optional[ILinkStats], None, None]

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.
  • PrivilegeError: If all_users is True and the user does not have root privileges.

method Kathara.get_links_api_objects

get_links_api_objects(
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[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.

Raises:

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

method Kathara.get_links_stats

get_links_stats(
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[Lab]' = None,
    link_name: 'str' = None,
    all_users: 'bool' = False
) → Generator[Dict[str, ILinkStats], None, None]

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.

Raises:

  • InvocationError: If a running network scenario hash, name or object is not specified.
  • PrivilegeError: If all_users is True and the user does not have root privileges.

method Kathara.get_machine_api_object

get_machine_api_object(
    machine_name: 'str',
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[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 Kathara.get_machine_stats

get_machine_stats(
    machine_name: 'str',
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[Lab]' = None,
    all_users: 'bool' = False
) → Generator[Optional[IMachineStats], None, None]

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 more than one param among lab_hash, lab_name and lab is specified.
  • PrivilegeError: If all_users is True and the user does not have root privileges.

method Kathara.get_machine_stats_obj

get_machine_stats_obj(
    machine: 'Machine',
    all_users: 'bool' = False
) → Generator[Optional[IMachineStats], None, None]

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.
  • PrivilegeError: If all_users is True and the user does not have root privileges.

method Kathara.get_machines_api_objects

get_machines_api_objects(
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[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.

Raises:

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

method Kathara.get_machines_stats

get_machines_stats(
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[Lab]' = None,
    machine_name: 'str' = None,
    all_users: 'bool' = False
) → Generator[Dict[str, IMachineStats], None, None]

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.

Raises:

  • InvocationError: If more than one param among lab_hash, lab_name and lab is specified.
  • PrivilegeError: If all_users is True and the user does not have root privileges.

method Kathara.get_release_version

get_release_version() → str

Return the current manager version.

Returns:

  • str: The current manager version.

method Kathara.undeploy_lab

undeploy_lab(
    lab_hash: 'Optional[str]' = None,
    lab_name: 'Optional[str]' = None,
    lab: 'Optional[Lab]' = None,
    selected_machines: 'Optional[Set[str]]' = None,
    excluded_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.
  • excluded_machines (Optional[Set[str]]): If not None, exclude devices from being undeployed.

Returns: None

Raises:

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

method Kathara.undeploy_link

undeploy_link(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 Kathara.undeploy_machine

undeploy_machine(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 Kathara.update_lab_from_api

update_lab_from_api(lab: 'Lab') → None

Update the passed network scenario from API objects.

Args:

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

method Kathara.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