1 # -*- coding: utf-8 -*-
3 # Copyright 2021 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM common repository.
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: agarcia@whitestack.com or fbravo@whitestack.com
25 """Python module for interacting with ETSI GS NFV-SOL004 compliant packages
27 This module provides a SOL004Package class for validating and interacting with
28 ETSI SOL004 packages. A valid SOL004 package may have its files arranged according
29 to one of the following two structures:
31 SOL004 with metadata directory SOL004 without metadata directory
33 native_charm_vnf/ native_charm_vnf/
34 ├── TOSCA-Metadata ├── native_charm_vnfd.mf
35 │ └── TOSCA.meta ├── native_charm_vnfd.yaml
36 ├── manifest.mf ├── ChangeLog.txt
37 ├── Definitions ├── Licenses
38 │ └── native_charm_vnfd.yaml │ └── license.lic
40 │ ├── icons │ └── icons
41 │ │ └── osm.png │ └── osm.png
42 │ ├── Licenses └── Scripts
43 │ │ └── license.lic ├── cloud_init
44 │ └── changelog.txt │ └── cloud-config.txt
45 └── Scripts └── charms
46 ├── cloud_init └── simple
47 │ └── cloud-config.txt ├── config.yaml
49 └── simple │ ├── install
61 from .sol_package
import SOLPackage
64 class SOL004PackageException(Exception):
68 class SOL004Package(SOLPackage
):
69 _MANIFEST_VNFD_ID
= "vnfd_id"
70 _MANIFEST_VNFD_PRODUCT_NAME
= "vnfd_product_name"
71 _MANIFEST_VNFD_PROVIDER_ID
= "vnfd_provider_id"
72 _MANIFEST_VNFD_SOFTWARE_VERSION
= "vnfd_software_version"
73 _MANIFEST_VNFD_PACKAGE_VERSION
= "vnfd_package_version"
74 _MANIFEST_VNFD_RELEASE_DATE_TIME
= "vnfd_release_date_time"
75 _MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS
= (
76 "compatible_specification_versions"
78 _MANIFEST_VNFM_INFO
= "vnfm_info"
80 _MANIFEST_ALL_FIELDS
= [
82 _MANIFEST_VNFD_PRODUCT_NAME
,
83 _MANIFEST_VNFD_PROVIDER_ID
,
84 _MANIFEST_VNFD_SOFTWARE_VERSION
,
85 _MANIFEST_VNFD_PACKAGE_VERSION
,
86 _MANIFEST_VNFD_RELEASE_DATE_TIME
,
87 _MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS
,
91 def __init__(self
, package_path
=""):
92 super().__init
__(package_path
)
94 def generate_manifest_data_from_descriptor(self
):
95 descriptor_path
= os
.path
.join(
96 self
._package
_path
, self
.get_descriptor_location()
98 with
open(descriptor_path
, "r") as descriptor
:
100 vnfd_data
= yaml
.safe_load(descriptor
)["vnfd"]
101 except yaml
.YAMLError
as e
:
102 print("Error reading descriptor {}: {}".format(descriptor_path
, e
))
105 self
._manifest
_metadata
= {}
106 self
._manifest
_metadata
[self
._MANIFEST
_VNFD
_ID
] = vnfd_data
.get(
109 self
._manifest
_metadata
[self
._MANIFEST
_VNFD
_PRODUCT
_NAME
] = vnfd_data
.get(
110 "product-name", "default-product-name"
112 self
._manifest
_metadata
[self
._MANIFEST
_VNFD
_PROVIDER
_ID
] = vnfd_data
.get(
115 self
._manifest
_metadata
[
116 self
._MANIFEST
_VNFD
_SOFTWARE
_VERSION
117 ] = vnfd_data
.get("version", "1.0")
118 self
._manifest
_metadata
[self
._MANIFEST
_VNFD
_PACKAGE
_VERSION
] = "1.0.0"
119 self
._manifest
_metadata
[self
._MANIFEST
_VNFD
_RELEASE
_DATE
_TIME
] = (
120 datetime
.datetime
.now().astimezone().isoformat()
122 self
._manifest
_metadata
[
123 self
._MANIFEST
_VNFD
_COMPATIBLE
_SPECIFICATION
_VERSIONS
125 self
._manifest
_metadata
[self
._MANIFEST
_VNFM
_INFO
] = "OSM"