Add required relations
This commit is contained in:
parent
518b4fbdc4
commit
ac8f8762e0
|
@ -10,6 +10,7 @@ from charmhelpers.fetch import (
|
||||||
)
|
)
|
||||||
from ops.model import (
|
from ops.model import (
|
||||||
ActiveStatus,
|
ActiveStatus,
|
||||||
|
BlockedStatus,
|
||||||
MaintenanceStatus,
|
MaintenanceStatus,
|
||||||
WaitingStatus,
|
WaitingStatus,
|
||||||
)
|
)
|
||||||
|
@ -24,6 +25,8 @@ class OSBaseCharm(CharmBase):
|
||||||
|
|
||||||
RESTART_MAP = {}
|
RESTART_MAP = {}
|
||||||
|
|
||||||
|
REQUIRED_RELATIONS = []
|
||||||
|
|
||||||
def __init__(self, framework, key):
|
def __init__(self, framework, key):
|
||||||
super().__init__(framework, key)
|
super().__init__(framework, key)
|
||||||
self.state.set_default(is_started=False)
|
self.state.set_default(is_started=False)
|
||||||
|
@ -47,6 +50,14 @@ class OSBaseCharm(CharmBase):
|
||||||
if self.state.is_paused:
|
if self.state.is_paused:
|
||||||
self.model.unit.status = MaintenanceStatus(
|
self.model.unit.status = MaintenanceStatus(
|
||||||
"Paused. Use 'resume' action to resume normal service.")
|
"Paused. Use 'resume' action to resume normal service.")
|
||||||
|
missing_relations = []
|
||||||
|
for relation in self.REQUIRED_RELATIONS:
|
||||||
|
if not self.framework.model.get_relation(relation):
|
||||||
|
missing_relations.append(relation)
|
||||||
|
if missing_relations:
|
||||||
|
self.model.unit.status = BlockedStatus(
|
||||||
|
'Missing relations: {}'.format(', '.join(missing_relations)))
|
||||||
|
return
|
||||||
if self.state.is_started:
|
if self.state.is_started:
|
||||||
self.model.unit.status = ActiveStatus('Unit is ready')
|
self.model.unit.status = ActiveStatus('Unit is ready')
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue