Asynchronous configuration management based on Python Asyncio
Project description
Okonf
Asynchronous configuration management system based on Python Asyncio.
Okonf manages the state and configuration of POSIX compatible systems. You can use it to configure your personal computers, servers, routers, ...
Okonf promotes a declarative syntax, where the goal is to ensure a given state of the target host instead of running commands on it.
Okonf emphasizes on being easy to use as a library in your own applications, and easy to extend with reusable components.
Okonf also focuses on excellent performance by running asynchronously.
Inspired by: pyinfra, Ansible, SaltStack.
Status
Okonf is still in early development, and it's API is subject to changes.
Suggestions and contributions are welcome.
Usage as a library
from okonf.connectors import LocalHost
from okonf.facts.files import FileContent
from okonf.utils import run
host = LocalHost()
run(
FileContent('/tmp/some_file', b'Some Content').apply(host),
)
More advanced usage:
import asyncio
from okonf.connectors.ssh import SSHHost
from okonf import Collection
from okonf.facts.files import FileContent
from okonf.facts.git import GitClone
host = SSHHost(host='127.0.0.1', username='myuser')
facts = Collection([
FileContent('/tmp/some_file', b'Some Content'),
GitClone('git@github.com:okeso/Okonf.git', '/opt/Okonf'),
])
asyncio.run(Collection.apply(host))
Usage as a tool
Declare your infrastructure in a Python file (here named infra.py
) with your two dictionnaries named hosts
and configs
.
For example, we like to have vim
, tree
and htop
installed on our systems:
from okonf.connectors import LocalHost
from okonf.facts.apt import AptPresent
hosts = {
'laptop': LocalHost(),
}
configs = {
'laptop': Sequence(
AptPresent(pkg) for pkg in
['vim', 'htop', 'tree'']
),
}
If you installed Okonf via pip
, you should then be able to check the current state with:
okonf check infra.py laptop
And to apply your configuration using:
okonf apply infra.py laptop
Now that you got the basics, you can replace the connector with an SSHHost
, and look at other facts you want to use.
Collections
Okonf provides two types of collections to group tasks into new higher level
tasks: Collection
and Sequence
.
A Collection
of facts will apply each of them in parallel, asynchronously.
A Sequence
of facts will apply each fact after the previous one,
in a sequential manner.
In the example below, the two facts help prividing a common functionnality, but they do not depend on each other and can be applied in parallel:
vim_configured = Collection([
AptPresent('vim'),
FileCopy('~/.vimrc', 'vimrc'),
])
In this other example however, each fact depends on the previous one, so they are applied sequentially:
ipython_virtualenv = Sequence([
AptPresent('virtualenv'),
DirectoryPresent('~/.virtualenvs/'),
Virtualenv('~/.virtualenvs/venv-ipython'),
PipInstalled(['itpython'], '~/.virtualenvs/venv-ipython'),
])
Creating facts
The example below shows the definition of the fact to ensure that a file is
present on disk. The enquire
method returns whether the file is present,
and the enforce
method is called if the file is absent to create it by
running shell commands on the host.
from okonf.facts.abstract import Fact
class FilePresent(Fact):
"""Ensure that a file is present"""
def __init__(self, remote_path: str) -> None:
self.remote_path = remote_path
async def enquire(self, host):
command = "ls -d {}".format(self.remote_path)
return await host.check_output(command, check=False) != ''
async def enforce(self, host):
await host.check_output("touch {}".format(self.remote_path))
return True
License
Okonf is licensed under the Apache License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Okonf-0.2.2.tar.gz
.
File metadata
- Download URL: Okonf-0.2.2.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 449c8197028069e0fd68ca5dc9e097e5b7e4fe91da54a5ab7f1bd34c705ac778 |
|
MD5 | 3bb1b9ae31f5b4274ba4f09f4ba1734c |
|
BLAKE2b-256 | 044a84baf54b1620d3117da1f1175470d4877405a387b8308b4810c1dde20d1d |
File details
Details for the file Okonf-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: Okonf-0.2.2-py3-none-any.whl
- Upload date:
- Size: 22.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58ef2bce611bf3c20f5d488011b9d8ec4f74b4ab63c95d90e8c9e2c1606e8bd0 |
|
MD5 | f13e64979cdca2f53cad1656ec72f6ae |
|
BLAKE2b-256 | 3fecc87021e0061e33e36857ca34d81f6f7eea8202be6e6ff9f16fbe1a783635 |