X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=common%2Fpython%2Frift%2Fmano%2Fro_account%2Faccounts.py;fp=common%2Fpython%2Frift%2Fmano%2Fro_account%2Faccounts.py;h=74e5ea282b56c552480ebeeac50ad4824bbc8659;hb=4870d0ee29789b859931e4e2c73e13dcb29537d5;hp=0000000000000000000000000000000000000000;hpb=6f1a3fe149e4a6b9803382cb299c902f4cf58ec9;p=osm%2FSO.git diff --git a/common/python/rift/mano/ro_account/accounts.py b/common/python/rift/mano/ro_account/accounts.py new file mode 100644 index 00000000..74e5ea28 --- /dev/null +++ b/common/python/rift/mano/ro_account/accounts.py @@ -0,0 +1,126 @@ + +# +# Copyright 2017 RIFT.IO Inc +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +import asyncio + +from gi.repository import ( + RwDts as rwdts, + RwRoAccountYang, + ) + +import rift.mano.dts as mano_dts +import rift.tasklets + +from rift.tasklets.rwnsmtasklet import openmano_nsm +from rift.tasklets.rwnsmtasklet import rwnsmplugin + +class ROAccount(object): + """ + RO Account Model class + """ + DEFAULT_PLUGIN = rwnsmplugin.RwNsPlugin + + def __init__(self, dts=None, log=None, loop=None, project=None, records_publisher=None, account_msg=None): + self._dts = dts + self._log = log + self._loop = loop + self._project = project + self._records_publisher = records_publisher + self._account_msg = None + if account_msg is not None: + self._account_msg = account_msg.deep_copy() + self._name = self._account_msg.name + + self._datacenters = [] + self._status = RwRoAccountYang.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus( + status="unknown", + details="Connection status lookup not started" + ) + self.live_instances = 0 + + if self._dts is None: + return + + self._nsm_plugins = rwnsmplugin.NsmPlugins() + self._nsm_cls = self.DEFAULT_PLUGIN + + try: + self._nsm_cls = self._nsm_plugins.class_by_plugin_name( + account_msg.ro_account_type + ) + except KeyError as e: + self._log.warning( + "RO account nsm plugin not found: %s. Using standard rift nsm.", + account_msg.name + ) + + self._ro_plugin = self._create_plugin(self._nsm_cls, account_msg) + + @property + def name(self): + return self._name + + @property + def account_msg(self): + return self._account_msg + + @property + def ro_acccount_type(self): + return self._account_msg.ro_account_type if self._account_msg else 'rift' + + @property + def ro_plugin(self): + return self._ro_plugin + + @property + def connection_status(self): + return self._status + + def _create_plugin(self, nsm_cls, account_msg): + self._log.debug("Instantiating new RO account using class: %s", nsm_cls) + nsm_instance = nsm_cls(self._dts, self._log, self._loop, + self._records_publisher, account_msg, self._project) + return nsm_instance + + def check_ro_account_status(self): + self._log.debug("Checking RO Account Status. Acct: %s", + self.name) + self._status = RwRoAccountYang.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus( + status="validating", + details="RO account connection status check in progress" + ) + try: + self._datacenters = [] + for uuid, name in self._ro_plugin._cli_api.datacenter_list(): + self._datacenters.append({ + 'uuid':uuid, + 'name':name + } + ) + self._status = RwRoAccountYang.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus( + status="success", + details="RO account connection status success" + ) + except: + self._status = RwRoAccountYang.YangData_RwProject_Project_RoAccountState_Account_ConnectionStatus( + status="failure", + details="RO account connection status failure" + ) + self._log.warning("RO account connection status failure, Acct:%s, status:%s", + self.name, self._status) + + def start_validate_ro_account(self, loop): + loop.run_in_executor(None, self.check_ro_account_status)