Unity MSB address
[modeling/etsicatalog.git] / catalog / packages / biz / vnf_package.py
index 6dec204..e202674 100644 (file)
@@ -15,7 +15,6 @@
 import json
 import logging
 import os
-
 import threading
 import traceback
 import urllib
@@ -25,7 +24,7 @@ import zipfile
 from catalog.packages import const
 from catalog.packages.biz.common import parse_file_range, read, save
 from catalog.packages.biz.notificationsutil import PkgNotifications
-from catalog.pub.config.config import CATALOG_ROOT_PATH
+from catalog.pub.config.config import CATALOG_ROOT_PATH, MSB_BASE_URL
 from catalog.pub.database.models import VnfPackageModel, NSPackageModel
 from catalog.pub.exceptions import CatalogException, ResourceNotFoundException
 from catalog.pub.utils import fileutil, toscaparser
@@ -279,6 +278,18 @@ def fill_artifacts_data(vnf_pkg_id):
             } for artifact in artifacts]
 
 
+def fill_links(pkg_id, is_onboarded=False):
+    self_href = "%s/api/vnfpkgm/v1/vnf_packages/%s" % (MSB_BASE_URL, pkg_id)
+    links = {
+        "self": {"href": self_href},
+        "vnfd": {"href": "%s/%s" % (self_href, "vnfd")},
+        "packageContent": {"href": "%s/%s" % (self_href, "package_content")}
+    }
+    if not is_onboarded:
+        links.pop("vnfd")
+    return links
+
+
 def fill_response_data(nf_pkg):
     pkg_info = {}
     pkg_info["id"] = nf_pkg.vnfPackageId
@@ -295,7 +306,7 @@ def fill_response_data(nf_pkg):
     pkg_info["usageState"] = nf_pkg.usageState
     if nf_pkg.userDefinedData:
         pkg_info["userDefinedData"] = json.JSONDecoder().decode(nf_pkg.userDefinedData)
-    pkg_info["_links"] = None  # TODO
+    pkg_info["_links"] = fill_links(nf_pkg.vnfPackageId, True)
     return pkg_info