fliswarm Reference#

Actor#

class fliswarm.actor.FLISwarmActor(*args, **kwargs)[source]#

Bases: LegacyActor

FLISwarm actor.

async connect_nodes()[source]#

Connects to the nodes.

get_container_name(node)[source]#

Returns the name of the container for a node.

Parameters:

node (Node) –

async start()[source]#

Starts the actor.

Return type:

BaseActor

parser = <CluGroup command-parser>#
Parameters:
  • args (Any) –

  • kwargs (Any) –

Return type:

Any

Node#

class fliswarm.node.Node(name, addr, category=None, daemon_addr=None, registry=None)[source]#

Bases: object

A client to handle a computer node.

Parameters:
  • name (str) – The name associated with this node.

  • addr (str) – The address to the node.

  • category (Optional[str]) – A category to use as a filter.

  • daemon_addr (Optional[str]) – The address to the Docker daemon. If None, defaults to tcp://node:port where port is the default Docker daemon port.

  • registry (Optional[str]) – The path to the Docker registry.

async client_alive()[source]#

Checks whether the Docker client is connected and pinging.

Return type:

bool

async connect()[source]#

Connects to the Docker client on the remote node.

async connected()[source]#

Returns True if the node and the Docker client are connected.

Return type:

bool

async create_volume(name, driver='local', opts={}, force=False, command=None)[source]#

Creates a volume in the node Docker engine.

Parameters:
  • name (str) – The name of the volume to create.

  • driver (str) – The driver to use.

  • opts (Dict[str, Any]) – A dict of key-values with the options to pass to the volume when creating it.

  • force (bool) – If True, and the volume already exists, removes it and creates it anew.

  • command (Command | FakeCommand | None) – A command to which output messages.

Returns:

The volume object.

Examples

To create an NFS volume pointing to /data on sdss-hub

nuc.create_volume('data', driver='local'
                  opts=['type=nfs', 'o=nfsvers=4,addr=sdss-hub,rw',
                        'device=:/data'])
async get_volume(name)[source]#

Returns the volume that matches the name, if it exists.

Parameters:

name (str) –

async is_container_running(name)[source]#

Returns True if the container is running.

Parameters:

name (str) –

async ping(timeout=0.5)[source]#

Pings the node. Returns True if the node is responding.

Return type:

bool

async report_status(command, volumes=True, containers=True)[source]#

Reports the status of the node to an actor.

Parameters:
  • command (Command) – The command that is requesting the status.

  • volumes (bool) – Whether to report the volumes connected to the node Docker engine.

  • containers (bool) – Whether to report the containers running. Only reports running containers whose ancestor matches the config['image'].

Notes

Outputs the node keyword, with format node={node_name, addr, daemon_addr, node_alive, docker_alive}. If containers=True, outputs the container keyword with format container={node_name, container_short_id}. If volumes=True, reports the volume keyword with format volume={node_name, volume, ping, docker_client}

async run_container(name, image, volumes=[], privileged=False, registry=None, envs={}, ports=[], force=False, command=None)[source]#

Runs a container in the node, in detached mode.

Parameters:
  • name (str) – The name to assign to the container.

  • image (str) – The image to run.

  • volumes (List[Any]) – Names of the volumes to mount. The mount point in the container will match the original device. The volumes must already exist in the node Docker engine.

  • privileged (bool) – Whether to run the container in privileged mode.

  • registry (Any | None) – The registry from which to pull the image, if it doesn’t exist locally.

  • envs (Dict[str, Any]) – A dictionary of environment variable to value to pass to the container.

  • ports (List[int] | Dict[str, Tuple[str, int]]) – Ports to bind inside the container. The format must be {'2222/tcp': 3333} which will expose port 2222 inside the container as port 3333 on the node. Also accepted is a list of integers; each integer port will be exposed in the container and bound to the same port in the node.

  • force (bool) – If True, removes any running containers of the same name, or any container with the same image as ancestor.

  • command (Command | FakeCommand | None) – A command to which output messages.

Returns:

The container object.

async stop_container(name, image, force=False, command=None)[source]#

Stops and removes the container.

Parameters:
  • name (str) – The name to assign to the container.

  • image (str) – The image to run.

  • force (bool) – If True, removes any stopped containers of the same name or with the same image as ancestor.

  • command (Command | FakeCommand | None) – A command to which output messages.

Tools#

class fliswarm.tools.FakeCommand[source]#

Bases: object

A fake Command object that doesn’t do anything.

class fliswarm.tools.IDPool[source]#

Bases: object

An ID pool that allows to return values to be reused.

get()[source]#

Returns an ID.

put(id)[source]#

Returns an ID to the pool.

Parameters:

id (int) –

fliswarm.tools.select_nodes(nodes, category=None, names=None)[source]#

Filters the nodes to command.

Parameters:
  • nodes (Dict[str, Any]) – A dictionary of Node instances to be filtered, keyed by node name.

  • category (str | None) – A category on which to filter.

  • names (str | List[str] | None) – A list or comma-separated string of node names on which to filter.

Returns:

A set of enabled Node instances that match the provided category or names. If neither category or names are defined, returns all the nodes.

Return type:

Set[Node]

async fliswarm.tools.subprocess_run_async(*args, shell=False)[source]#

Runs a command asynchronously.

If shell=True the command will be executed through the shell. In that case the argument must be a single string with the full command. Otherwise, must receive a list of program arguments. Returns the output of stdout.