Skip to content

Kathara.model.Machine

Tommaso Caiazzi edited this page Sep 30, 2022 · 15 revisions

module Kathara.model.Machine


class Machine

A Kathara device.

Contains information about the device and the API object to interact with the Manager.

Attributes:

  • lab (Kathara.model.Lab): The Kathara network Scenario of the device.
  • name (str): The name of the device.
  • interfaces (collection.OrderedDict[int, Kathara.model.Link]): A list of the collision domains of the device.
  • meta (Dict[str, Any]): Keys are meta properties name, values are meta properties values.
  • startup_commands (List[str]): A list of commands to execute at the device startup.
  • api_object (Any): To interact with the current Kathara Manager.
  • capabilities (List[str]): The selected capabilities for the device.
  • startup_path (str): The path of the device startup file, if exists.
  • shutdown_path (str): The path of the device shutdown file, if exists.
  • folder (str): The path of the device folder, if exists.

method Machine.__init__

__init__(lab: 'LabPackage.Lab', name: str, **kwargs) → None

Create a new instance of a Kathara device.

Args:

  • lab (Kathara.model.Lab): The Kathara network scenario of the new device.
  • name (str): The name of the device.
  • **kwargs (Dict[str, Any]): Specifies the optional parameters of the device.

Returns: None


method Machine.add_interface

add_interface(link: 'LinkPackage.Link', number: int = None) → None

Add an interface to the device attached to the specified collision domain.

Args:

  • link (Kathara.model.Link): The Kathara collision domain to attach.
  • number (int): The number of the new interface. If it is None, the first free number is selected.

Returns: None

Raises:

  • MachineCollisionDomainConflictError: If the interface number specified is already used on the device.
  • MachineCollisionDomainConflictError: If the device is already connected to the collision domain.

method Machine.add_meta

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

Add a meta property to the device.

Args:

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

Returns: None

Raises:

  • MachineOptionError: If the specified value is not valid for the specified property.

method Machine.check

check() → None

Sorts interfaces check if there are missing positions.

Returns: None

Raises:

  • NonSequentialMachineInterfaceError: If there is a missing interface number.

method Machine.get_cpu

get_cpu(multiplier: int = 1) → Optional[int]

Get the CPU limit, multiplied by a specific multiplier.

User should pass a float value ranging from 0 to max user CPUs. Try to take it from options, or device meta. Otherwise, return None.

Args:

  • multiplier (int): A numeric multiplier for the CPU limit value.

Returns:

  • Optional[int]: The CPU limit of the device.

Raises:

  • MachineOptionError: If the CPU value specified is not valid.

method Machine.get_image

get_image() → str

Get the image of the device, if defined in options or device meta. If not, use default one.

Returns:

  • str: The name of the device image.

method Machine.get_mem

get_mem() → str

Get memory limit, if defined in options. If not, use the value from device meta. Otherwise, return None.

Returns:

  • str: The memory limit of the device.

Raises:

  • MachineOptionError: If the memory value specified is not valid.

method Machine.get_num_terms

get_num_terms() → int

Get the number of terminal to be opened for the device.

Returns:

  • int: The number of terminal to be opened.

Raises:

  • MachineOptionError: If the terminals number value specified is not valid.

method Machine.get_ports

get_ports() → Optional[Dict[Tuple[int, str], int]]

Get the port mapping of the device.

Returns:

  • Dict[(int, str), int]: Keys are pairs (host_port, protocol), values specifies the guest_port.

method Machine.is_ipv6_enabled

is_ipv6_enabled() → bool

Check if IPv6 is enabled on the device.

Returns:

  • bool: True if it is enabled, else False.

Raises:

  • MachineOptionError: If the IPv6 value specified is not valid.

method Machine.pack_data

pack_data() → Optional[bytes]

Pack machine data into a .tar.gz file and returns the tar content as a byte array.

While packing files, it also applies the win2linux patch in order to remove UTF-8 BOM.

Returns:

  • bytes: the tar content.

method Machine.remove_interface

remove_interface(link: 'LinkPackage.Link') → None

Disconnect the device from the specified collision domain.

Args:

  • link (Kathara.model.Link): The Kathara collision domain to disconnect.

Returns: None

Raises:

  • MachineCollisionDomainConflictError: If the device is not connected to the collision domain.

method Machine.update_meta

update_meta(args: Dict[str, Any]) → None

Update the device metas from a dict.

Args:

  • args (Dict[str, Any]): Keys are the meta properties names, values are the updated meta properties values.

Returns: None


This file was automatically generated via lazydocs.

Clone this wiki locally