Tool for managing Elasticsearch resources as code
Project description
Nemesis
Nemesis is a python library to manage Elasticsearch resources as code. Nemesis operates a lot more like Pulumi than terraform. Each resource that nemesis supports is an actual python object which can be used like any other python object.
Elasticsearch resources can be crafted as Python objects. Elasticsearch resources can be fetched from the Elasticsearch cluster and diffed against local versions. Deployments can happen if a remote resource doesn't exist. Deployments can happen if a local_resource is registered with force=True, to force updating of the resource even if it hasn't changed.
Creating new resources is not trivial at this point in time. It's difficult because, to create the resource you first need to define the dataclass and all the attributes on that class. Next you would need to define the Schema for that resource, then you would need to define all the CRUD method for that resource. There's no automated way to do this. But would be nice to create a code generator to scan the Elasticsearch repo and pull out the various resources and their types so they can be created in Nemesis.
Pull requests for new resources added to nemesis would be greatly appriciated!
Getting started.
Installation
First to get started you must install nemesis
:
pip install nemesis
Creating your first nemesis project
First create the directory you want to put your nemesis project into:
$ mkdir my_first_project
$ cd my_first_project
$ nemesis new
The nemesis.py file
After you run the nemesis new
command a newly created nemesis.py file will exist. This file has some example code in it to help you get started.
- instantiate the
Nemesis
object as the variablen
. - using the
nemesis.resources.elasticsearch.*
modules create your ES resources register
those resources with theNemesis
client.n.register(my_resource_name)
Help
Running the --help
flag will give you help on any command or subcommand.
> nemesis --help
Usage: nemesis [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...
Nemesis CLI
Options:
--help Show this message and exit.
Commands:
launch Deploy resources to Elasticsearch
new Create a new nemesis deployment
preview Preview the resources to deployed
Preview
Run nemesis preview
to see what will be deployed to Elasticsearch.
This will render a diff to tell you what's going to be created or changed.
Launch
Run nemesis launch
to deploy your changes.
This will actually ship your resources to Elasticsearch
Additional features
Pre/Post deploy hooks.
nemesis supports pre and post deploy hooks. This is useful in various situations:
- You are creating an ingest pipeline and you want to run some tests to ensure your pipeline works before the pipeline is deployed.
You can write a function to call
resource.simulate
on your pipeline resource. - You have a transform you want to "reset". You can define a "predeploy" function to "stop" the current transform, delete the current dest index, and then recreate the dest index. then define a "postdeploy" function which will start the transform
- Watchers can be "simulated" using the "execute" api. This unfortunatly only works on watchers that exist already, but you can deploy the watcher and then write a post-deploy test that will ensure your watcher works as expected.
- Your imagination is the limit on things you might want to do before and/or after something has been deployed
Diffing elasticsearch resources
Nemesis supports deep diffing of resources with a succinct mode and verbose mode.
Example of a "succinct" diff:
> nemesis launch -y
Hello Nemesis!
Preview resources to be deployed
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ Resource ┃ Name ┃ Action ┃ Diff ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ IndexTemplate │ index_template_billing_aggregate │ create │ + ['index_patterns'] │
│ │ │ │ + ['template'] │
│ │ │ │ + ['version'] │
├──────────────────┼──────────────────────────────────┼───────────┼──────────────────────┤
│ IngestPipeline │ total_cost │ create │ + ['id'] │
│ │ │ │ + ['processors'] │
│ │ │ │ + ['description'] │
│ │ │ │ + ['version'] │
├──────────────────┼──────────────────────────────────┼───────────┼──────────────────────┤
│ Transform │ total_cost_2021_12 │ create │ + ['source'] │
│ │ │ │ + ['dest'] │
│ │ │ │ + ['id'] │
│ │ │ │ + ['pivot'] │
│ │ │ │ + ['description'] │
│ │ │ │ + 'frequency'] │
├──────────────────┼──────────────────────────────────┼───────────┼──────────────────────┤
│ LogstashPipeline │ test_logstash_pipeline │ update │ ~ ['last_modified'] │
├──────────────────┼──────────────────────────────────┼───────────┼──────────────────────┤
│ Role │ test-role │ unchanged │ │
├──────────────────┼──────────────────────────────────┼───────────┼──────────────────────┤
│ RoleMapping │ test_role_mapping │ unchanged │ │
├──────────────────┼──────────────────────────────────┼───────────┼──────────────────────┤
│ Watch │ test-watch │ unchanged │ │
└──────────────────┴──────────────────────────────────┴───────────┴──────────────────────┘
Resources:
Creating: 3
Updating: 1
Unchanged: 3
And an example of a verbose diff:
> nemesis launch -v
Hello Nemesis!
────────────────────────────────────────────────────────────────────────────────────────────────────────
Preview IndexTemplate(index_template_billing_aggregate)
┏━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Field ┃ Value ┃
┡━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ ['index_patterns'] │ + [ │
│ │ "billing_aggregate_*" │
│ │ ] │
│ ['template'] │ + { │
│ │ "settings": { │
│ │ "index": { │
│ │ "number_of_shards": "1", │
│ │ "number_of_replicas": "1" │
│ │ } │
│ │ }, │
│ │ "mappings": { │
│ │ "_source": { │
│ │ "enabled": true │
│ │ }, │
│ │ "properties": { │
│ │ "@timestamp": { │
│ │ "type": "date" │
│ │ }, │
│ │ "@version": { │
│ │ "type": "text" │
│ │ }, │
│ │ "cloud_provider": { │
│ │ "type": "keyword" │
│ │ }, │
│ │ "sum_total": { │
│ │ "type": "float" │
│ │ }, │
│ │ "team_name": { │
│ │ "type": "keyword" │
│ │ } │
│ │ } │
│ │ } │
│ │ } │
│ ['version'] │ + 3 │
└─────────────────────┴─────────────────────────────────┘
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 nemesis-0.0.9.tar.gz
.
File metadata
- Download URL: nemesis-0.0.9.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b11dc93876aef618d28c79f418549b399f6e769c22c8c582365a8769b79bf972 |
|
MD5 | e350673e0d03dc86fb4f16942c72dde6 |
|
BLAKE2b-256 | 2df901676303b1c712f125ce1c98e069402a0d44ceb3671ba16ba00b4240e4c2 |
File details
Details for the file nemesis-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: nemesis-0.0.9-py3-none-any.whl
- Upload date:
- Size: 45.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94d28915e01f49f3797804f63ab33fa926d3e85f5b811b4b66de71d9f5be0e21 |
|
MD5 | 7ab3e4b72e0c35248391ae3fa90a6348 |
|
BLAKE2b-256 | 7f7eaf785ee3c74737b057333664861c916acc193c4fbead2b47ffb7be52abb7 |