From 319b8a5b560b881c51e019b1350a4d73b5df2b41 Mon Sep 17 00:00:00 2001 From: gcalvino Date: Mon, 5 Nov 2018 15:33:23 +0100 Subject: [PATCH] VNFs with only VLDs compatibility Change-Id: If67fc71ba17be046af8c795a473461422d345aaa Signed-off-by: gcalvino --- openmano | 117 +++++++++++++++++++++++++------------------------ osm_ro/nfvo.py | 12 ++--- 2 files changed, 65 insertions(+), 64 deletions(-) diff --git a/openmano b/openmano index d3b4feb6..2434f952 100755 --- 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'" diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index f4a2d798..024e83aa 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -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. -- 2.25.1