[ops-sunbeam] Move handlers setup in post_init

Because handler setup was performed in __init__, this made using
attributes defined in constructor impossible to use in the setup
methods except by ensuring right order in object init. This, in
turn, added a lot of overhead.
Methods of an object should be able to use attributes defined in
the object constructor.

Move handler setup in __post_init__ hooks, called after object
initialiazation.
Remove constructors only calling super() constructor.
Re-order attribute definition to be called after super()
constructor.

Change-Id: Ieb9d23b1e4764e2c0e894c932b7584b5b7c38258
Signed-off-by: Guillaume Boutry <guillaume.boutry@canonical.com>
This commit is contained in:
Guillaume Boutry 2025-02-21 13:24:38 +01:00
parent 2cc6bdfad6
commit cb27776b43
No known key found for this signature in database
GPG Key ID: 0DD77DC1796E98CD
20 changed files with 55 additions and 455 deletions

View File

@ -60,9 +60,6 @@ class AODHWSGIPebbleHandler(sunbeam_chandlers.WSGIPebbleHandler):
class AODHEvaluatorPebbleHandler(sunbeam_chandlers.ServicePebbleHandler):
"""Pebble handler for AODH Evaluator."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def get_layer(self) -> dict:
"""AODH Evaluator service layer.

View File

@ -85,14 +85,14 @@ class VaultKvRequiresHandler(sunbeam_rhandlers.RelationHandler):
def __init__(
self,
charm: ops.CharmBase,
charm: sunbeam_charm.OSBaseOperatorCharm,
relation_name: str,
callback_f,
mount_suffix: str,
mandatory: bool = False,
):
self.mount_suffix = mount_suffix
super().__init__(charm, relation_name, callback_f, mandatory)
self.mount_suffix = mount_suffix
def setup_event_handler(self) -> ops.Object:
"""Configure event handlers for a vault-kv relation."""

View File

@ -21,7 +21,6 @@ This charm provide Ceilometer services as part of an OpenStack deployment
import logging
import uuid
from typing import (
Callable,
List,
)
@ -37,9 +36,6 @@ from charms.ceilometer_k8s.v0.ceilometer_service import (
CeilometerConfigRequestEvent,
CeilometerServiceProvides,
)
from ops.charm import (
CharmBase,
)
logger = logging.getLogger(__name__)
@ -51,14 +47,6 @@ CEILOMETER_NOTIFICATION_CONTAINER = "ceilometer-notification"
class CeilometerServiceProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for ceilometer service relation."""
def __init__(
self,
charm: CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for an Ceilometer service relation."""
logger.debug("Setting up Ceilometer service event handler")
@ -182,9 +170,6 @@ class CeilometerOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
db_sync_cmds = [["ceilometer-upgrade"]]
def __init__(self, framework: ops.framework):
super().__init__(framework)
def get_shared_meteringsecret(self):
"""Return the shared metering secret."""
return self.leader_get(self.shared_metering_secret_key)

View File

@ -23,7 +23,6 @@ of an OpenStack deployment
import logging
import uuid
from typing import (
Callable,
List,
Mapping,
Optional,
@ -127,14 +126,6 @@ class StorageBackendProvidesHandler(sunbeam_rhandlers.RelationHandler):
class CephAccessProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for identity service relation."""
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for an Identity service relation."""
logger.debug("Setting up Ceph Access event handler")

View File

@ -24,7 +24,6 @@ import json
import logging
import secrets
from typing import (
Callable,
Dict,
Iterable,
List,
@ -83,15 +82,6 @@ class BindRndcProvidesRelationHandler(sunbeam_rhandlers.RelationHandler):
interface: bind_rndc.BindRndcProvides
charm: "BindOperatorCharm"
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
mandatory: bool = True,
):
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.Object:
"""Setup event handler for the relation."""
interface = sunbeam_tracing.trace_type(bind_rndc.BindRndcProvides)(

View File

@ -178,14 +178,6 @@ class DesignatePebbleHandler(sunbeam_chandlers.WSGIPebbleHandler):
class DesignateServiceProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for designate service relation."""
def __init__(
self,
charm: ops.CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for an Ceilometer service relation."""
logger.debug("Setting up Ceilometer service event handler")
@ -218,15 +210,6 @@ class BindRndcRequiresRelationHandler(sunbeam_rhandlers.RelationHandler):
charm: "DesignateOperatorCharm"
interface: bind_rndc.BindRndcRequires
def __init__(
self,
charm: ops.CharmBase,
relation_name: str,
callback_f: Callable,
mandatory: bool = True,
):
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.Object:
"""Setup event handler for the relation."""
interface = sunbeam_tracing.trace_type(bind_rndc.BindRndcRequires)(

View File

@ -153,7 +153,6 @@ class GlanceStorageRelationHandler(sunbeam_rhandlers.CephClientHandler):
juju_storage_name: str = None,
) -> None:
"""Run constructor."""
self.juju_storage_name = juju_storage_name
super().__init__(
charm,
relation_name,
@ -162,6 +161,7 @@ class GlanceStorageRelationHandler(sunbeam_rhandlers.CephClientHandler):
app_name,
mandatory=True,
)
self.juju_storage_name = juju_storage_name
def set_status(self, status: compound_status.Status) -> None:
"""Override the base set_status.
@ -227,13 +227,7 @@ class GlanceStorageRelationHandler(sunbeam_rhandlers.CephClientHandler):
class GlanceConfigContext(sunbeam_ctxts.ConfigContext):
"""Glance configuration context."""
def __init__(
self,
charm: sunbeam_charm.OSBaseOperatorAPICharm,
namespace: str,
) -> None:
"""Initialise the context."""
super().__init__(charm, namespace)
charm: "GlanceOperatorCharm"
def context(self) -> dict:
"""Context used when rendering templates."""

View File

@ -20,7 +20,6 @@ This charm provide Gnocchi services as part of an OpenStack deployment
import logging
from typing import (
Callable,
List,
)
@ -37,7 +36,6 @@ from charms.gnocchi_k8s.v0.gnocchi_service import (
GnocchiServiceReadinessRequestEvent,
)
from ops.charm import (
CharmBase,
RelationEvent,
)
from ops.framework import (
@ -55,26 +53,6 @@ GNOCCHI_METRICD_CONTAINER = "gnocchi-metricd"
class GnocchiServiceProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for Gnocchi service relation on provider side."""
def __init__(
self,
charm: CharmBase,
relation_name: str,
callback_f: Callable,
):
"""Create a new gnocchi service handler.
Create a new GnocchiServiceProvidesHandler that updates service
readiness on the related units.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
"""
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for Gnocchi service relation."""
logger.debug("Setting up Gnocchi service event handler")

View File

@ -204,9 +204,9 @@ class HeatOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
db_sync_cmds = [["heat-manage", "db_sync"]]
def __init__(self, framework):
super().__init__(framework)
self.traefik_route_public = None
self.traefik_route_internal = None
super().__init__(framework)
self._state.set_default(identity_ops_ready=False)
self.framework.observe(
self.on.peers_relation_created, self._on_peer_relation_created

View File

@ -36,7 +36,6 @@ from pathlib import (
Path,
)
from typing import (
Callable,
Dict,
List,
)
@ -155,14 +154,6 @@ class KeystoneConfigAdapter(sunbeam_contexts.ConfigContext):
class IdentityServiceProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for identity service relation."""
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for an Identity service relation."""
logger.debug("Setting up Identity Service event handler")
@ -192,14 +183,6 @@ class IdentityServiceProvidesHandler(sunbeam_rhandlers.RelationHandler):
class DomainConfigHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for domain config relation."""
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for an Identity service relation."""
logger.debug("Setting up Identity Service event handler")
@ -235,14 +218,6 @@ class DomainConfigHandler(sunbeam_rhandlers.RelationHandler):
class IdentityCredentialsProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for identity credentials relation."""
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for a Identity Credentials relation."""
logger.debug("Setting up Identity Credentials event handler")
@ -272,14 +247,6 @@ class IdentityCredentialsProvidesHandler(sunbeam_rhandlers.RelationHandler):
class IdentityResourceProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for identity resource relation."""
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for an Identity resource relation."""
logger.debug("Setting up Identity Resource event handler")
@ -351,12 +318,10 @@ class KeystoneOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
SEND_CA_CERT_RELATION_NAME = "send-ca-cert"
def __init__(self, framework):
# NOTE(gboutry): super().__init__ will call self.bootstrapped() which tries to
# make use of the keystone_manager
super().__init__(framework)
self.keystone_manager = manager.KeystoneManager(
self, KEYSTONE_CONTAINER
)
super().__init__(framework)
self._state.set_default(admin_domain_name="admin_domain")
self._state.set_default(admin_domain_id=None)
self._state.set_default(default_domain_id=None)

View File

@ -24,7 +24,6 @@ Send domain configuration to the keystone charm.
import json
import logging
from typing import (
Callable,
List,
Mapping,
)
@ -62,14 +61,6 @@ class LDAPConfigContext(config_contexts.ConfigContext):
class DomainConfigProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for identity credentials relation."""
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for a domain config relation."""
logger.debug("Setting up domain config event handler")
@ -101,9 +92,6 @@ class KeystoneLDAPK8SCharm(sunbeam_charm.OSBaseOperatorCharm):
DOMAIN_CONFIG_RELATION_NAME = "domain-config"
def __init__(self, *args):
super().__init__(*args)
def get_relation_handlers(
self, handlers=None
) -> List[sunbeam_rhandlers.RelationHandler]:

View File

@ -21,9 +21,6 @@ import logging
from collections import (
OrderedDict,
)
from typing import (
Callable,
)
import ops.framework
import ops.model
@ -75,31 +72,6 @@ class ConsulEndpointsRequirerHandler(sunbeam_rhandlers.RelationHandler):
interface: "ConsulEndpointsRequirer"
def __init__(
self,
charm: "sunbeam_charm.OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new consul-cluster handler.
Create a new ConsulEndpointsRequirerHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for consul-cluster relation."""
logger.debug(f"Setting up {self.relation_name} event handler")

View File

@ -22,7 +22,6 @@ This charm provide Neutron services as part of an OpenStack deployment
import logging
import re
from typing import (
Callable,
List,
)
@ -51,32 +50,7 @@ logger = logging.getLogger(__name__)
class DesignateServiceRequiresHandler(sunbeam_rhandlers.RelationHandler):
"""Handle external-dns relation on the requires side."""
def __init__(
self,
charm: ops.charm.CharmBase,
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new external-dns handler.
Create a new DesignateServiceRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> None:
def setup_event_handler(self) -> ops.Object:
"""Configure event handlers for external-dns service relation."""
logger.debug("Setting up Designate service event handler")
svc = sunbeam_tracing.trace_type(

View File

@ -40,9 +40,6 @@ from charms.nova_k8s.v0.nova_service import (
NovaConfigRequestEvent,
NovaServiceProvides,
)
from ops.charm import (
CharmBase,
)
from ops.pebble import (
ExecError,
)
@ -265,8 +262,8 @@ class CloudComputeRequiresHandler(sunbeam_rhandlers.RelationHandler):
:param mandatory: flag to determine if relation handler is mandatory
:type mandatory: bool
"""
self.region = region
super().__init__(charm, relation_name, callback_f, mandatory)
self.region = region
def setup_event_handler(self):
"""Configure event handlers for the cloud-compute service relation."""
@ -303,14 +300,6 @@ class CloudComputeRequiresHandler(sunbeam_rhandlers.RelationHandler):
class NovaServiceProvidesHandler(sunbeam_rhandlers.RelationHandler):
"""Handler for nova service relation."""
def __init__(
self,
charm: CharmBase,
relation_name: str,
callback_f: Callable,
):
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for nova service relation."""
logger.debug("Setting up Nova service event handler")
@ -345,9 +334,9 @@ class NovaOperatorCharm(sunbeam_charm.OSBaseOperatorAPICharm):
shared_metadata_secret_key = "shared-metadata-secret"
def __init__(self, framework):
super().__init__(framework)
self.traefik_route_public = None
self.traefik_route_internal = None
super().__init__(framework)
self.framework.observe(
self.on.peers_relation_created, self._on_peer_relation_created
)

View File

@ -185,10 +185,6 @@ class OVNCentralOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
_state = StoredState()
mandatory_relations = {"peers"}
def __init__(self, framework):
"""Setup OVN central charm class."""
super().__init__(framework)
def get_pebble_handlers(self):
"""Pebble handlers for all OVN containers."""
pebble_handlers = [

View File

@ -73,7 +73,9 @@ from ops.model import (
logger = logging.getLogger(__name__)
class OSBaseOperatorCharm(ops.charm.CharmBase):
class OSBaseOperatorCharm(
ops.charm.CharmBase, metaclass=sunbeam_core.PostInitMeta
):
"""Base charms for OpenStack operators."""
_state = ops.framework.StoredState()
@ -111,15 +113,10 @@ class OSBaseOperatorCharm(ops.charm.CharmBase):
self.status = compound_status.Status("workload", priority=100)
self.status_pool = compound_status.StatusPool(self)
self.status_pool.add(self.status)
self.relation_handlers = self.get_relation_handlers()
self.bootstrap_status = compound_status.Status(
"bootstrap", priority=90
)
self.status_pool.add(self.bootstrap_status)
if not self.bootstrapped():
self.bootstrap_status.set(
MaintenanceStatus("Service not bootstrapped")
)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(self.on.secret_changed, self._on_secret_changed)
self.framework.observe(self.on.secret_rotate, self._on_secret_rotate)
@ -128,6 +125,14 @@ class OSBaseOperatorCharm(ops.charm.CharmBase):
self.on.collect_unit_status, self._on_collect_unit_status_event
)
def __post_init__(self):
"""Post init hook."""
self.relation_handlers = self.get_relation_handlers()
if not self.bootstrapped():
self.bootstrap_status.set(
MaintenanceStatus("Service not bootstrapped")
)
def can_add_handler(
self,
relation_name: str,
@ -604,9 +609,9 @@ class OSBaseOperatorCharm(ops.charm.CharmBase):
class OSBaseOperatorCharmK8S(OSBaseOperatorCharm):
"""Base charm class for k8s based charms."""
def __init__(self, framework: ops.framework.Framework) -> None:
"""Run constructor."""
super().__init__(framework)
def __post_init__(self):
"""Post init hook."""
super().__post_init__()
self.pebble_handlers = self.get_pebble_handlers()
def get_pebble_handlers(self) -> List[sunbeam_chandlers.PebbleHandler]:
@ -825,10 +830,6 @@ class OSBaseOperatorAPICharm(OSBaseOperatorCharmK8S):
wsgi_admin_script: str
wsgi_public_script: str
def __init__(self, framework: ops.framework.Framework) -> None:
"""Run constructor."""
super().__init__(framework)
@property
def service_endpoints(self) -> list[dict]:
"""List of endpoints for this service."""

View File

@ -53,7 +53,7 @@ ContainerDir = collections.namedtuple(
@sunbeam_tracing.trace_type
class PebbleHandler(ops.framework.Object):
class PebbleHandler(ops.framework.Object, metaclass=sunbeam_core.PostInitMeta):
"""Base handler for Pebble based containers."""
def __init__(
@ -74,7 +74,6 @@ class PebbleHandler(ops.framework.Object):
self.container_configs.extend(self.default_container_configs())
self.template_dir = template_dir
self.callback_f = callback_f
self.setup_pebble_handler()
self.status = compound_status.Status("container:" + container_name)
self.charm.status_pool.add(self.status)
@ -84,6 +83,10 @@ class PebbleHandler(ops.framework.Object):
)
self._files_changed: list[str] = []
def __post_init__(self) -> None:
"""Post init."""
self.setup_pebble_handler()
def setup_pebble_handler(self) -> None:
"""Configure handler for pebble ready event."""
prefix = self.container_name.replace("-", "_")

View File

@ -93,3 +93,13 @@ class OPSCharmContexts:
"""Iterate over the relations presented to the charm."""
for namespace in self.namespaces:
yield namespace, getattr(self, namespace)
class PostInitMeta(type):
"""Allows object to run post init methods."""
def __call__(cls, *args, **kw):
"""Call __post_init__ after __init__."""
instance = super().__call__(*args, **kw)
instance.__post_init__()
return instance

View File

@ -492,15 +492,9 @@ class OVSDBCMSProvidesHandler(
interface: "ovsdb.OVSDBCMSProvides"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
) -> None:
"""Run constructor."""
super().__init__(charm, relation_name, callback_f, mandatory)
def __post_init__(self):
"""Post init hook."""
super().__post_init__()
self._update_address_data()
def setup_event_handler(self) -> ops.framework.Object:

View File

@ -45,6 +45,7 @@ from ops.model import (
WaitingStatus,
)
from ops_sunbeam.core import (
PostInitMeta,
RelationDataMapping,
)
@ -78,7 +79,7 @@ REPLICATED = "replicated"
@sunbeam_tracing.trace_type
class RelationHandler(ops.framework.Object):
class RelationHandler(ops.framework.Object, metaclass=PostInitMeta):
"""Base handler class for relations.
A relation handler is used to manage a charms interaction with a relation
@ -109,10 +110,13 @@ class RelationHandler(ops.framework.Object):
self.charm = charm
self.relation_name = relation_name
self.callback_f = callback_f
self.interface = self.setup_event_handler()
self.mandatory = mandatory
self.status = compound_status.Status(self.relation_name)
self.charm.status_pool.add(self.status)
def __post_init__(self):
"""Run post init."""
self.interface = self.setup_event_handler()
self.set_status(self.status)
def set_status(self, status: compound_status.Status) -> None:
@ -192,9 +196,9 @@ class IngressHandler(RelationHandler):
mandatory: bool = False,
) -> None:
"""Run constructor."""
super().__init__(charm, relation_name, callback_f, mandatory)
self.default_ingress_port = default_ingress_port
self.service_name = service_name
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for an Ingress relation."""
@ -301,8 +305,8 @@ class DBHandler(RelationHandler):
) -> None:
"""Run constructor."""
# a database name as requested by the charm.
self.database_name = database
super().__init__(charm, relation_name, callback_f, mandatory)
self.database_name = database
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for a MySQL relation."""
@ -447,9 +451,9 @@ class RabbitMQHandler(RelationHandler):
mandatory: bool = False,
) -> None:
"""Run constructor."""
super().__init__(charm, relation_name, callback_f, mandatory)
self.username = username
self.vhost = vhost
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for an AMQP relation."""
@ -542,9 +546,9 @@ class IdentityServiceRequiresHandler(RelationHandler):
mandatory: bool = False,
) -> None:
"""Run constructor."""
super().__init__(charm, relation_name, callback_f, mandatory)
self.service_endpoints = service_endpoints
self.region = region
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for an Identity service relation."""
@ -711,9 +715,9 @@ class CephClientHandler(RelationHandler):
mandatory: bool = False,
) -> None:
"""Run constructor."""
super().__init__(charm, relation_name, callback_f, mandatory)
self.allow_ec_overwrites = allow_ec_overwrites
self.app_name = app_name
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for an ceph-client interface."""
@ -1000,10 +1004,10 @@ class TlsCertificatesHandler(RelationHandler):
mandatory: bool = False,
) -> None:
"""Run constructor."""
super().__init__(charm, relation_name, callback_f, mandatory)
self._private_keys: dict[str, str] = {}
self.sans_dns = sans_dns
self.sans_ips = sans_ips
super().__init__(charm, relation_name, callback_f, mandatory)
try:
peer_relation = self.model.get_relation("peers")
# TODO(gboutry): fix type ignore
@ -1320,28 +1324,6 @@ class IdentityCredentialsRequiresHandler(RelationHandler):
interface: "identity_credentials.IdentityCredentialsRequires"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
) -> None:
"""Create a new identity-credentials handler.
Create a new IdentityCredentialsRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for identity-credentials relation."""
import charms.keystone_k8s.v0.identity_credentials as identity_credentials
@ -1386,31 +1368,6 @@ class IdentityResourceRequiresHandler(RelationHandler):
interface: "identity_resource.IdentityResourceRequires"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new identity-ops handler.
Create a new IdentityResourceRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self):
"""Configure event handlers for an Identity resource relation."""
import charms.keystone_k8s.v0.identity_resource as ops_svc
@ -1465,31 +1422,6 @@ class CeilometerServiceRequiresHandler(RelationHandler):
interface: "ceilometer_service.CeilometerServiceRequires"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new ceilometer-service handler.
Create a new CeilometerServiceRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.Object:
"""Configure event handlers for Ceilometer service relation."""
import charms.ceilometer_k8s.v0.ceilometer_service as ceilometer_svc
@ -1540,28 +1472,6 @@ class CephAccessRequiresHandler(RelationHandler):
interface: "ceph_access.CephAccessRequires"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
) -> None:
"""Create a new ceph-access handler.
Create a new CephAccessRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for ceph-access relation."""
import charms.cinder_ceph_k8s.v0.ceph_access as ceph_access
@ -1653,8 +1563,8 @@ class UserIdentityResourceRequiresHandler(RelationHandler):
extra_ops: list[dict | Callable] | None = None,
extra_ops_process: ExtraOpsProcess | None = None,
):
self.username = name
super().__init__(charm, relation_name, callback_f, mandatory)
self.username = name
self.charm = charm
self.add_suffix = add_suffix
# add_suffix is used to add suffix to username to create unique user
@ -2060,31 +1970,6 @@ class CertificateTransferRequiresHandler(RelationHandler):
interface: "certificate_transfer.CertificateTransferRequires"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new certificate-transfer requires handler.
Create a new CertificateTransferRequiresHandler that receives the
certificates from the provider and updates certificates on all
the containers.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.Object:
"""Configure event handlers for tls relation."""
logger.debug("Setting up certificate transfer event handler")
@ -2223,31 +2108,6 @@ class NovaServiceRequiresHandler(RelationHandler):
interface: "nova_service.NovaServiceRequires"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new nova-service handler.
Create a new NovaServiceRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.Object:
"""Configure event handlers for Nova service relation."""
import charms.nova_k8s.v0.nova_service as nova_svc
@ -2356,10 +2216,10 @@ class TracingRequireHandler(RelationHandler):
configuring charm.
:type mandatory: bool
"""
super().__init__(charm, relation_name, lambda *args: None, mandatory)
if protocols is None:
protocols = ["otlp_http"]
self.protocols = protocols
super().__init__(charm, relation_name, lambda *args: None, mandatory)
def setup_event_handler(self) -> ops.Object:
"""Configure event handlers for tracing relation."""
@ -2393,31 +2253,6 @@ class GnocchiServiceRequiresHandler(RelationHandler):
interface: "gnocchi_service.GnocchiServiceRequires"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new gnocchi service handler.
Create a new GnocchiServiceRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for Gnocchi service relation."""
import charms.gnocchi_k8s.v0.gnocchi_service as gnocchi_svc
@ -2465,31 +2300,6 @@ class ServiceReadinessRequiresHandler(RelationHandler):
interface: "service_readiness.ServiceReadinessRequirer"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
mandatory: bool = False,
):
"""Create a new service-ready requirer handler.
Create a new ServiceReadinessRequiresHandler that handles initial
events from the relation and invokes the provided callbacks based on
the event raised.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
:param mandatory: If the relation is mandatory to proceed with
configuring charm
:type mandatory: bool
"""
super().__init__(charm, relation_name, callback_f, mandatory)
def setup_event_handler(self) -> ops.framework.Object:
"""Configure event handlers for service-ready relation."""
import charms.sunbeam_libs.v0.service_readiness as service_readiness
@ -2545,26 +2355,6 @@ class ServiceReadinessProviderHandler(RelationHandler):
interface: "service_readiness.ServiceReadinessProvider"
def __init__(
self,
charm: "OSBaseOperatorCharm",
relation_name: str,
callback_f: Callable,
):
"""Create a new service-readiness provider handler.
Create a new ServiceReadinessProvidesHandler that updates service
readiness on the related units.
:param charm: the Charm class the handler is for
:type charm: ops.charm.CharmBase
:param relation_name: the relation the handler is bound to
:type relation_name: str
:param callback_f: the function to call when the nodes are connected
:type callback_f: Callable
"""
super().__init__(charm, relation_name, callback_f)
def setup_event_handler(self):
"""Configure event handlers for service-readiness relation."""
import charms.sunbeam_libs.v0.service_readiness as service_readiness