Move GnocchiServiceRequiresHandler to ops_sunbeam
Move GnocchiServiceRequiresHandler to ops_sunbeam library. Change-Id: I9412b3e65b203c59252ad680ecfa65f83ad187bd
This commit is contained in:
parent
199619e6c5
commit
d6619680e1
@ -36,19 +36,12 @@ from charms.ceilometer_k8s.v0.ceilometer_service import (
|
||||
CeilometerConfigRequestEvent,
|
||||
CeilometerServiceProvides,
|
||||
)
|
||||
from charms.gnocchi_k8s.v0.gnocchi_service import (
|
||||
GnocchiServiceRequires,
|
||||
)
|
||||
from ops.charm import (
|
||||
CharmBase,
|
||||
RelationEvent,
|
||||
)
|
||||
from ops.main import (
|
||||
main,
|
||||
)
|
||||
from ops.model import (
|
||||
BlockedStatus,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -56,72 +49,6 @@ CEILOMETER_CENTRAL_CONTAINER = "ceilometer-central"
|
||||
CEILOMETER_NOTIFICATION_CONTAINER = "ceilometer-notification"
|
||||
|
||||
|
||||
@sunbeam_tracing.trace_type
|
||||
class GnocchiServiceRequiresHandler(sunbeam_rhandlers.RelationHandler):
|
||||
"""Handle gnocchi service relation on the requires side."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
charm: CharmBase,
|
||||
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."""
|
||||
logger.debug("Setting up Gnocchi service event handler")
|
||||
svc = GnocchiServiceRequires(
|
||||
self.charm,
|
||||
self.relation_name,
|
||||
)
|
||||
self.framework.observe(
|
||||
svc.on.readiness_changed,
|
||||
self._on_gnocchi_service_readiness_changed,
|
||||
)
|
||||
self.framework.observe(
|
||||
svc.on.goneaway,
|
||||
self._on_gnocchi_service_goneaway,
|
||||
)
|
||||
return svc
|
||||
|
||||
def _on_gnocchi_service_readiness_changed(
|
||||
self, event: RelationEvent
|
||||
) -> None:
|
||||
"""Handle config_changed event."""
|
||||
logger.debug("Gnocchi service readiness changed event received")
|
||||
self.callback_f(event)
|
||||
|
||||
def _on_gnocchi_service_goneaway(self, event: RelationEvent) -> None:
|
||||
"""Handle gone_away event."""
|
||||
logger.debug("Gnocchi service gone away event received")
|
||||
self.callback_f(event)
|
||||
if self.mandatory:
|
||||
self.status.set(BlockedStatus("integration missing"))
|
||||
|
||||
@property
|
||||
def ready(self) -> bool:
|
||||
"""Whether handler is ready for use."""
|
||||
return self.interface.service_ready
|
||||
|
||||
|
||||
@sunbeam_tracing.trace_type
|
||||
class CeilometerServiceProvidesHandler(sunbeam_rhandlers.RelationHandler):
|
||||
"""Handler for ceilometer service relation."""
|
||||
@ -354,7 +281,7 @@ class CeilometerOperatorCharm(sunbeam_charm.OSBaseOperatorCharmK8S):
|
||||
)
|
||||
handlers.append(self.config_svc)
|
||||
if self.can_add_handler("gnocchi-db", handlers):
|
||||
self.gnocchi_svc = GnocchiServiceRequiresHandler(
|
||||
self.gnocchi_svc = sunbeam_rhandlers.GnocchiServiceRequiresHandler(
|
||||
self,
|
||||
"gnocchi-db",
|
||||
self.configure_charm,
|
||||
|
@ -50,6 +50,7 @@ if typing.TYPE_CHECKING:
|
||||
import charms.certificate_transfer_interface.v0.certificate_transfer as certificate_transfer
|
||||
import charms.cinder_ceph_k8s.v0.ceph_access as ceph_access
|
||||
import charms.data_platform_libs.v0.data_interfaces as data_interfaces
|
||||
import charms.gnocchi_k8s.v0.gnocchi_service as gnocchi_service
|
||||
import charms.keystone_k8s.v0.identity_credentials as identity_credentials
|
||||
import charms.keystone_k8s.v0.identity_resource as identity_resource
|
||||
import charms.keystone_k8s.v1.identity_service as identity_service
|
||||
@ -2377,3 +2378,75 @@ class TracingRequireHandler(RelationHandler):
|
||||
def ready(self) -> bool:
|
||||
"""Whether handler is ready for use."""
|
||||
return self.interface.is_ready()
|
||||
|
||||
|
||||
@sunbeam_tracing.trace_type
|
||||
class GnocchiServiceRequiresHandler(RelationHandler):
|
||||
"""Handle gnocchi service relation on the requires side."""
|
||||
|
||||
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
|
||||
|
||||
logger.debug("Setting up Gnocchi service event handler")
|
||||
svc = sunbeam_tracing.trace_type(gnocchi_svc.GnocchiServiceRequires)(
|
||||
self.charm,
|
||||
self.relation_name,
|
||||
)
|
||||
self.framework.observe(
|
||||
svc.on.readiness_changed,
|
||||
self._on_gnocchi_service_readiness_changed,
|
||||
)
|
||||
self.framework.observe(
|
||||
svc.on.goneaway,
|
||||
self._on_gnocchi_service_goneaway,
|
||||
)
|
||||
return svc
|
||||
|
||||
def _on_gnocchi_service_readiness_changed(
|
||||
self, event: ops.framework.EventBase
|
||||
) -> None:
|
||||
"""Handle config_changed event."""
|
||||
logger.debug("Gnocchi service readiness changed event received")
|
||||
self.callback_f(event)
|
||||
|
||||
def _on_gnocchi_service_goneaway(
|
||||
self, event: ops.framework.EventBase
|
||||
) -> None:
|
||||
"""Handle gone_away event."""
|
||||
logger.debug("Gnocchi service gone away event received")
|
||||
self.callback_f(event)
|
||||
if self.mandatory:
|
||||
self.status.set(BlockedStatus("integration missing"))
|
||||
|
||||
@property
|
||||
def ready(self) -> bool:
|
||||
"""Whether handler is ready for use."""
|
||||
return self.interface.service_ready
|
||||
|
Loading…
Reference in New Issue
Block a user