import abc
import asyncio
+import gi
import tempfile
from gi.repository import (
RPC_SCHEMA_ENDPOINT = RwPkgMgmtYang.YangOutput_RwPkgMgmt_GetPackageSchema
RPC_PACKAGE_ADD_ENDPOINT = RwPkgMgmtYang.YangOutput_RwPkgMgmt_PackageFileAdd
RPC_PACKAGE_DELETE_ENDPOINT = RwPkgMgmtYang.YangOutput_RwPkgMgmt_PackageFileDelete
+RPC_PACKAGE_COPY_ENDPOINT = RwPkgMgmtYang.YangOutput_RwPkgMgmt_PackageCopy
class EndpointDiscoveryRpcHandler(mano_dts.AbstractRpcHandler):
def callback(self, ks_path, msg):
"""Forwards the request to proxy.
"""
+
url = yield from self.proxy.endpoint(
- msg.package_type,
- msg.package_id)
+ msg.package_type if msg.has_field('package_type') else "",
+ msg.package_id,
+ msg.project_name if msg.has_field('project_name') else None)
rpc_op = RPC_PKG_ENDPOINT.from_dict({"endpoint": url})
3. Return a tracking ID for the client to monitor the entire status
"""
- def __init__(self, log, dts, loop, proxy, publisher):
+ def __init__(self, log, dts, loop, proxy, tasklet):
"""
Args:
proxy: Any impl of .proxy.AbstractPackageManagerProxy
- publisher: Instance of DownloadStatusPublisher
+ publisher: Instance of tasklet to find the DownloadStatusPublisher
+ for a specific project
"""
super().__init__(log, dts, loop)
self.proxy = proxy
- self.publisher = publisher
+ self.tasklet = tasklet
@property
def xpath(self):
return "/rw-pkg-mgmt:package-file-add"
+ def get_publisher(self, msg):
+ try:
+ proj = self.tasklet.projects[msg.project_name]
+ except Exception as e:
+ err = "Project or project name not found {}: {}". \
+ format(msg.as_dict(), e)
+ self.log.error (err)
+ raise Exception (err)
+
+ return proj.job_handler
+
@asyncio.coroutine
def callback(self, ks_path, msg):
+ publisher = self.get_publisher(msg)
+
if not msg.external_url:
# For now we will only support External URL download
raise Exception ("No download URL provided")
auth=auth,
file_obj=filename,
proxy=self.proxy,
- log=self.log)
+ log=self.log,
+ project=msg.project_name)
- download_id = yield from self.publisher.register_downloader(url_downloader)
+ download_id = yield from publisher.register_downloader(url_downloader)
rpc_op = RPC_PACKAGE_ADD_ENDPOINT.from_dict({"task_id": download_id})
return rpc_op
+class PackageCopyOperationsRpcHandler(mano_dts.AbstractRpcHandler):
+ def __init__(self, log, dts, loop, project, proxy, publisher):
+ """
+ Args:
+ proxy: Any impl of .proxy.AbstractPackageManagerProxy
+ publisher: CopyStatusPublisher object
+ """
+ super().__init__(log, dts, loop, project)
+ self.proxy = proxy
+ self.publisher = publisher
+
+ @property
+ def xpath(self):
+ return "/rw-pkg-mgmt:package-copy"
+
+ @asyncio.coroutine
+ def callback(self, ks_path, msg):
+ import uuid
+ copier = pkg_downloader.PackageFileCopier.from_rpc_input(msg, self.project, proxy=self.proxy, log=self.log)
+
+ transaction_id, dest_package_id = yield from self.publisher.register_copier(copier)
+ rpc_op = RPC_PACKAGE_COPY_ENDPOINT.from_dict({
+ "transaction_id":transaction_id,
+ "package_id":dest_package_id,
+ "package_type":msg.package_type})
+
+ return rpc_op
class PackageDeleteOperationsRpcHandler(mano_dts.AbstractRpcHandler):
def __init__(self, log, dts, loop, proxy):
rpc_op = RPC_PACKAGE_DELETE_ENDPOINT.from_dict({"status": str(True)})
try:
+ package_file_type = msg.vnfd_file_type.lower() \
+ if msg.package_type == 'VNFD' else msg.nsd_file_type.lower()
self.proxy.package_file_delete(
msg.package_type,
msg.package_id,
- msg.package_path)
+ msg.package_path,
+ package_file_type,
+ msg.project_name,
+ )
except Exception as e:
self.log.exception(e)
rpc_op.status = str(False)