def otherDevice(current): return "10.10.20.51" if current == "10.10.20.52" else "10.10.20.52" moved1 = False installedOn1 = False inStarting = 2 while True: _, alerts = fd.get_alerts() migrated2 = False for alert in alerts["data"]: if "APP_HEALTH" == alert["type"]: # Device issues if alert["appName"] == "dep1" and not moved1: print("migrating dep1") fd.stop_app("dep1") fd.uninstall_app("dep1", alert["ipAddress"]) code, _ = fd.install_app("dep1", ["10.10.20.53"]) while code == 400: code, _ = fd.install_app("dep1", ["10.10.20.53"]) fd.start_app("dep1") moved1 = True if not installedOn1: print("INSTALLING 1") installedOn1 = True fd.stop_app("dep2") code, _ = fd.install_app("dep2", ["10.10.20.51"]) count = 0 while code == 400: print("FAILED to migrate to","10.10.20.51", count) count+=1
def otherDevice(current): return "10.10.20.51" if current == "10.10.20.52" else "10.10.20.52" moved1 = False while True: _, alerts = fd.get_alerts() migrated2 = False for alert in alerts["data"]: if "APP_HEALTH" == alert["type"]: # Device issues if alert["appName"] == "dep1" and not moved1: print("migrating dep1") fd.stop_app("dep1") fd.uninstall_app("dep1", alert["ipAddress"]) code, _ = fd.install_app("dep1", ["10.10.20.53"]) while code == 400: code, _ = fd.install_app("dep1", ["10.10.20.53"]) fd.start_app("dep1") moved1 = True elif alert["appName"] == "dep2": if migrated2 == True: continue migrated2 = True print("dep2", alert["ipAddress"], "->", otherDevice(alert["ipAddress"])) fd.stop_app("dep2") code, _ = fd.uninstall_app("dep2", alert["ipAddress"]) code, _ = fd.install_app("dep2", [otherDevice(alert["ipAddress"])])