backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / core_manager.py
1 # Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """
17  Core Manager module dedicated for providing CORE_MANAGER singleton
18 """
19 from ryu.services.protocols.bgp.base import Activity
20 from ryu.services.protocols.bgp.base import ActivityException
21 from ryu.services.protocols.bgp.rtconf.neighbors import NeighborsConf
22 from ryu.services.protocols.bgp.rtconf.vrfs import VrfsConf
23
24
25 class _CoreManager(Activity):
26     """Core service manager.
27     """
28
29     def __init__(self):
30         self._common_conf = None
31         self._neighbors_conf = None
32         self._vrfs_conf = None
33         self._core_service = None
34         super(_CoreManager, self).__init__()
35
36     def _run(self, *args, **kwargs):
37         self._common_conf = kwargs.pop('common_conf')
38         self._neighbors_conf = NeighborsConf()
39         self._vrfs_conf = VrfsConf()
40         from ryu.services.protocols.bgp.core import CoreService
41         self._core_service = CoreService(self._common_conf,
42                                          self._neighbors_conf,
43                                          self._vrfs_conf)
44         waiter = kwargs.pop('waiter')
45         core_activity = self._spawn_activity(self._core_service, waiter=waiter)
46         core_activity.wait()
47
48     def get_core_service(self):
49         self._check_started()
50         return self._core_service
51
52     def _check_started(self):
53         if not self.started:
54             raise ActivityException('Cannot access any property before '
55                                     'activity has started')
56
57     @property
58     def common_conf(self):
59         self._check_started()
60         return self._common_conf
61
62     @property
63     def neighbors_conf(self):
64         self._check_started()
65         return self._neighbors_conf
66
67     @property
68     def vrfs_conf(self):
69         self._check_started()
70         return self._vrfs_conf
71
72
73 # _CoreManager instance that manages core bgp service and configuration data.
74 CORE_MANAGER = _CoreManager()