From c020d817b384dd6ab36dde93a9b42d6bf9199c14 Mon Sep 17 00:00:00 2001 From: Varun Prasad Date: Sat, 10 Sep 2016 06:29:21 -0400 Subject: [PATCH] RIFT-14553: Datacenters are now listed under ro-accounts Signed-off-by: Varun Prasad --- common/python/CMakeLists.txt | 1 + common/python/rift/mano/dts/__init__.py | 3 +- .../rift/mano/dts/subscriber/ro_account.py | 36 +++++++++++ .../rift/tasklets/rwlaunchpad/datacenters.py | 61 ++++++++----------- .../rift/tasklets/rwlaunchpad/tasklet.py | 2 +- .../rwnsm/rift/tasklets/rwnsmtasklet/cloud.py | 11 +--- rwlaunchpad/plugins/yang/rw-launchpad.yang | 6 +- 7 files changed, 71 insertions(+), 49 deletions(-) create mode 100644 common/python/rift/mano/dts/subscriber/ro_account.py diff --git a/common/python/CMakeLists.txt b/common/python/CMakeLists.txt index 658d5252..85ead68d 100644 --- a/common/python/CMakeLists.txt +++ b/common/python/CMakeLists.txt @@ -41,6 +41,7 @@ rift_python_install_tree( rift/mano/dts/subscriber/store.py rift/mano/dts/subscriber/ns_subscriber.py rift/mano/dts/subscriber/vnf_subscriber.py + rift/mano/dts/subscriber/ro_account.py COMPONENT ${PKG_LONG_NAME} PYTHON3_ONLY ) diff --git a/common/python/rift/mano/dts/__init__.py b/common/python/rift/mano/dts/__init__.py index e5230348..a56fa049 100644 --- a/common/python/rift/mano/dts/__init__.py +++ b/common/python/rift/mano/dts/__init__.py @@ -21,4 +21,5 @@ from .core import DtsHandler from .subscriber.core import AbstractOpdataSubscriber, AbstractConfigSubscriber from .subscriber.vnf_subscriber import VnfdCatalogSubscriber, VnfrCatalogSubscriber from .subscriber.ns_subscriber import NsrCatalogSubscriber, NsdCatalogSubscriber -from .subscriber.store import SubscriberStore \ No newline at end of file +from .subscriber.store import SubscriberStore +from .subscriber.ro_account import ROAccountConfigSubscriber \ No newline at end of file diff --git a/common/python/rift/mano/dts/subscriber/ro_account.py b/common/python/rift/mano/dts/subscriber/ro_account.py new file mode 100644 index 00000000..575d649c --- /dev/null +++ b/common/python/rift/mano/dts/subscriber/ro_account.py @@ -0,0 +1,36 @@ +""" +# +# Copyright 2016 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. +# + +@file ro_account.py +@author Varun Prasad (varun.prasad@riftio.com) +@date 09-Jul-2016 + +""" + +import gi +gi.require_version('RwDts', '1.0') +from gi.repository import RwDts as rwdts + +from . import core + +class ROAccountConfigSubscriber(core.AbstractConfigSubscriber): + + def key_name(self): + return "name" + + def get_xpath(self): + return("C,/rw-launchpad:resource-orchestrator") \ No newline at end of file diff --git a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/datacenters.py b/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/datacenters.py index 84fddb65..05731a61 100644 --- a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/datacenters.py +++ b/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/datacenters.py @@ -22,11 +22,12 @@ from gi.repository import ( RwLaunchpadYang, ) +import rift.mano.dts as mano_dts import rift.openmano.openmano_client as openmano_client import rift.tasklets -class DataCenterPublisher(object): +class DataCenterPublisher(mano_dts.DtsHandler): """ This class is reponsible for exposing the data centers associated with an openmano cloud account. @@ -34,44 +35,33 @@ class DataCenterPublisher(object): XPATH = "D,/rw-launchpad:datacenters" - def __init__(self, tasklet): + def __init__(self, log, dts, loop): """Creates an instance of a DataCenterPublisher Arguments: tasklet - the tasklet that this publisher is registered for """ - self.tasklet = tasklet - self.reg = None - - @property - def dts(self): - """The DTS instance used by this tasklet""" - return self.tasklet.dts - - @property - def log(self): - """The logger used by this tasklet""" - return self.tasklet.log - - @property - def loop(self): - """The event loop used by this tasklet""" - return self.tasklet.loop - - @property - def accounts(self): - """The known openmano cloud accounts""" - accounts = list() - for acc in self.tasklet.cloud_accounts: - if acc.account_type == "openmano": - accounts.append(acc.account_msg) - - return accounts + super().__init__(log, dts, loop) + + self._ro_sub = mano_dts.ROAccountConfigSubscriber( + self.log, + self.dts, + self.loop, + callback=self.on_ro_account_change + ) + self.ro_accounts = {} + + def on_ro_account_change(self, ro_account, action): + if action in [ RwDts.QueryAction.CREATE, RwDts.QueryAction.UPDATE ]: + self.ro_accounts[ro_account.name] = ro_account + elif action == RwDts.QueryAction.DELETE and ro_account.name in self.ro_accounts: + del self.ro_accounts[ro_account.name] @asyncio.coroutine def register(self): """Registers the publisher with DTS""" + yield from self._ro_sub.register() @asyncio.coroutine def on_prepare(xact_info, action, ks_path, msg): @@ -82,10 +72,13 @@ class DataCenterPublisher(object): # Iterate over the known openmano accounts and populate cloud # account instances with the corresponding data center info - for account in self.accounts: + for _, account in self.ro_accounts.items(): + if account.account_type != "openmano": + continue + try: - cloud_account = RwLaunchpadYang.CloudAccount() - cloud_account.name = account.name + ro_account = RwLaunchpadYang.ROAccount() + ro_account.name = account.name # Create a client for this cloud account to query for # the associated data centers @@ -98,14 +91,14 @@ class DataCenterPublisher(object): # Populate the cloud account with the data center info for uuid, name in client.datacenter_list(): - cloud_account.datacenters.append( + ro_account.datacenters.append( RwLaunchpadYang.DataCenter( uuid=uuid, name=name, ) ) - datacenters.cloud_accounts.append(cloud_account) + datacenters.ro_accounts.append(ro_account) except Exception as e: self.log.exception(e) diff --git a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/tasklet.py b/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/tasklet.py index ca09d33c..9bcb2d38 100644 --- a/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/tasklet.py +++ b/rwlaunchpad/plugins/rwlaunchpadtasklet/rift/tasklets/rwlaunchpad/tasklet.py @@ -405,7 +405,7 @@ class LaunchpadTasklet(rift.tasklets.Tasklet): yield from self.vnfd_catalog_handler.register() self.log.debug("creating datacenter handler") - self.datacenter_handler = datacenters.DataCenterPublisher(self) + self.datacenter_handler = datacenters.DataCenterPublisher(self.log, self.dts, self.loop) yield from self.datacenter_handler.register() self.log.debug("creating cloud account handler") diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py index 5326ca12..5d73680b 100644 --- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py +++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/cloud.py @@ -124,15 +124,6 @@ class NsmPlugins(object): return self._plugin_classes[name] -class ROAccountConfigSubscriber(mano_dts.AbstractConfigSubscriber): - - def key_name(self): - return "name" - - def get_xpath(self): - return("C,/rw-launchpad:resource-orchestrator") - - class CloudAccountConfigSubscriber: def __init__(self, log, dts, log_hdl): self._dts = dts @@ -180,7 +171,7 @@ class ROAccountPluginSelector(object): self._nsm_plugins = NsmPlugins() - self._ro_sub = ROAccountConfigSubscriber( + self._ro_sub = mano_dts.ROAccountConfigSubscriber( self._log, self._dts, self._loop, diff --git a/rwlaunchpad/plugins/yang/rw-launchpad.yang b/rwlaunchpad/plugins/yang/rw-launchpad.yang index 37a9c85d..454aec1d 100644 --- a/rwlaunchpad/plugins/yang/rw-launchpad.yang +++ b/rwlaunchpad/plugins/yang/rw-launchpad.yang @@ -104,18 +104,18 @@ module rw-launchpad rwpb:msg-new DataCenters; config false; - list cloud-accounts { + list ro-accounts { description "A list of OpenMano cloud accounts that have data centers associated with them"; - rwpb:msg-new CloudAccount; + rwpb:msg-new ROAccount; key "name"; leaf name { description "The name of the cloud account"; type leafref { - path "/rw-cloud:cloud/rw-cloud:account/rw-cloud:name"; + path "/rw-launchpad:resource-orchestrator/rw-launchpad:name"; } } -- 2.25.1