+ "Unexpected MIME type for file {}: MIME type {}".format(
+ filename, mime_type
+ )
+ )
+
+ special_override_string = ""
+ if override_epa or override_nonepa or override_paravirt:
+ # If override for EPA, non-EPA or paravirt is required, get the descriptor data
+ descriptor_data = None
+ if mime_type in ["application/yaml", "text/plain", "application/json"]:
+ with open(filename) as df:
+ descriptor_data = df.read()
+ elif mime_type in ["application/gzip", "application/x-gzip"]:
+ tar_object = tarfile.open(filename, "r:gz")
+ descriptor_list = []
+ for member in tar_object:
+ if member.isreg():
+ if "/" not in os.path.dirname(
+ member.name
+ ) and member.name.endswith(".yaml"):
+ descriptor_list.append(member.name)
+ if len(descriptor_list) > 1:
+ raise ClientException(
+ "Found more than one potential descriptor in the tar.gz file"
+ )
+ elif len(descriptor_list) == 0:
+ raise ClientException(
+ "No descriptor was found in the tar.gz file"
+ )
+ with tar_object.extractfile(descriptor_list[0]) as df:
+ descriptor_data = df.read()
+ tar_object.close()
+ if not descriptor_data:
+ raise ClientException("Descriptor could not be read")
+ desc_type, vnfd = validation_im().yaml_validation(descriptor_data)
+ validation_im().pyangbind_validation(desc_type, vnfd)
+
+ vnfd = yaml.safe_load(descriptor_data)
+ vcd_list = []
+ vdu_list = []
+ for k in vnfd:
+ # Get only the first descriptor in case there are many in the yaml file
+ # k can be vnfd or etsi-nfv-vnfd:vnfd. This check is skipped
+ first_vnfd = vnfd.get(k, {})
+ vcd_list = first_vnfd.get("virtual-compute-desc", [])
+ vdu_list = first_vnfd.get("vdu", [])
+ break
+
+ for vcd_number, vcd in enumerate(vcd_list):
+ if override_epa:
+ virtual_memory = vcd["virtual-memory"]
+ virtual_memory["mempage-size"] = "LARGE"
+ virtual_memory["numa-enabled"] = True
+ virtual_memory["numa-node-policy"] = {
+ "node-cnt": 1,
+ "mem-policy": "STRICT",
+ }
+ virtual_cpu = vcd["virtual-cpu"]
+ virtual_cpu["pinning"] = {
+ "policy": "static",
+ "thread-policy": "PREFER",
+ }
+
+ cpu_override_string = (
+ "virtual-compute-desc.{}.virtual-cpu={};".format(
+ vcd_number, quote(yaml.safe_dump(virtual_cpu))
+ )
+ )
+ memory_override_string = (
+ "virtual-compute-desc.{}.virtual-memory={};".format(
+ vcd_number, quote(yaml.safe_dump(virtual_memory))
+ )
+ )
+ special_override_string = "{}{}{}".format(
+ special_override_string,
+ cpu_override_string,
+ memory_override_string,
+ )
+
+ headers["Query-String-Format"] = "yaml"
+ if override_nonepa:
+ virtual_memory = vcd["virtual-memory"]
+ virtual_memory["mempage-size"] = ""
+ virtual_memory["numa-enabled"] = ""
+ virtual_memory["numa-node-policy"] = {}
+ virtual_cpu = vcd["virtual-cpu"]
+ virtual_cpu["pinning"] = {}
+
+ cpu_override_string = (
+ "virtual-compute-desc.{}.virtual-cpu={};".format(
+ vcd_number, quote(yaml.safe_dump(virtual_cpu))
+ )
+ )
+ memory_override_string = (
+ "virtual-compute-desc.{}.virtual-memory={};".format(
+ vcd_number, quote(yaml.safe_dump(virtual_memory))
+ )
+ )
+ special_override_string = "{}{}{}".format(
+ special_override_string,
+ cpu_override_string,
+ memory_override_string,
+ )
+
+ if override_paravirt:
+ for vdu_number, vdu in enumerate(vdu_list):
+ for cpd_number, cpd in enumerate(vdu["int-cpd"]):
+ for vnir_number, vnir in enumerate(
+ cpd["virtual-network-interface-requirement"]
+ ):
+ special_override_string = (
+ "{}vdu.{}.int-cpd.{}.virtual-network-interface-"
+ "requirement.{}.virtual-interface.type="
+ "PARAVIRT;".format(
+ special_override_string,
+ vdu_number,
+ cpd_number,
+ vnir_number,
+ )
+ )
+
+ special_override_string = special_override_string.rstrip(";")
+