Skip to content

Commit

Permalink
Publish for xmmp service discovery and event
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Nov 23, 2023
1 parent 7f7bcec commit 102c83c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions imageroot/actions/configure-module/85publish_srv_keys
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

#
# Copyright (C) 2023 Nethesis S.r.l.
# SPDX-License-Identifier: GPL-3.0-or-later
#

import json
import agent
import os

node_id = int(os.environ['NODE_ID'])
agent_id = os.environ['AGENT_ID']
module_uuid = os.environ['MODULE_UUID']
hostname = os.environ['EJABBERD_HOSTNAME']

with agent.redis_connect() as rdb:
node_address = rdb.hget(f'node/{node_id}/vpn', 'ip_address')

# Create srv records in Redis for service discovery
with agent.redis_connect(privileged=True) as prdb:
trx = prdb.pipeline()

kxmmp = agent_id + "/srv/tcp/xmmp"
trx.delete(kxmmp).hset(kxmmp, mapping={
"port": "5222",
"host": node_address,
"node": str(node_id),
"module_uuid": module_uuid,
"ejabberd_hostname": hostname
})

# Publish change event
trx.publish(agent_id + "/event/ejabberd-settings-changed", json.dumps({
"reason": os.getenv("AGENT_TASK_ACTION", "unknown"),
"module_id": os.environ['MODULE_ID'],
"node_id": node_id,
"module_uuid": module_uuid,
}))

trx.execute()

0 comments on commit 102c83c

Please sign in to comment.