From 71ccd2a33ee2710c9c56e533e675223a8a8bbaec Mon Sep 17 00:00:00 2001 From: Antonio Francisco Date: Fri, 25 Jun 2021 15:37:05 -0300 Subject: [PATCH] Load all EVCs on startup Fixes #19 --- main.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index 9dbb856b..e5445d2c 100644 --- a/main.py +++ b/main.py @@ -54,6 +54,7 @@ def setup(self): self._lock = Lock() self.execute_as_loop(settings.DEPLOY_EVCS_INTERVAL) + self.load_all_evcs() def execute(self): """Execute once when the napp is running.""" @@ -535,19 +536,32 @@ def load_evcs(self, event): for circuit_id in self._circuits_by_interface.get(interface_id, []): if circuit_id in circuits and circuit_id not in self.circuits: - try: - evc = self._evc_from_dict(circuits[circuit_id]) - except ValueError as exception: - log.error( - f'Could not load EVC {circuit_id} ' - f'because {exception}') - continue - - evc.deactivate() - evc.current_path = Path([]) - evc.sync() - self.circuits.setdefault(circuit_id, evc) - self.sched.add(evc) + self._load_evc(circuits[circuit_id]) + + def load_all_evcs(self): + """Try to load all EVCs on startup.""" + for circuit_id, circuit in self.storehouse.get_data().items(): + if circuit_id not in self.circuits: + self._load_evc(circuit) + + def _load_evc(self, circuit_dict): + """Load one EVC from storehouse to memory.""" + try: + evc = self._evc_from_dict(circuit_dict) + except ValueError as exception: + log.error( + f'Could not load EVC {circuit_dict["id"]} ' + f'because {exception}') + return None + + if evc.archived: + return None + evc.deactivate() + evc.current_path = Path([]) + evc.sync() + self.circuits.setdefault(evc.id, evc) + self.sched.add(evc) + return evc @listen_to('kytos/flow_manager.flow.error') def handle_flow_mod_error(self, event):