3
This interface layer implements the basic form of the `http` interface protocol,
4
which is used for things such as reverse-proxies, load-balanced servers, REST
5
service discovery, et cetera.
11
By providing the `http` interface, your charm is providing an HTTP server that
12
can be load-balanced, reverse-proxied, used as a REST endpoint, etc.
14
Your charm need only provide the port on which it is serving its content, as
15
soon as the `{relation_name}.available` state is set:
18
@when('website.available')
19
def configure_website(website):
20
website.configure(port=hookenv.config('port'))
25
By requiring the `http` interface, your charm is consuming one or more HTTP
26
servers, as a REST endpoint, to load-balance a set of servers, etc.
28
Your charm should respond to the `{relation_name}.available` state, which
29
indicates that there is at least one HTTP server connected.
31
The `services()` method returns a list of available HTTP services and their
32
associated hosts and ports.
34
The return value is a list of dicts of the following form:
39
'service_name': name_of_service,
42
'hostname': address_of_host,
43
'port': port_for_host,
52
A trivial example of handling this interface would be:
55
from charms.reactive.helpers import data_changed
57
@when('reverseproxy.available')
58
def update_reverse_proxy_config(reverseproxy):
59
services = reverseproxy.services()
60
if not data_changed('reverseproxy.services', services):
62
for service in services:
63
for host in service['hosts']:
64
hookenv.log('{} has a unit {}:{}'.format(
65
services['service_name'],