Add daemon PostgreSQL notify action
This commit is contained in:
@@ -380,3 +380,58 @@ def monitor(config, runtime_state):
|
||||
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
NOTIFY_FIELDS = (
|
||||
"type",
|
||||
"operation",
|
||||
"promote_uname",
|
||||
"demote_uname",
|
||||
"promoted_uname",
|
||||
"unpromoted_uname",
|
||||
)
|
||||
|
||||
|
||||
def _notify_value(parameters, field):
|
||||
value = parameters.get(field, "")
|
||||
|
||||
if not isinstance(value, str):
|
||||
raise ValueError(
|
||||
f"notify field {field} must be a string"
|
||||
)
|
||||
|
||||
if any(char in value for char in ("\n", "\r", "\x00")):
|
||||
raise ValueError(
|
||||
f"notify field {field} contains invalid characters"
|
||||
)
|
||||
|
||||
return value.strip()
|
||||
|
||||
|
||||
def notify(config, runtime_state, request_parameters):
|
||||
"""
|
||||
Record Pacemaker notification metadata in daemon runtime state.
|
||||
|
||||
The daemon remains the local authority for this resource instance.
|
||||
Node-target interpretation is deliberately deferred until the state
|
||||
persistence and demotion action are migrated together.
|
||||
"""
|
||||
if not isinstance(request_parameters, dict):
|
||||
raise ValueError(
|
||||
"notify parameters must be a JSON object"
|
||||
)
|
||||
|
||||
state = {
|
||||
field: _notify_value(request_parameters, field)
|
||||
for field in NOTIFY_FIELDS
|
||||
}
|
||||
|
||||
state["received_at"] = time.time()
|
||||
|
||||
postgresql_state = _postgres_runtime_state(runtime_state)
|
||||
postgresql_state["notification"] = state
|
||||
|
||||
return {
|
||||
"ocf_rc": OCF_SUCCESS,
|
||||
"state": dict(state),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user