X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=rwlaunchpad%2Fplugins%2Frwnsm%2Frift%2Ftasklets%2Frwnsmtasklet%2Fcloud.py;fp=rwlaunchpad%2Fplugins%2Frwnsm%2Frift%2Ftasklets%2Frwnsmtasklet%2Fcloud.py;h=46647425ff7b7c8e9c66b708cecc0c94eb2c3eef;hb=4870d0ee29789b859931e4e2c73e13dcb29537d5;hp=343f80940a536e72a96f3b5538bac701393c50d0;hpb=6f1a3fe149e4a6b9803382cb299c902f4cf58ec9;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py index 343f8094..46647425 100644 --- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py +++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py @@ -1,6 +1,5 @@ - # -# Copyright 2016 RIFT.IO Inc +# Copyright 2016-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. @@ -24,119 +23,24 @@ from gi.repository import ( ) import rift.mano.cloud +import rift.mano.ro_account import rift.mano.dts as mano_dts import rift.tasklets -from . import openmano_nsm from . import rwnsmplugin - -class RwNsPlugin(rwnsmplugin.NsmPluginBase): - """ - RW Implentation of the NsmPluginBase - """ - def __init__(self, dts, log, loop, publisher, ro_account): - self._dts = dts - self._log = log - self._loop = loop - - def set_state(self, nsr_id, state): - pass - - def create_nsr(self, nsr_msg, nsd,key_pairs=None): - """ - Create Network service record - """ - pass - - @asyncio.coroutine - def deploy(self, nsr): - pass - - @asyncio.coroutine - def instantiate_ns(self, nsr, config_xact): - """ - Instantiate NSR with the passed nsr id - """ - yield from nsr.instantiate(config_xact) - - @asyncio.coroutine - def instantiate_vnf(self, nsr, vnfr, scaleout=False): - """ - Instantiate NSR with the passed nsr id - """ - yield from vnfr.instantiate(nsr) - - @asyncio.coroutine - def instantiate_vl(self, nsr, vlr): - """ - Instantiate NSR with the passed nsr id - """ - yield from vlr.instantiate() - - @asyncio.coroutine - def terminate_ns(self, nsr): - """ - Terminate the network service - """ - pass - - @asyncio.coroutine - def terminate_vnf(self, vnfr): - """ - Terminate the network service - """ - yield from vnfr.terminate() - - @asyncio.coroutine - def terminate_vl(self, vlr): - """ - Terminate the virtual link - """ - yield from vlr.terminate() - - -class NsmPlugins(object): - """ NSM Plugins """ - def __init__(self): - self._plugin_classes = { - "openmano": openmano_nsm.OpenmanoNsPlugin, - } - - @property - def plugins(self): - """ Plugin info """ - return self._plugin_classes - - def __getitem__(self, name): - """ Get item """ - print("%s", self._plugin_classes) - return self._plugin_classes[name] - - def register(self, plugin_name, plugin_class, *args): - """ Register a plugin to this Nsm""" - self._plugin_classes[plugin_name] = plugin_class - - def deregister(self, plugin_name, plugin_class, *args): - """ Deregister a plugin to this Nsm""" - if plugin_name in self._plugin_classes: - del self._plugin_classes[plugin_name] - - def class_by_plugin_name(self, name): - """ Get class by plugin name """ - return self._plugin_classes[name] - - class CloudAccountConfigSubscriber: - def __init__(self, log, dts, log_hdl): + def __init__(self, log, dts, log_hdl, project): self._dts = dts self._log = log self._log_hdl = log_hdl - + self._project = project + self._cloud_sub = rift.mano.cloud.CloudAccountConfigSubscriber( self._dts, self._log, self._log_hdl, + self._project, rift.mano.cloud.CloudAccountConfigCallbacks()) def get_cloud_account_sdn_name(self, account_name): @@ -150,93 +54,49 @@ class CloudAccountConfigSubscriber: self._log.debug("No SDN Account associated with Cloud name %s", account_name) return None + def get_cloud_account_msg(self,account_name): + if account_name in self._cloud_sub.accounts: + self._log.debug("Cloud accnt msg is %s",self._cloud_sub.accounts[account_name].account_msg) + return self._cloud_sub.accounts[account_name].account_msg + @asyncio.coroutine def register(self): - self._cloud_sub.register() + yield from self._cloud_sub.register() + def deregister(self): + self._cloud_sub.deregister() -class ROAccountPluginSelector(object): - """ - Select the RO based on the config. - - If no RO account is specified, then default to rift-ro. - - Note: - Currently only one RO can be used (one-time global config.) - """ - DEFAULT_PLUGIN = RwNsPlugin - - def __init__(self, dts, log, loop, records_publisher): +class ROAccountConfigSubscriber: + def __init__(self, dts, log, loop, project, records_publisher): self._dts = dts self._log = log self._loop = loop + self._project = project self._records_publisher = records_publisher - self._nsm_plugins = NsmPlugins() - - self._ro_sub = mano_dts.ROAccountConfigSubscriber( - self._log, + self._log.debug("Inside cloud - RO Account Config Subscriber init") + + self._ro_sub = rift.mano.ro_account.ROAccountConfigSubscriber( self._dts, - self._loop, - callback=self.on_ro_account_change - ) - self._nsr_sub = mano_dts.NsrCatalogSubscriber( self._log, - self._dts, self._loop, - self.handle_nsr) - - # The default plugin will be RwNsPlugin - self._ro_plugin = self._create_plugin(self.DEFAULT_PLUGIN, None) - self.live_instances = 0 - - @property - def ro_plugin(self): - return self._ro_plugin - - def handle_nsr(self, nsr, action): - if action == rwdts.QueryAction.CREATE: - self.live_instances += 1 - elif action == rwdts.QueryAction.DELETE: - self.live_instances -= 1 - - def on_ro_account_change(self, ro_account, action): - if action in [rwdts.QueryAction.CREATE, rwdts.QueryAction.UPDATE]: - self._on_ro_account_change(ro_account) - elif action == rwdts.QueryAction.DELETE: - self._on_ro_account_deleted(ro_account) - - def _on_ro_account_change(self, ro_account): - self._log.debug("Got nsm plugin RO account: %s", ro_account) - try: - nsm_cls = self._nsm_plugins.class_by_plugin_name( - ro_account.account_type - ) - except KeyError as e: - self._log.debug( - "RO account nsm plugin not found: %s. Using standard rift nsm.", - ro_account.name - ) - nsm_cls = self.DEFAULT_PLUGIN - - ro_plugin = self._create_plugin(nsm_cls, ro_account) - if self.live_instances == 0: - self._ro_plugin = ro_plugin - else: - raise ValueError("Unable to change the plugin when live NS instances exists!") - - def _on_ro_account_deleted(self, ro_account): - self._ro_plugin = None - - def _create_plugin(self, nsm_cls, ro_account): - - 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, ro_account) - - return nsm_instance - + self._project, + self._records_publisher, + rift.mano.ro_account.ROAccountConfigCallbacks()) + + def get_ro_plugin(self, account_name): + if (account_name is not None) and (account_name in self._ro_sub.accounts): + ro_account = self._ro_sub.accounts[account_name] + self._log.debug("RO Account associated with name %s is %s", account_name, ro_account) + return ro_account.ro_plugin + + self._log.debug("RO Account associated with name %s using default plugin", account_name) + return rwnsmplugin.RwNsPlugin(self._dts, self._log, self._loop, self._records_publisher, None, self._project) + @asyncio.coroutine def register(self): - yield from self._ro_sub.register() - yield from self._nsr_sub.register() + self._log.debug("Registering ROAccount Config Subscriber") + yield from self._ro_sub.register() + + def deregister(self): + self._ro_sub.deregister() \ No newline at end of file