3 # Copyright 2017 RIFT.IO Inc
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 from gi
.repository
import (
24 import rift
.mano
.dts
as mano_dts
27 from rift
.tasklets
.rwnsmtasklet
import openmano_nsm
28 from rift
.tasklets
.rwnsmtasklet
import rwnsmplugin
30 class ROAccount(object):
32 RO Account Model class
34 DEFAULT_PLUGIN
= rwnsmplugin
.RwNsPlugin
36 def __init__(self
, dts
=None, log
=None, loop
=None, project
=None, records_publisher
=None, account_msg
=None):
40 self
._project
= project
41 self
._records
_publisher
= records_publisher
42 self
._account
_msg
= None
43 if account_msg
is not None:
44 self
._account
_msg
= account_msg
.deep_copy()
45 self
._name
= self
._account
_msg
.name
47 self
._datacenters
= []
48 self
._status
= RwRoAccountYang
.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus(
50 details
="Connection status lookup not started"
52 self
.live_instances
= 0
57 self
._nsm
_plugins
= rwnsmplugin
.NsmPlugins()
58 self
._nsm
_cls
= self
.DEFAULT_PLUGIN
61 self
._nsm
_cls
= self
._nsm
_plugins
.class_by_plugin_name(
62 account_msg
.ro_account_type
66 "RO account nsm plugin not found: %s. Using standard rift nsm.",
70 self
._ro
_plugin
= self
._create
_plugin
(self
._nsm
_cls
, account_msg
)
77 def account_msg(self
):
78 return self
._account
_msg
81 def ro_acccount_type(self
):
82 return self
._account
_msg
.ro_account_type
if self
._account
_msg
else 'rift'
86 return self
._ro
_plugin
89 def connection_status(self
):
92 def _create_plugin(self
, nsm_cls
, account_msg
):
93 self
._log
.debug("Instantiating new RO account using class: %s", nsm_cls
)
94 nsm_instance
= nsm_cls(self
._dts
, self
._log
, self
._loop
,
95 self
._records
_publisher
, account_msg
, self
._project
)
98 def check_ro_account_status(self
):
99 self
._log
.debug("Checking RO Account Status. Acct: %s",
101 self
._status
= RwRoAccountYang
.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus(
103 details
="RO account connection status check in progress"
106 self
._datacenters
= []
107 for uuid
, name
in self
._ro
_plugin
._cli
_api
.datacenter_list():
108 self
._datacenters
.append({
113 self
._status
= RwRoAccountYang
.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus(
115 details
="RO account connection status success"
118 self
._status
= RwRoAccountYang
.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus(
120 details
="RO account connection status failure"
122 self
._log
.warning("RO account connection status failure, Acct:%s, status:%s",
123 self
.name
, self
._status
)
125 def start_validate_ro_account(self
, loop
):
126 loop
.run_in_executor(None, self
.check_ro_account_status
)