topology.platforms.node

Base platform engine module for topology.

This module defines the functionality that a Topology Engine Node must implement to be able to create a network using a specific environment.

Classes

  • HighLevelShellAPI: API used to interact with node shells.
  • LowLevelShellAPI: API used to interact with low level shell objects.
  • ServicesAPI: API to gather information and connection parameters to a node services.
  • StateAPI: API to control the enable/disabled state of a node.
  • BaseNode: Base engine node class.
  • CommonNode: Base engine node class with a common base implementation.
class topology.platforms.node.HighLevelShellAPI

API used to interact with node shells.

Variables:default_shell (str) – Engine node default shell.

Inheritance

Inheritance diagram of HighLevelShellAPI

available_shells()

Get the list of available shells.

Returns:The list of all available shells. The first element is the default (if any).
Return type:List of str.
send_command(cmd, shell=None, silent=False)

Send a command to this engine node.

Parameters:
  • cmd (str) – Command to send.
  • shell (str) – Shell that must interpret the command. None for the default shell. Is up to the engine node to determine what its default shell is.
  • silent (bool) – True to call the shell logger, False otherwise.
Returns:

The response of the command.

Return type:

str

class topology.platforms.node.LowLevelShellAPI

API used to interact with low level shell objects.

Inheritance

Inheritance diagram of LowLevelShellAPI

get_shell(shell)

Get the shell object associated with the given name.

The shell object allows to access the low-level shell API.

Parameters:shell (str) – Name of the shell.
Returns:The associated shell object.
Return type:BaseShell
use_shell(shell)

Create a context manager that allows to use a different default shell in a context, including access to it’s low-level shell object.

Parameters:shell (str) – The default shell to use in the context.

Assuming, for example, that a node has two shells: bash and python:

with mynode.use_shell('python') as python:
    # This context manager sets the default shell to 'python'
    mynode('from os import getcwd')
    cwd = mynode('print(getcwd())')

    # Access to the low-level shell API
    python.send_command('foo = (', matches=['... '])
    ...
class topology.platforms.node.ServicesAPI

API to gather information and connection parameters to a node services.

Inheritance

Inheritance diagram of ServicesAPI

available_services()

Get the list of all available services.

Returns:The list of all available services.
Return type:List of str.
get_service(service)

Get the service object associated with the given name.

The service object holds all connection parameters.

Parameters:service (str) – Name of the service.
Returns:The associated service object.
Return type:BaseService
class topology.platforms.node.StateAPI

API to control the enable/disabled state of a node.

Inheritance

Inheritance diagram of StateAPI

disable()

Disable this node.

A disabled node doesn’t allow communication.

enable()

Enable this node.

An enabled node allows communication.

is_enabled()

Query if the node is enabled.

Returns:True if the node is enabled, False otherwise.
Return type:bool
class topology.platforms.node.BaseNode(identifier, **kwargs)

Base engine node class.

This class represent the base interface that engine nodes require to implement.

See the Plugins Development Guide for reference.

Parameters:

identifier (str) – User identifier of the engine node.

Variables:
  • identifier – User identifier of the engine node. Please note that this identifier is unique in the topology being built, but is not unique in the execution system.
  • metadata – Additional metadata (kwargs leftovers).
  • ports – Mapping between node ports and engine ports. This variable is populated by the topology.manager.TopologyManager.

Inheritance

Inheritance diagram of BaseNode

class topology.platforms.node.CommonNode(identifier, **kwargs)

Base engine node class with a common base implementation.

This class provides a basic common implementation for managing shells and services. Internal ordered dictionaries handles the keys for shells and services objects that implements the logic for those shells or services.

Child classes will then only require to call registration methods _register_shell() and _register_service().

In particular, this class implements support for Communication Libraries using class LibsProxy that will hook with all available libraries.

See BaseNode.

Note

The method :meth: _get_services_address should be provided by the Platform Engine base node.

Inheritance

Inheritance diagram of CommonNode

available_services()

Implementation of the public available_services interface.

This method will just list the available keys in the internal ordered dictionary.

See ServicesAPI.available_services() for more information.

available_shells()

Implementation of the public available_shells interface.

This method will just list the available keys in the internal ordered dictionary.

See HighLevelShellAPI.available_shells() for more information.

disable()

Implementation of the disable interface.

This method will just set the value of the _enabled flag to False.

See StateAPI.disable() for more information.

enable()

Implementation of the enable interface.

This method will just set the value of the _enabled flag to True.

See StateAPI.enable() for more information.

get_service(service)

Implementation of the public get_service interface.

This method will return the service object associated with the given service name.

See ServicesAPI.get_service() for more information.

get_shell(shell)

Implementation of the public get_shell interface.

This method will return the shell object associated with the given shell name.

See LowLevelShellAPI.get_shell() for more information.

is_enabled()

Implementation of the is_enabled interface.

This method will just return the internal value of the _enabled flag.

See StateAPI.is_enabled() for more information.

send_command(cmd, shell=None, silent=False)

Implementation of the public send_command interface.

This method will lookup for the shell argument in an internal ordered dictionary to fetch a shell object to delegate the command to. If None is provided, the default shell of the node will be used.

See HighLevelShellAPI.send_command() for more information.

use_shell(shell)

Implementation of the public use_shell interface.

This method allows to create contexts (using a Python Context Manager) that allows the user, by the means of a with statement, to create a context to use a specific shell in it.

See LowLevelShellAPI.use_shell() for more information.