|
2 | 2 |
|
3 | 3 | NApp to provision circuits from user request.
|
4 | 4 | """
|
| 5 | +from threading import Lock |
| 6 | + |
5 | 7 | from flask import jsonify, request
|
6 | 8 | from werkzeug.exceptions import (BadRequest, Conflict, Forbidden,
|
7 | 9 | MethodNotAllowed, NotFound,
|
@@ -48,6 +50,8 @@ def setup(self):
|
48 | 50 | # dictionary of EVCs by interface
|
49 | 51 | self._circuits_by_interface = {}
|
50 | 52 |
|
| 53 | + self._lock = Lock() |
| 54 | + |
51 | 55 | self.execute_as_loop(settings.DEPLOY_EVCS_INTERVAL)
|
52 | 56 |
|
53 | 57 | def execute(self):
|
@@ -508,28 +512,31 @@ def add_to_dict_of_sets(self, intf, circuit_id):
|
508 | 512 | @listen_to('kytos/topology.port.created')
|
509 | 513 | def load_evcs(self, event):
|
510 | 514 | """Try to load the unloaded EVCs from storehouse."""
|
511 |
| - log.debug("Event load_evcs %s", event) |
512 |
| - circuits = self.storehouse.get_data() |
513 |
| - if not self._circuits_by_interface: |
514 |
| - self.load_circuits_by_interface(circuits) |
515 |
| - |
516 |
| - interface_id = '{}:{}'.format(event.content['switch'], |
517 |
| - event.content['port']) |
518 |
| - |
519 |
| - for circuit_id in self._circuits_by_interface.get(interface_id, []): |
520 |
| - if circuit_id in circuits and circuit_id not in self.circuits: |
521 |
| - try: |
522 |
| - evc = self._evc_from_dict(circuits[circuit_id]) |
523 |
| - except ValueError as exception: |
524 |
| - log.info( |
525 |
| - f'Could not load EVC {circuit_id} because {exception}') |
526 |
| - continue |
527 |
| - |
528 |
| - evc.deactivate() |
529 |
| - evc.current_path = Path([]) |
530 |
| - evc.sync() |
531 |
| - self.circuits.setdefault(circuit_id, evc) |
532 |
| - self.sched.add(evc) |
| 515 | + with self._lock: |
| 516 | + log.debug("Event load_evcs %s", event) |
| 517 | + circuits = self.storehouse.get_data() |
| 518 | + if not self._circuits_by_interface: |
| 519 | + self.load_circuits_by_interface(circuits) |
| 520 | + |
| 521 | + interface_id = '{}:{}'.format(event.content['switch'], |
| 522 | + event.content['port']) |
| 523 | + |
| 524 | + for circuit_id in self._circuits_by_interface.get(interface_id, |
| 525 | + []): |
| 526 | + if circuit_id in circuits and circuit_id not in self.circuits: |
| 527 | + try: |
| 528 | + evc = self._evc_from_dict(circuits[circuit_id]) |
| 529 | + except ValueError as exception: |
| 530 | + log.info( |
| 531 | + f'Could not load EVC {circuit_id} ' |
| 532 | + f'because {exception}') |
| 533 | + continue |
| 534 | + |
| 535 | + evc.deactivate() |
| 536 | + evc.current_path = Path([]) |
| 537 | + evc.sync() |
| 538 | + self.circuits.setdefault(circuit_id, evc) |
| 539 | + self.sched.add(evc) |
533 | 540 |
|
534 | 541 | @listen_to('kytos/flow_manager.flow.error')
|
535 | 542 | def handle_flow_mod_error(self, event):
|
|
0 commit comments