From 43f7559c5123eb252c8af6ad5bca6ba3cc98816c Mon Sep 17 00:00:00 2001 From: Logan Lipke Date: Mon, 6 Jul 2020 13:45:25 -0700 Subject: [PATCH] Added wait_for_ip method to Realm, waits for all eth and sta ports to get ip --- py-json/realm.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/py-json/realm.py b/py-json/realm.py index 3b668816..a3a83658 100755 --- a/py-json/realm.py +++ b/py-json/realm.py @@ -201,6 +201,40 @@ class Realm(LFCliBase): return info return [1, int(info[0]), info[1]] + def wait_for_ip(self): + num_ports = 0 + num_ips = 0 + print("Waiting for ips...") + response = super().json_get("/port/list?fields=alias,ip,port+type") + if (response is None) or ("interfaces" not in response): + print("station_list: incomplete response:") + pprint(response) + exit(1) + + for x in range(len(response['interfaces'])): + for k, v in response['interfaces'][x].items(): + if "wlan" not in v['alias'] and v['port type'] == "WIFI-STA" or v['port type'] == "Ethernet": + num_ports += 1 + + while num_ips != num_ports: + num_ips = 0 + response = super().json_get("/port/list?fields=alias,ip,port+type") + if (response is None) or ("interfaces" not in response): + print("station_list: incomplete response:") + pprint(response) + exit(1) + + for x in range(len(response['interfaces'])): + for k, v in response['interfaces'][x].items(): + if "wlan" not in v['alias'] and v['port type'] == "WIFI-STA" or v['port type'] == "Ethernet": + if v['ip'] != '0.0.0.0': + num_ips += 1 + time.sleep(1) + + + + + def parse_time(self, time_string): if isinstance(time_string, str): pattern = re.compile("^(\d+)([dhms]$)")