update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b second try
[osm/SO.git] / rwlaunchpad / plugins / rwnsm / rift / tasklets / rwnsmtasklet / cloud.py
1 #
2 # Copyright 2016-2017 RIFT.IO Inc
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 import asyncio
18 from gi.repository import (
19 RwDts as rwdts,
20 RwcalYang as rwcal,
21 RwTypes,
22 ProtobufC,
23 )
24
25 import rift.mano.cloud
26 import rift.mano.ro_account
27 import rift.mano.dts as mano_dts
28 import rift.tasklets
29
30 from . import rwnsmplugin
31
32 class CloudAccountConfigSubscriber:
33 def __init__(self, log, dts, log_hdl, project):
34 self._dts = dts
35 self._log = log
36 self._log_hdl = log_hdl
37 self._project = project
38
39 self._cloud_sub = rift.mano.cloud.CloudAccountConfigSubscriber(
40 self._dts,
41 self._log,
42 self._log_hdl,
43 self._project,
44 rift.mano.cloud.CloudAccountConfigCallbacks())
45
46 def get_cloud_account_sdn_name(self, account_name):
47 if account_name in self._cloud_sub.accounts:
48 self._log.debug("Cloud accnt msg is %s",self._cloud_sub.accounts[account_name].account_msg)
49 if self._cloud_sub.accounts[account_name].account_msg.has_field("sdn_account"):
50 sdn_account = self._cloud_sub.accounts[account_name].account_msg.sdn_account
51 self._log.info("SDN associated with Cloud name %s is %s", account_name, sdn_account)
52 return sdn_account
53 else:
54 self._log.debug("No SDN Account associated with Cloud name %s", account_name)
55 return None
56
57 def get_cloud_account_msg(self,account_name):
58 if account_name in self._cloud_sub.accounts:
59 self._log.debug("Cloud accnt msg is %s",self._cloud_sub.accounts[account_name].account_msg)
60 return self._cloud_sub.accounts[account_name].account_msg
61
62 @asyncio.coroutine
63 def register(self):
64 yield from self._cloud_sub.register()
65
66 def deregister(self):
67 self._cloud_sub.deregister()
68
69 class ROAccountConfigSubscriber:
70 def __init__(self, dts, log, loop, project, records_publisher):
71 self._dts = dts
72 self._log = log
73 self._loop = loop
74 self._project = project
75 self._records_publisher = records_publisher
76
77 self._log.debug("Inside cloud - RO Account Config Subscriber init")
78
79 self._ro_sub = rift.mano.ro_account.ROAccountConfigSubscriber(
80 self._dts,
81 self._log,
82 self._loop,
83 self._project,
84 self._records_publisher,
85 rift.mano.ro_account.ROAccountConfigCallbacks())
86
87 def get_ro_plugin(self, account_name):
88 if (account_name is not None) and (account_name in self._ro_sub.accounts):
89 ro_account = self._ro_sub.accounts[account_name]
90 self._log.debug("RO Account associated with name %s is %s", account_name, ro_account)
91 return ro_account.ro_plugin
92
93 self._log.debug("RO Account associated with name %s using default plugin", account_name)
94 return rwnsmplugin.RwNsPlugin(self._dts, self._log, self._loop, self._records_publisher, None, self._project)
95
96 @asyncio.coroutine
97 def register(self):
98 self._log.debug("Registering ROAccount Config Subscriber")
99 yield from self._ro_sub.register()
100
101 def deregister(self):
102 self._ro_sub.deregister()