2 # Copyright 2016-2017 RIFT.IO Inc
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 from gi
.repository
import (
25 import rift
.mano
.cloud
26 import rift
.mano
.ro_account
27 import rift
.mano
.dts
as mano_dts
30 from . import rwnsmplugin
32 class CloudAccountConfigSubscriber
:
33 def __init__(self
, log
, dts
, log_hdl
, project
):
36 self
._log
_hdl
= log_hdl
37 self
._project
= project
39 self
._cloud
_sub
= rift
.mano
.cloud
.CloudAccountConfigSubscriber(
44 rift
.mano
.cloud
.CloudAccountConfigCallbacks())
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
)
54 self
._log
.debug("No SDN Account associated with Cloud name %s", account_name
)
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
64 yield from self
._cloud
_sub
.register()
67 self
._cloud
_sub
.deregister()
69 class ROAccountConfigSubscriber
:
70 def __init__(self
, dts
, log
, loop
, project
, records_publisher
):
74 self
._project
= project
75 self
._records
_publisher
= records_publisher
77 self
._log
.debug("Inside cloud - RO Account Config Subscriber init")
79 self
._ro
_sub
= rift
.mano
.ro_account
.ROAccountConfigSubscriber(
84 self
._records
_publisher
,
85 rift
.mano
.ro_account
.ROAccountConfigCallbacks())
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
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
)
98 self
._log
.debug("Registering ROAccount Config Subscriber")
99 yield from self
._ro
_sub
.register()
101 def deregister(self
):
102 self
._ro
_sub
.deregister()