From 7bbfd925f464c507c841757c7b3c5e1d9293475e Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 29 Apr 2020 13:11:44 +0200 Subject: [PATCH] Adds invalid appointment to tower_info Invalid appointments are those which tower signature is invalid --- watchtower-plugin/tower_info.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/watchtower-plugin/tower_info.py b/watchtower-plugin/tower_info.py index ee4499c..8aa6b7a 100644 --- a/watchtower-plugin/tower_info.py +++ b/watchtower-plugin/tower_info.py @@ -1,5 +1,13 @@ class TowerInfo: - def __init__(self, netaddr, available_slots, status="active", appointments=None, pending_appointments=None): + def __init__( + self, + netaddr, + available_slots, + status="reachable", + appointments=None, + pending_appointments=None, + invalid_appointments=None, + ): self.netaddr = netaddr self.available_slots = available_slots self.status = status @@ -14,6 +22,11 @@ class TowerInfo: else: self.pending_appointments = pending_appointments + if not invalid_appointments: + self.invalid_appointments = [] + else: + self.invalid_appointments = invalid_appointments + @classmethod def from_dict(cls, tower_data): netaddr = tower_data.get("netaddr") @@ -21,11 +34,15 @@ class TowerInfo: status = tower_data.get("status") appointments = tower_data.get("appointments") pending_appointments = tower_data.get("pending_appointments") + invalid_appointments = tower_data.get("invalid_appointments") - if any(v is None for v in [netaddr, available_slots, status, appointments, pending_appointments]): + if any( + v is None + for v in [netaddr, available_slots, status, appointments, pending_appointments, invalid_appointments] + ): raise ValueError("Wrong appointment data, some fields are missing") - return cls(netaddr, available_slots, status, appointments, pending_appointments) + return cls(netaddr, available_slots, status, appointments, pending_appointments, invalid_appointments) def to_dict(self): return self.__dict__ @@ -36,4 +53,5 @@ class TowerInfo: "status": self.status, "available_slots": self.available_slots, "pending_appointments": self.pending_appointments, + "invalid_appointments": self.invalid_appointments, }