A Python client for docker events API.
Project description
objective
have a CLI to start a process which runs abitrary code on docker events
be able to provide a way to change behavior of and provide data to event subscribers
load subscribers by module or file
events may be extended
install
# pip install docker-events
usage
# docker-events --help
Usage: docker-events [OPTIONS]
Options:
-s, --sock TEXT the docker socket
-c, --config FILENAME a config yaml
-m, --module TEXT a python module to load
-f, --file PATH a python file to load
-l, --log PATH logging config
--debug enable debug log level
--help Show this message and exit.
# create a config for skydns
# cat > skydns-config.yaml << EOF
---
skydns:
domain: foo
skydns.containers:
redis:
domain: myredis.{domain}
EOF
# run skydns subscriber on start events
# docker-events -c skydns-config.yaml -m docker_events.tools.skydns
API
There are some predefined events: start, stop, create, die, destroy, pull
You may write your own events like this:
@event
def pull(client, event_data):
return event_data.get('status') == 'pull'
Events may be extended by other events:
@docker_events.pull.extend
def pull_something(client, event_data):
return event_data['id'].startswith("foobar")
For example if you want to use skydns, you may want to put the following code into a file or module and load it via -m or -f option:
"""
setup skydns records for containers
"""
import docker_events
import etcd
import simplejson as json
etcd_client = etcd.Client()
@docker_events.start.subscribe
def set_skydns_record(client, docker_event, config):
# get ip of container
container = client.inspect_container(docker_event['id'])
container_name = container['Name'].strip("/")
container_ip = container['NetworkSettings']['IPAddress']
skydns_config = config.get('skydns', {})
skydns_containers = config.get('skydns.containers', {
'domain': 'docker.local'
})
# find domain name for this container
if skydns_config and container_name in skydns_containers:
# use template
domain = skydns_containers[container_name].get('domain').format(**skydns_config)
else:
# join container_name with domain
domain = '.'.join((container_name, skydns_config.get('domain')))
domain_path = '/'.join(reversed(domain.split('.')))
etcd_client.write('/skydns/local/skydns/{}'.format(domain_path), json.dumps({
'host': container_ip
}))
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 docker-events-0.0.6.tar.gz
.
File metadata
- Download URL: docker-events-0.0.6.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f7b9ee56ccf4d635445102a3f19c7e40dd5f5c7baea134c11f75a5de5c76194 |
|
MD5 | f00f698c86b94cf02b8a8510292081a4 |
|
BLAKE2b-256 | 56a21dd8f84fada6a02a28acbe8aab2b07a6edf4861c8d2c5ac679781f937374 |
Provenance
File details
Details for the file docker_events-0.0.6-py2.py3-none-any.whl
.
File metadata
- Download URL: docker_events-0.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8508624671e870bf8e0795cca469fcdafe2f6a0c83edb051009b0433ee6684f2 |
|
MD5 | 4b111063002a5ed0f8609747ea9fc655 |
|
BLAKE2b-256 | d2b85abb4dc3869458131e1f0b9dddbd4b5ff56c8e0f94879e4c53d7ae7ffcf8 |