Skip to main content

Swarm Regulator

Regulate your Docker Swarm cluster, according to YOUR rules. Use async Python functions to enforce rules like service placement and resource management on your Docker Swarm.

Concepts

Consumer

Each regulator is based on top of a single consumer. The consumer responds to Docker events and instruments all components of the regulator.

Conditions

A regulator needs to know when to apply its rules. This is what conditions are for. Conditions help us know when should a rule be applied on a Docker Swarm entity. In brief, a condition is a Python function (or callable) that accepts a Docker Swarm entity as a single argument and returns True when the rule should run, and False when it shouldn't.

🙌 Heads up: In order to avoid infinite loops, a confition that initially returns True, should return False, when it gets the regulated entity as an argument. If this is not the case, the rule is being ignored.

Rules

Rules simply do the job. Rules are async Python functions that accept a Docker Swarm entity as an argument and return it modified, so it complies with the business logic we intend to enforce on our Docker Swarm cluster.

Requirements

  • Python 3.8+
  • Docker Swarm Mode cluster

Install

pipenv

pipenv install swarm-regulator

poetry

poetry add swarm-regulator

pip

pip install swarm-regulator

Run

  1. Create a Python file (e.g. regulator.py)
  2. Import the consumer from the swarm_regulator package
  3. Register your rules that will run according to given conditions
  4. Run your regulator

Example

regulator.py

from swarm_regulator import consumer


def _extract_constraints(service_spec):
    return service_spec["TaskTemplate"]["Placement"].get("Constraints", [])


def has_not_constraints(service_spec) -> bool:
    constraints = _extract_constraints(service_spec)
    return not len(constraints)


async def do_not_schedule_on_gpu(service_spec):
    constraints = _extract_constraints(service_spec) + ["node.labels.gpu!=true"]
    service_spec["TaskTemplate"]["Placement"]["Constraints"] = constraints
    return service_spec


consumer.register_rule(
    "service", has_not_constraints, do_not_schedule_on_gpu,
)

consumer.run()

Run

python regulator.py

Metadata

Release files for swarm-regulator 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swarm-regulator 0.2.3
File Size Uploaded Provenance Actions
swarm-regulator-0.2.3.tar.gz 5.2 kB Without provenance Details for swarm-regulator-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swarm-regulator 0.2.3
File Interpreter ABI Platform Actions
swarm_regulator-0.2.3-py3-none-any.whl Python 3 none any Details for swarm_regulator-0.2.3-py3-none-any.whl

Total release size: 11.5 kB

Release files / swarm-regulator-0.2.3.tar.gz

Download URL swarm-regulator-0.2.3.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4356ce01bfd7b36e99f90aef1a631222808a44f0fbe5bef69ca3b402d55f35e6
BLAKE2b-256 checksum
How to use checksums
7674c351a09a1e6612fbb43c0a1848720230d9f649272b28625dbf888ac0438c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.8.1 Darwin/19.2.0

Release files / swarm_regulator-0.2.3-py3-none-any.whl

Download URL swarm_regulator-0.2.3-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bace59cdf88bf3135ce769c8d41216bf7ef0c275edb7a723346f22de629bce97
BLAKE2b-256 checksum
How to use checksums
001daa454e62059b5b3347b6333d473cb0a14dbcbc724b85ee9147380c602286
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.0 CPython/3.8.1 Darwin/19.2.0

Security for swarm-regulator 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page