|
| 1 | +# API Reference |
| 2 | + |
| 3 | +## Table of Contents |
| 4 | + |
| 5 | + * [`LBProvider` Class](#lbprovider-class) |
| 6 | + * [`LBConsumers` Class](#lbconsumers-class) |
| 7 | + * [`Request` Objects](#request-objects) |
| 8 | + * [`HealthCheck` Objects](#healthcheck-objects) |
| 9 | + * [`Response` Objects](#response-objects) |
| 10 | + |
| 11 | +----------------------------------------- |
| 12 | + |
| 13 | +## `LBProvider` Class |
| 14 | + |
| 15 | +This is the main API class for requesting load balancers from a provider charm. |
| 16 | +When instantiated, it should be passed a charm instance and a relation name. |
| 17 | + |
| 18 | +### Events |
| 19 | + |
| 20 | + * `available` Emitted once the provider is available to take requests |
| 21 | + * `responses_changed` Emitted whenever one or more responses have been received or updated |
| 22 | + |
| 23 | +### Methods |
| 24 | + |
| 25 | + * `get_request(name)` Get or create a request with the given name |
| 26 | + * `send_request(request)` Send the completed request to the provider |
| 27 | + * `get_response(name)` Get the response to a specific request (equivalent to `get_request(name).response`) |
| 28 | + * `ack_response(response)` Acknowledge a response so that it is no longer considered new or changed |
| 29 | + |
| 30 | +### Properties |
| 31 | + |
| 32 | + * `is_available` Whether the provider is available to take requests |
| 33 | + * `is_changed` Whether there are any new or changed responses which have not been acknowledged |
| 34 | + * `all_responses` A list of all received responses, even if they have not changed |
| 35 | + * `new_responses` A list of all responses which are new or have changed and not been acknowledged |
| 36 | + |
| 37 | +### Flags |
| 38 | + |
| 39 | +For charms using the older charms.reactive framework, the following flags will |
| 40 | +be automatically managed: |
| 41 | + |
| 42 | + * `endpoint.{relation_name}.available` Set or cleared based on `is_available` |
| 43 | + * `endpoint.{relation_name}.responses_changed` Set or cleared based on `is_changed` |
| 44 | + |
| 45 | + |
| 46 | +## `LBConsumers` Class |
| 47 | + |
| 48 | +This is the main API class for providing load balancers to consumer charms. |
| 49 | +When instantiated, it should be passed a charm instance and a relation name. |
| 50 | + |
| 51 | +### Events |
| 52 | + |
| 53 | + * `requests_changed` Emitted whenever one or more requests have been received or updated |
| 54 | + |
| 55 | +### Methods |
| 56 | + |
| 57 | + * `send_response(request)` Send the completed `Response` attached to the given `Request` |
| 58 | + |
| 59 | +### Properties |
| 60 | + |
| 61 | + * `is_changed` Whether there are any new or changed requests which have not been responded to |
| 62 | + * `all_requests` A list of all received requests, even if they have not changed |
| 63 | + * `new_requests` A list of all requests which are new or have changed and not been responded to |
| 64 | + |
| 65 | +### Flags |
| 66 | + |
| 67 | +For charms using the older charms.reactive framework, the following flags will |
| 68 | +be automatically managed: |
| 69 | + |
| 70 | + * `endpoint.{relation_name}.requests_changed` Set or cleared based on `is_changed` |
| 71 | + |
| 72 | + |
| 73 | +## `Request` Objects |
| 74 | + |
| 75 | +Represents a request for a load balancer. |
| 76 | + |
| 77 | +Acquired from `LBProvider.get_request(name)`, `LBConsumers.all_requests`, or `LBConsumers.new_requests`. |
| 78 | + |
| 79 | +### Properties |
| 80 | + |
| 81 | + * `name` Name of the request (`str`, read-only) |
| 82 | + * `response` `Reponse` to this request (will always exist, but may be "empty"; see below) |
| 83 | + * `hash` An MD5 hash of the data for the request (`str`, read-only) |
| 84 | + |
| 85 | +### Fields |
| 86 | + |
| 87 | + * `traffic_type` Type of traffic to route (`str`, required) |
| 88 | + * `backends` List of backend addresses (`str`s, default: every units' `ingress-address`) |
| 89 | + * `backend_ports` List of ports or `range`s to route (`int`s or `range(int, int)`, required) |
| 90 | + * `algorithm` List of traffic distribution algorithms, in order of preference (`str`s, optional) |
| 91 | + * `sticky` Whether traffic "sticks" to a given backend (`bool`, default: `False`) |
| 92 | + * `health_checks` List of `HealthCheck` objects (see below, optional) |
| 93 | + * `public` Whether the address should be public (`bool`, default: `True`) |
| 94 | + * `tls_termination` Whether to enable TLS termination (`bool`, default: `False`) |
| 95 | + * `tls_cert` If TLS termination is enabled, a manually provided cert (`str`, optional) |
| 96 | + * `tls_key` If TLS termination is enabled, a manually provided key (`str`, optional) |
| 97 | + * `ingress_address` A manually provided ingress address (optional, may not be supported) |
| 98 | + * `ingress_ports` A list of ingress ports or `range`s (`int`s or `range(int, int)`; default: `backend_ports`) |
| 99 | + |
| 100 | +### Methods |
| 101 | + |
| 102 | + * `add_health_check(**fields)` Create a `HealthCheck` object (see below) with the given fields and add it to the list. |
| 103 | + |
| 104 | + |
| 105 | +## `HealthCheck` Objects |
| 106 | + |
| 107 | +Represents a health check endpoint to determine if a backend is functional. |
| 108 | + |
| 109 | +Acquired from `Request.add_health_check()`, or `Request.health_checks`. |
| 110 | + |
| 111 | +### Fields |
| 112 | + |
| 113 | + * `traffic_type` Type of traffic to use to make the check (e.g., "https", "udp", etc.) (`str`, required) |
| 114 | + * `port` Port to check on (`int`, required) |
| 115 | + * `path` Path on the backend to check (e.g., for "https" or "http" types) (`str`, optional) |
| 116 | + * `interval` How many seconds to wait between checks (`int`, default: 30) |
| 117 | + * `retries` How many failed attempts before considering a backend down (`int`, default: 3) |
| 118 | + |
| 119 | + |
| 120 | +## `Response` Objects |
| 121 | + |
| 122 | +Represents a response to a load balancer request. |
| 123 | + |
| 124 | +Acquired from `Request.response`. A `Request` object will always have a |
| 125 | +`response` attribute, but the response might be "empty" if it has not been |
| 126 | +filled in with valid data, in which case `bool(response)` will be `False`. |
| 127 | + |
| 128 | +### Properties |
| 129 | + |
| 130 | + * `name` Name of the request (`str`, read-only) |
| 131 | + * `hash` An MD5 hash of the data for the request (read-only) |
| 132 | + |
| 133 | +### Fields |
| 134 | + |
| 135 | + * `success` Whether the request was successful (`bool`, required) |
| 136 | + * `message` If not successful, an indication as to why (`str`, required if `success` is `False`) |
| 137 | + * `address` The address of the LB (`str`, required if `success` is `True`) |
| 138 | + * `request_hash` The hash of the `Request` when this `Response` was sent (`str`, set automatically) |
0 commit comments