Skip to content

Commit

Permalink
feat(migration): update module listing to use ns8-action command
Browse files Browse the repository at this point in the history
  • Loading branch information
stephdl committed Dec 18, 2024
1 parent 7bfe94e commit f587e61
Showing 1 changed file with 18 additions and 25 deletions.
43 changes: 18 additions & 25 deletions api/migration/read
Original file line number Diff line number Diff line change
Expand Up @@ -241,41 +241,34 @@ def list_apps():
apps.append(get_account_provider_info())
return apps

# Function to check if 'mail' is installed on a given node
def is_mail_installed_on_node(module_data, node_id):
for module in module_data:
if module.get("id") == "mail":
for destination in module.get("install_destinations", []):
if destination["node_id"] == node_id and destination["instances"] > 0:
return True
return False

# Function to check if 'ejabberd' is installed on a given node
def is_ejabberd_installed_on_node(module_data, node_id):
for module in module_data:
if module.get("id") == "ejabberd":
for destination in module.get("install_destinations", []):
if destination["node_id"] == node_id and destination["instances"] > 0:
return True
return False

def get_cluster_status():
bash_command = "/usr/sbin/ns8-action cluster get-cluster-status null"
process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
output, error = process.communicate()

output = json.loads(output.decode('utf-8'))

with open("/var/lib/nethserver/nethserver-ns8-migration/list-modules.json", "r") as file:
module_data = json.load(file)
# list all modules
command = ["/usr/sbin/ns8-action", "cluster", "list-modules", "null"]
process = subprocess.Popen(command, stdout=subprocess.PIPE)
modules_output, error = process.communicate()
modules = json.loads(modules_output)

# iterate over all nodes and check if mail and ejabberd are installed
for node in output["data"]["output"]["nodes"]:
node_id = node["id"]
mail_installed = is_mail_installed_on_node(module_data, node_id)
ejabberd_installed = is_ejabberd_installed_on_node(module_data, node_id)
node["mail_installed"] = mail_installed
node["ejabberd_installed"] = ejabberd_installed

node["mail_installed"] = False
node["ejabberd_installed"] = False
for module in modules['data']['output']:
if module.get("id") == "mail":
for destination in module.get("install_destinations", []):
if destination["node_id"] == node_id and destination["instances"] > 0:
node["mail_installed"] = True
if module.get("id") == "ejabberd":
for destination in module.get("install_destinations", []):
if destination["node_id"] == node_id and destination["instances"] > 0:
node["ejabberd_installed"] = True

return simplejson.loads(json.dumps(output))

def check_user_domains():
Expand Down

0 comments on commit f587e61

Please sign in to comment.