VNFs with only VLDs compatibility 49/6849/1
authorgcalvino <guillermo.calvinosanchez@altran.com>
Mon, 5 Nov 2018 14:33:23 +0000 (15:33 +0100)
committergcalvino <guillermo.calvinosanchez@altran.com>
Mon, 5 Nov 2018 14:33:23 +0000 (15:33 +0100)
Change-Id: If67fc71ba17be046af8c795a473461422d345aaa
Signed-off-by: gcalvino <guillermo.calvinosanchez@altran.com>
openmano
osm_ro/nfvo.py

index d3b4feb..2434f95 100755 (executable)
--- a/openmano
+++ b/openmano
@@ -273,13 +273,13 @@ def vnf_create(args):
         if not vnfds:
             vnfds = vnfd_catalog.get("vnfd")
         vnfd = vnfds[0]
-        vdu_list = vnfd["vdu"]
+        vdu_list = vnfd.get("vdu")
 
     else:  # old API
         api_version = ""
         token = "vnfs"
         vnfd = myvnf['vnf']
-        vdu_list = vnfd["VNFC"]
+        vdu_list = vnfd.get("VNFC")
 
     if args.name or args.description or args.image_path or args.image_name or args.image_checksum:
         # TODO, change this for API v3
@@ -289,62 +289,63 @@ def vnf_create(args):
                 vnfd['name'] = args.name
             if args.description:
                 vnfd['description'] = args.description
-            if args.image_path:
-                index = 0
-                for image_path_ in args.image_path.split(","):
-                    # print "image-path", image_path_
-                    if api_version == "/v3":
-                        if vdu_list[index].get("image"):
-                            vdu_list[index]['image'] = image_path_
-                            if "image-checksum" in vdu_list[index]:
-                                del vdu_list[index]["image-checksum"]
-                        else:  # image name in volumes
-                            vdu_list[index]["volumes"][0]["image"] = image_path_
-                            if "image-checksum" in vdu_list[index]["volumes"][0]:
-                                del vdu_list[index]["volumes"][0]["image-checksum"]
-                    else:
-                        vdu_list[index]['VNFC image'] = image_path_
-                        if "image name" in vdu_list[index]:
-                            del vdu_list[index]["image name"]
-                        if "image checksum" in vdu_list[index]:
-                            del vdu_list[index]["image checksum"]
-                    index += 1
-            if args.image_name:  # image name precedes if both are supplied
-                index = 0
-                for image_name_ in args.image_name.split(","):
-                    if api_version == "/v3":
-                        if vdu_list[index].get("image"):
-                            vdu_list[index]['image'] = image_name_
-                            if "image-checksum" in vdu_list[index]:
-                                del vdu_list[index]["image-checksum"]
-                            if vdu_list[index].get("alternative-images"):
-                                for a_image in vdu_list[index]["alternative-images"]:
-                                    a_image['image'] = image_name_
-                                    if "image-checksum" in a_image:
-                                        del a_image["image-checksum"]
-                        else:  # image name in volumes
-                            vdu_list[index]["volumes"][0]["image"] = image_name_
-                            if "image-checksum" in vdu_list[index]["volumes"][0]:
-                                del vdu_list[index]["volumes"][0]["image-checksum"]
-                    else:
-                        vdu_list[index]['image name'] = image_name_
-                        if "VNFC image" in vdu_list[index]:
-                            del vdu_list[index]["VNFC image"]
-                    index += 1
-            if args.image_checksum:
-                index = 0
-                for image_checksum_ in args.image_checksum.split(","):
-                    if api_version == "/v3":
-                        if vdu_list[index].get("image"):
-                            vdu_list[index]['image-checksum'] = image_checksum_
-                            if vdu_list[index].get("alternative-images"):
-                                for a_image in vdu_list[index]["alternative-images"]:
-                                    a_image['image-checksum'] = image_checksum_
-                        else:  # image name in volumes
-                            vdu_list[index]["volumes"][0]["image-checksum"] = image_checksum_
-                    else:
-                        vdu_list[index]['image checksum'] = image_checksum_
-                    index += 1
+            if vdu_list:
+                if args.image_path:
+                    index = 0
+                    for image_path_ in args.image_path.split(","):
+                        # print "image-path", image_path_
+                        if api_version == "/v3":
+                            if vdu_list[index].get("image"):
+                                vdu_list[index]['image'] = image_path_
+                                if "image-checksum" in vdu_list[index]:
+                                    del vdu_list[index]["image-checksum"]
+                            else:  # image name in volumes
+                                vdu_list[index]["volumes"][0]["image"] = image_path_
+                                if "image-checksum" in vdu_list[index]["volumes"][0]:
+                                    del vdu_list[index]["volumes"][0]["image-checksum"]
+                        else:
+                            vdu_list[index]['VNFC image'] = image_path_
+                            if "image name" in vdu_list[index]:
+                                del vdu_list[index]["image name"]
+                            if "image checksum" in vdu_list[index]:
+                                del vdu_list[index]["image checksum"]
+                        index += 1
+                if args.image_name:  # image name precedes if both are supplied
+                    index = 0
+                    for image_name_ in args.image_name.split(","):
+                        if api_version == "/v3":
+                            if vdu_list[index].get("image"):
+                                vdu_list[index]['image'] = image_name_
+                                if "image-checksum" in vdu_list[index]:
+                                    del vdu_list[index]["image-checksum"]
+                                if vdu_list[index].get("alternative-images"):
+                                    for a_image in vdu_list[index]["alternative-images"]:
+                                        a_image['image'] = image_name_
+                                        if "image-checksum" in a_image:
+                                            del a_image["image-checksum"]
+                            else:  # image name in volumes
+                                vdu_list[index]["volumes"][0]["image"] = image_name_
+                                if "image-checksum" in vdu_list[index]["volumes"][0]:
+                                    del vdu_list[index]["volumes"][0]["image-checksum"]
+                        else:
+                            vdu_list[index]['image name'] = image_name_
+                            if "VNFC image" in vdu_list[index]:
+                                del vdu_list[index]["VNFC image"]
+                        index += 1
+                if args.image_checksum:
+                    index = 0
+                    for image_checksum_ in args.image_checksum.split(","):
+                        if api_version == "/v3":
+                            if vdu_list[index].get("image"):
+                                vdu_list[index]['image-checksum'] = image_checksum_
+                                if vdu_list[index].get("alternative-images"):
+                                    for a_image in vdu_list[index]["alternative-images"]:
+                                        a_image['image-checksum'] = image_checksum_
+                            else:  # image name in volumes
+                                vdu_list[index]["volumes"][0]["image-checksum"] = image_checksum_
+                        else:
+                            vdu_list[index]['image checksum'] = image_checksum_
+                        index += 1
         except (KeyError, TypeError), e:
             if str(e) == 'vnf':           error_pos= "missing field 'vnf'"
             elif str(e) == 'name':        error_pos= "missing field  'vnf':'name'"
index f4a2d79..024e83a 100644 (file)
@@ -1600,13 +1600,13 @@ def get_vnf_id(mydb, tenant_id, vnf_id):
             SELECT=('vms.uuid as uuid', 'vms.osm_id as osm_id', 'vms.name as name', 'vms.description as description',
                     'boot_data'),
             WHERE={'vnfs.uuid': vnf_id} )
-    if len(content)==0:
-        raise NfvoException("vnf '{}' not found".format(vnf_id), HTTP_Not_Found)
+    if len(content)!=0:
+        #raise NfvoException("vnf '{}' not found".format(vnf_id), HTTP_Not_Found)
     # change boot_data into boot-data
-    for vm in content:
-        if vm.get("boot_data"):
-            vm["boot-data"] = yaml.safe_load(vm["boot_data"])
-            del vm["boot_data"]
+        for vm in content:
+            if vm.get("boot_data"):
+                vm["boot-data"] = yaml.safe_load(vm["boot_data"])
+                del vm["boot_data"]
 
     data['vnf']['VNFC'] = content
     #TODO: GET all the information from a VNFC and include it in the output.