fliswarm Reference#
Actor#
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 totcp://node:port
whereport
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:
- async connected()[source]#
Returns
True
if the node and the Docker client are connected.- Return type:
- 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
onsdss-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:
- async report_status(command, volumes=True, containers=True)[source]#
Reports the status of the node to an actor.
- Parameters:
Notes
Outputs the
node
keyword, with formatnode={node_name, addr, daemon_addr, node_alive, docker_alive}
. Ifcontainers=True
, outputs thecontainer
keyword with formatcontainer={node_name, container_short_id}
. Ifvolumes=True
, reports thevolume
keyword with formatvolume={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.
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.
- fliswarm.tools.select_nodes(nodes, category=None, names=None)[source]#
Filters the nodes to command.
- 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.