headers["Content-Type"] = "text/plain"
elif mime_type in ["application/gzip", "application/x-gzip"]:
headers["Content-Type"] = "application/gzip"
+ elif mime_type in ["application/zip"]:
+ headers["Content-Type"] = "application/zip"
else:
raise ClientException(
"Unexpected MIME type for file {}: MIME type {}".format(
from urllib.parse import quote
import tarfile
from osm_im.validation import Validation as validation_im
+from zipfile import ZipFile
class Vnfd(object):
headers["Content-Type"] = "text/plain"
elif mime_type in ["application/gzip", "application/x-gzip"]:
headers["Content-Type"] = "application/gzip"
+ elif mime_type in ["application/zip"]:
+ headers["Content-Type"] = "application/zip"
else:
raise ClientException(
"Unexpected MIME type for file {}: MIME type {}".format(
with tar_object.extractfile(descriptor_list[0]) as df:
descriptor_data = df.read()
tar_object.close()
+ elif mime_type in ["application/zip"]:
+ package_zip = ZipFile(filename)
+ package_files = package_zip.infolist()
+
+ descriptors = []
+ if (
+ "Definitions" in package_files
+ and "TOSCA-Metadata" in package_files
+ ):
+ descriptors = [
+ definition
+ for definition in package_files
+ if "Definitions/" in definition
+ and (
+ definition.endswith(".yaml")
+ or definition.endswith(".yml")
+ )
+ ]
+ else:
+ descriptors = [
+ definition
+ for definition in package_files
+ if definition.endswith(".yaml")
+ or definition.endswith(".yml")
+ ]
+ if len(descriptors) < 1:
+ raise ClientException(
+ "No descriptor found on this package, OSM was expecting at least 1"
+ )
+ descriptor_data = package_zip.open(descriptors[0])
+ package_zip.close()
+
if not descriptor_data:
raise ClientException("Descriptor could not be read")
desc_type, vnfd = validation_im().yaml_validation(descriptor_data)