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: Node)[source]

Returns the name of the container for a node.

async start() BaseActor[source]

Starts the actor.

parser = <CluGroup command-parser>

Node

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

Bases: object

A client to handle a computer node.

Parameters:
  • name – The name associated with this node.

  • addr – The address to the node.

  • category – A category to use as a filter.

  • daemon_addr – The address to the Docker daemon. If None, defaults to tcp://node:port where port is the default Docker daemon port.

  • registry – The path to the Docker registry.

async client_alive() bool[source]

Checks whether the Docker client is connected and pinging.

async connect()[source]

Connects to the Docker client on the remote node.

async connected() bool[source]

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

async create_volume(name: str, driver: str = 'local', opts: Dict[str, Any] = {}, force: bool = False, command: Command | FakeCommand | None = None)[source]

Creates a volume in the node Docker engine.

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

  • driver – The driver to use.

  • opts – A dict of key-values with the options to pass to the volume when creating it.

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

  • command – 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: str)[source]

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

async is_container_running(name: str)[source]

Returns True if the container is running.

async ping(timeout=2) bool[source]

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

async report_status(command: Command, volumes: bool = True, containers: bool = True)[source]

Reports the status of the node to an actor.

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

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

  • containers – 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: str, image: str, volumes: List[Any] = [], privileged: bool = False, registry: Any | None = None, envs: Dict[str, Any] = {}, ports: List[int] | Dict[str, Tuple[str, int]] = [], force: bool = False, command: Command | FakeCommand | None = None) bool[source]

Runs a container in the node, in detached mode.

Parameters:
  • name – The name to assign to the container.

  • image – The image to run.

  • volumes – 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 – Whether to run the container in privileged mode.

  • registry – The registry from which to pull the image, if it doesn’t exist locally.

  • envs – A dictionary of environment variable to value to pass to the container.

  • ports – 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 – If True, removes any running containers of the same name, or any container with the same image as ancestor.

  • command – A command to which output messages.

Returns:

The container object.

async stop_container(name: str, image: str, force: bool = False, command: Command | FakeCommand | None = None)[source]

Stops and removes the container.

Parameters:
  • name – The name to assign to the container.

  • image – The image to run.

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

  • command – 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: int)[source]

Returns an ID to the pool.

fliswarm.tools.select_nodes(nodes: Dict[str, Any], category: str | None = None, names: str | List[str] | None = None) Set[Node][source]

Filters the nodes to command.

Parameters:
  • nodes – A dictionary of Node instances to be filtered, keyed by node name.

  • category – A category on which to filter.

  • names – 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.

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.