Schema-based Operator Relation Libraries
Project description
sborl - Schema-based Operator Relation Libraries
This library provides a base for creating relation endpoint libraries for use with charmed operators and Juju. It tries to make creating Pythonic implementations of a relation interface protocol straightforward and approachable, while encouraging good patterns such as using schema-based interface protocol validation, providing helpers for testing charms using your library, and surfacing problems with relations in a clean way.
Example
An example endpoint class and usage might look like:
class RandomURLRequirer(sborl.relation.EndpointWrapper):
INTERFACE = "random-url"
ROLE = "requires"
SCHEMA = Path(__file__) / "schema.yaml"
LIMIT = 1
@property
def url(self):
if not self.is_ready():
return None
relation = self.relations[0]
return self.unwrap(relation)[relation.app]["url"]
class MyCharm(ops.charm.CharmBase):
def __init__(self, *args):
super().__init__(*args)
self.random_url = RandomURLRequirer(charm=self, endpoint="random-url-provider")
self.framework.observe(self.random_url.on.ready, self._log_url)
def _log_url(self, event):
log.info(f"Got random URL: {self.random_url.url}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sborl-0.0.7.tar.gz
(7.9 kB
view details)
File details
Details for the file sborl-0.0.7.tar.gz
.
File metadata
- Download URL: sborl-0.0.7.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f880c79bee524591d722526b2d6a4c52c4e76823b7d77f6238f43a566bc5a954 |
|
MD5 | f0e1d0f75eb5341eb36b03e4f7a5ad05 |
|
BLAKE2b-256 | 5104596b2fe0d2ffe1cdc0c928f1a43e01ec1fc06b8f2cab491f322bc6588b37 |