From 089cb4d696097dfef840a8e0240dc4be6d038220 Mon Sep 17 00:00:00 2001 From: forest Date: Thu, 9 Dec 2021 12:53:29 -0600 Subject: [PATCH] trying to fix bugs in get_all_by_host_and_network --- capsulflask/spoke_model.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/capsulflask/spoke_model.py b/capsulflask/spoke_model.py index 8c896b9..0bb31f0 100644 --- a/capsulflask/spoke_model.py +++ b/capsulflask/spoke_model.py @@ -168,7 +168,7 @@ class ShellScriptSpoke(VirtualizationInterface): try: vms_with_macs = json.load(macs_json_file) except: - raise Exception(f"failed to parse the JSON file '{macs_json_filename}'") + current_app.logger.warn(f"failed to parse the JSON file '{macs_json_filename}'") for vm in vms_with_macs: for mac in vm['macs']: @@ -184,7 +184,7 @@ class ShellScriptSpoke(VirtualizationInterface): else: current_app.logger.info(f"get_all_by_host_and_network: '{vm['domain']}' not in vm_state_by_id, defaulting to 'shut off'") - vms_by_id[vm['domain']] = dict(macs=dict(), state=vm_state) + vms_by_id[vm['domain']] = dict(macs=dict(), state=vm_state, network=network['name']) vms_by_id[vm['domain']]['macs'][mac] = True @@ -194,7 +194,7 @@ class ShellScriptSpoke(VirtualizationInterface): try: statuses = json.load(status_json_file) except: - raise Exception(f"failed to parse the JSON file '{status_json_filename}'") + current_app.logger.warn(f"failed to parse the JSON file '{status_json_filename}'") for status in statuses: if status['mac-address'] in vm_id_by_mac: @@ -203,7 +203,11 @@ class ShellScriptSpoke(VirtualizationInterface): else: current_app.logger.info(f"get_all_by_host_and_network: {status['mac-address']} not in vm_id_by_mac") - networks[network['name']] = vms_by_id + networks = dict() + for vm in vms_by_id: + if vm['network'] not in networks: + networks[vm['network']] = [] + networks[vm['network']].append(vm) to_return = dict() to_return[current_app.config['SPOKE_HOST_ID']] = networks