QVolution2019.2/AoM_Service/library/alert_config_list.py

37 lines
1.1 KiB
Python
Executable File

from alert_config import Alert_Config
class Alert_Config_List() :
def __init__(self, alert_configs=None) :
self.hash = {}
if alert_configs :
self.add(alert_configs)
def __getitem__(self, k) :
return self.hash[k]
def __len__(self) :
return len(self.hash)
def add(self, alert_config) :
if isinstance(alert_config, Alert_Config):
self.hash[alert_config.id] = alert_config
elif isinstance(alert_config, list) :
for a in alert_config :
self.add(a)
elif isinstance(alert_config, Alert_Config_List) :
for k in alert_config.hash :
self.add(alert_config.hash[k])
else :
raise Exception("unexpected type added to Alert_Config_List")
def compare(self, other) :
if not other :
other = Alert_Config_List()
self_keys = self.hash.keys()
other_keys = other.hash.keys()
added = other_keys - self_keys
removed = self_keys - other_keys
intersection = [i for i in self_keys if i in other_keys]
modified = [ i for i in intersection if self[i] != other[i] ]
return set(added), set(removed), set(modified)