A simple Python Bottle app that presents Consul nodes and services as RunDeck resource and option models.
THIS IS A WORK IN PROGRESS! Currently I'm only using it internally, and it has not been throughly tested.
- bottle
- python-consul
/resource
- Returns a Rundeck resource-json-v10 formatted resource model of Consul nodes and services./services
- Returns a simple json-formatted list of Consul services for use as a Rundeck option model provider. The following optional parameters are allowed (and multiple can be used together):tag
- return services that have a given tagtags
- return all services matching (comma-separated) list of tagsdc
- return services in a given datacenterstartswith
- return services that start with given stringcontains
- return services that contain the given stringendswith
- only return services that contain a given stringregex
- return services matching regex pattern (accepts URL-encoded string)
Optional projects can be configured (for example multiple consul clusters or environments):
/resource/<project>
/services/<project>
Run ./app.py
, or if using a configuration file (see below),
./app.py --config /path/to/config.json
. How to keep it running is up to you.
The configuration file is optional. If provided it should follow the format
indicated below. If not provided the app will listen on 0.0.0.0:8080
and
will attempt to connect to consul at 127.0.0.1:8500
.
host
- listen address for server (default:0.0.0.0
)port
- listen port for server (default:8080
)consul
- dictionary of the following Consul connection parameters:host
- consul host (default:127.0.0.1
)port
- consul host (default:8500
)token
- consul token (default:None
)scheme
- consul HTTP(S) connection scheme (default:http
)verify
- whether to verify TLS cert (default:True
)cert
- consul TLS certificate (default:None
)
datacenters
- only include certain datacenters in resourceservices
- only include certain services in resourceexclude
- return all services except for thesenode_attributes
- map of additional attributes to map to all nodes returned in the resource model (see below for examples)append_tags
- whether to append Consul tags to their respective service, or to associate them directly to the node (default isfalse
). For example, given a Consul node with servicemysql
& tagmaster
, ifappend_tags
is true the node will have an attribute ofmysql:master
... ormysql
andmaster
if false.
If datacenters
, services
, and exclude
are not provided, queries to
/resource
(or /resource/<project>
) will return all services in all datacenters.
Example (not using multiple "projects"):
{
"host": "0.0.0.0",
"port": 8080,
"consul": {
"host": "localhost",
"port": "8500",
"token": "optionalsecret"
},
"datacenters": ["dc1", "dc2"],
"services": ["service1", "service2"],
"exclude": ["excluded_service1"],
"node_attributes": {
"username": "ubuntu"
},
"append_tags": true
}
Example (multiple environments/clusters):
{
"host": "0.0.0.0",
"port": 8080,
"projects": {
"dev": {
"consul": {
"host": "consul-dev.example.net",
"token": "devsecret"
},
"node_attributes": {
"username": "ubuntu",
"environment": "dev"
}
},
"prod": {
"consul": {
"host": "consul-prod.example.net",
"token": "prodsecret"
},
"node_attributes": {
"username": "ubuntu",
"environment": "prod"
}
}
}
}