Skip to main content

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.5.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file sborl-0.0.5.tar.gz.

File metadata

  • Download URL: sborl-0.0.5.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for sborl-0.0.5.tar.gz
Algorithm Hash digest
SHA256 fd3dce7de5a70274c0353009c6664e4a7b8d975df040af77a4039a452054f509
MD5 bb0fea029007f12a3d2f147bdeddd301
BLAKE2b-256 9aa793db0422a0d72e6dfa58c348c1ed6f983ab2d8cd21d0fbe3a1dfcfeb0126

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page