X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=rwlaunchpad%2Fplugins%2Frwpkgmgr%2Frift%2Ftasklets%2Frwpkgmgr%2Fsubscriber%2Fdownload_status.py;h=6bca8588134232c3f7aaea5f8130b361da001ea2;hb=9ad945aab0b5a992e1df860bede8ecc9b143470e;hp=b4acb5f5523760e5e81f0bc4921be79091f9e53f;hpb=e36fcf1de3aa198c2c931c591db3859c09941347;p=osm%2FSO.git diff --git a/rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/subscriber/download_status.py b/rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/subscriber/download_status.py index b4acb5f5..6bca8588 100644 --- a/rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/subscriber/download_status.py +++ b/rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/subscriber/download_status.py @@ -36,21 +36,22 @@ from gi.repository import ( ) class DownloadStatusSubscriber(mano_dts.AbstractOpdataSubscriber): + def __init__(self, log, dts, loop, project, callback): + super().__init__(log, dts, loop, project, callback) + + def get_xpath(self): + return self._project.add_project( + "D,/rw-pkg-mgmt:download-jobs/rw-pkg-mgmt:job") - def __init__(self, log, dts, loop, callback): - super().__init__(log, dts, loop, callback) - - def get_xpath(self): - return ("D,/rw-pkg-mgmt:download-jobs/rw-pkg-mgmt:job") class VnfdStatusSubscriber(DownloadStatusSubscriber): DOWNLOAD_DIR = store.VnfdPackageFilesystemStore.DEFAULT_ROOT_DIR MODULE_DESC = 'vnfd rw-vnfd'.split() DESC_TYPE = 'vnfd' - def __init__(self, log, dts, loop): - super().__init__(log, dts, loop, self.on_change) - self.subscriber = mano_dts.VnfdCatalogSubscriber(log, dts, loop) + def __init__(self, log, dts, loop, project): + super().__init__(log, dts, loop, project, self.on_change) + self.subscriber = mano_dts.VnfdCatalogSubscriber(log, dts, loop, project) def on_change(self, msg, action): log_msg = "1. Vnfd called w/ msg attributes: {} id {} name {} action: {}".format(repr(msg), msg.id, msg.name, repr(action)) @@ -58,7 +59,7 @@ class VnfdStatusSubscriber(DownloadStatusSubscriber): if action == RwDts.QueryAction.UPDATE: actionCreate(self, msg) else: - self.log.debug("VnfdStatusSubscriber: No action for ", action) + self.log.debug("VnfdStatusSubscriber: No action for {}".format(repr(action))) pass def get_xpath(self): @@ -70,9 +71,9 @@ class NsdStatusSubscriber(DownloadStatusSubscriber): MODULE_DESC = 'nsd rw-nsd'.split() DESC_TYPE = 'nsd' - def __init__(self, log, dts, loop): - super().__init__(log, dts, loop, self.on_change) - self.subscriber = mano_dts.NsdCatalogSubscriber(log, dts, loop) + def __init__(self, log, dts, loop, project): + super().__init__(log, dts, loop, project, self.on_change) + self.subscriber = mano_dts.NsdCatalogSubscriber(log, dts, loop, project) def on_change(self, msg, action): log_msg = "1. Nsd called w/ msg attributes: {} id {} name {} action: {}".format(repr(msg), msg.id, msg.name, repr(action)) @@ -80,7 +81,7 @@ class NsdStatusSubscriber(DownloadStatusSubscriber): if action == RwDts.QueryAction.UPDATE: actionCreate(self, msg) else: - self.log.debug("NsdStatusSubscriber: No action for ", action) + self.log.debug("NsdStatusSubscriber: No action for {}".format(repr(action))) pass def get_xpath(self): @@ -93,16 +94,23 @@ def actionCreate(descriptor, msg): ''' desc_name = msg.name if msg.name else "" - download_dir = os.path.join(descriptor.DOWNLOAD_DIR, msg.id, desc_name) - - if not os.path.exists(download_dir): - os.makedirs(download_dir) - descriptor.log.debug("Created directory {}".format(download_dir)) - - model = RwYang.Model.create_libncx() - for module in descriptor.MODULE_DESC: model.load_module(module) - - yaml_path = "{base}/{name}_{type}.yaml".format(base=download_dir, name=msg.name, type=descriptor.DESC_TYPE) - with open(yaml_path,"w") as fh: - fh.write(msg.to_yaml(model)) + download_dir = os.path.join(descriptor.DOWNLOAD_DIR, msg.id) + + # If a download dir is present with contents, then we know it has been created in the + # upload path. + if os.path.exists(download_dir) and os.listdir(download_dir): + descriptor.log.debug("Skpping folder creation, {} already present".format(download_dir)) + return + else: + download_dir = os.path.join(download_dir, desc_name) + if not os.path.exists(download_dir): + os.makedirs(download_dir) + descriptor.log.debug("Created directory {}".format(download_dir)) + + model = RwYang.Model.create_libncx() + for module in descriptor.MODULE_DESC: model.load_module(module) + + yaml_path = "{base}/{name}_{type}.yaml".format(base=download_dir, name=msg.name, type=descriptor.DESC_TYPE) + with open(yaml_path,"w") as fh: + fh.write(msg.to_yaml(model))