Skip to content

Commit

Permalink
Load all EVCs on startup
Browse files Browse the repository at this point in the history
Fixes #19
  • Loading branch information
ajoaoff committed Jul 2, 2021
1 parent c1432fd commit 71ccd2a
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 71ccd2a

Please sign in to comment.