plugin - endpoint -> netaddr in TowerInfo and adds get_summary

This commit is contained in:
Sergi Delgado Segura
2020-04-23 12:44:25 +02:00
parent 5f33d63cb6
commit d86112d86e

View File

@@ -1,6 +1,6 @@
class TowerInfo: class TowerInfo:
def __init__(self, endpoint, available_slots, appointments=None): def __init__(self, netaddr, available_slots, appointments=None):
self.endpoint = endpoint self.netaddr = netaddr
self.available_slots = available_slots self.available_slots = available_slots
if not appointments: if not appointments:
@@ -10,14 +10,17 @@ class TowerInfo:
@classmethod @classmethod
def from_dict(cls, tower_data): def from_dict(cls, tower_data):
endpoint = tower_data.get("endpoint") netaddr = tower_data.get("netaddr")
available_slots = tower_data.get("available_slots") available_slots = tower_data.get("available_slots")
appointments = tower_data.get("appointments") appointments = tower_data.get("appointments")
if any(v is None for v in [endpoint, available_slots, appointments]): if any(v is None for v in [netaddr, available_slots, appointments]):
raise ValueError("Wrong appointment data, some fields are missing") raise ValueError("Wrong appointment data, some fields are missing")
return cls(endpoint, available_slots, appointments) return cls(netaddr, available_slots, appointments)
def to_dict(self): def to_dict(self):
return self.__dict__ return self.__dict__
def get_summary(self):
return {"netaddr": self.netaddr, "available_slots": self.available_slots}