From 280bcfd584b87de4038ac07ef448ff48b6bae6de Mon Sep 17 00:00:00 2001 From: forest Date: Sat, 30 Jan 2021 02:10:22 -0600 Subject: [PATCH] =?UTF-8?q?check=20null=20on=20double=5Fcheck=5Fcapsul=5Fa?= =?UTF-8?q?ddress=20=F0=9F=98=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- capsulflask/console.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/capsulflask/console.py b/capsulflask/console.py index 302644e..ee36f98 100644 --- a/capsulflask/console.py +++ b/capsulflask/console.py @@ -40,6 +40,7 @@ def double_check_capsul_address(id, ipv4, get_ssh_host_keys): the virtualization model threw an error in double_check_capsul_address of {id}: {my_exec_info_message(sys.exc_info())}""" ) + return None return result @@ -57,7 +58,9 @@ def index(): # for now we are going to check the IP according to the virt model # on every request. this could be done by a background job and cached later on... for vm in vms: - vm["ipv4"] = double_check_capsul_address(vm["id"], vm["ipv4"], False).ipv4 + result = double_check_capsul_address(vm["id"], vm["ipv4"], False) + if result is not None: + vm["ipv4"] = result.ipv4 vms = list(map( lambda x: dict( @@ -109,10 +112,13 @@ def detail(id): else: needs_ssh_host_keys = "ssh_host_keys" not in vm or len(vm["ssh_host_keys"]) == 0 + vm_from_virt_model = double_check_capsul_address(vm["id"], vm["ipv4"], needs_ssh_host_keys) - vm["ipv4"] = vm_from_virt_model.ipv4 - if needs_ssh_host_keys: - vm["ssh_host_keys"] = vm_from_virt_model.ssh_host_keys + + if vm_from_virt_model is not None: + vm["ipv4"] = vm_from_virt_model.ipv4 + if needs_ssh_host_keys: + vm["ssh_host_keys"] = vm_from_virt_model.ssh_host_keys vm["created"] = vm['created'].strftime("%b %d %Y %H:%M") vm["ssh_authorized_keys"] = ", ".join(vm["ssh_authorized_keys"]) if len(vm["ssh_authorized_keys"]) > 0 else ""