1 # Copyright ETSI Contributors and Others.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 """Python module for interacting with ETSI GS NFV-SOL007 compliant packages.
18 This module provides a SOL007Package class for validating and interacting with
19 ETSI SOL007 packages. A valid SOL007 package may have its files arranged according
20 to one of the following two structures:
22 SOL007 with metadata directory SOL007 without metadata directory
24 native_charm_vnf/ native_charm_vnf/
25 ├── TOSCA-Metadata ├── native_charm_nsd.mf
26 │ └── TOSCA.meta ├── native_charm_nsd.yaml
27 ├── manifest.mf ├── ChangeLog.txt
28 ├── Definitions ├── Licenses
29 │ └── native_charm_nsd.yaml │ └── license.lic
31 │ ├── icons │ └── icons
32 │ │ └── osm.png │ └── osm.png
33 │ ├── Licenses └── Scripts
34 │ │ └── license.lic ├── cloud_init
35 │ └── changelog.txt │ └── cloud-config.txt
36 └── Scripts └── charms
37 ├── cloud_init └── simple
38 │ └── cloud-config.txt ├── config.yaml
40 └── simple │ ├── install
52 from .sol_package
import SOLPackage
55 class SOL007PackageException(Exception):
59 class SOL007Package(SOLPackage
):
60 _MANIFEST_NSD_INVARIANT_ID
= "nsd_invariant_id"
61 _MANIFEST_NSD_NAME
= "nsd_name"
62 _MANIFEST_NSD_DESIGNER
= "nsd_designer"
63 _MANIFEST_NSD_FILE_STRUCTURE_VERSION
= "nsd_file_structure_version"
64 _MANIFEST_NSD_RELEASE_DATE_TIME
= "nsd_release_date_time"
65 _MANIFEST_NSD_COMPATIBLE_SPECIFICATION_VERSIONS
= (
66 "compatible_specification_versions"
69 _MANIFEST_ALL_FIELDS
= [
70 _MANIFEST_NSD_INVARIANT_ID
,
72 _MANIFEST_NSD_DESIGNER
,
73 _MANIFEST_NSD_FILE_STRUCTURE_VERSION
,
74 _MANIFEST_NSD_RELEASE_DATE_TIME
,
75 _MANIFEST_NSD_COMPATIBLE_SPECIFICATION_VERSIONS
,
78 def __init__(self
, package_path
=""):
79 super().__init
__(package_path
)
81 def generate_manifest_data_from_descriptor(self
):
82 descriptor_path
= os
.path
.join(
83 self
._package
_path
, self
.get_descriptor_location()
85 with
open(descriptor_path
, "r") as descriptor
:
87 nsd_data
= yaml
.safe_load(descriptor
)["nsd"]
88 except yaml
.YAMLError
as e
:
89 print("Error reading descriptor {}: {}".format(descriptor_path
, e
))
92 self
._manifest
_metadata
= {}
93 self
._manifest
_metadata
[self
._MANIFEST
_NSD
_INVARIANT
_ID
] = nsd_data
.get(
96 self
._manifest
_metadata
[self
._MANIFEST
_NSD
_NAME
] = nsd_data
.get(
97 "name", "default-name"
99 self
._manifest
_metadata
[self
._MANIFEST
_NSD
_DESIGNER
] = nsd_data
.get(
102 self
._manifest
_metadata
[
103 self
._MANIFEST
_NSD
_FILE
_STRUCTURE
_VERSION
104 ] = nsd_data
.get("version", "1.0")
105 self
._manifest
_metadata
[self
._MANIFEST
_NSD
_RELEASE
_DATE
_TIME
] = (
106 datetime
.datetime
.now().astimezone().isoformat()
108 self
._manifest
_metadata
[
109 self
._MANIFEST
_NSD
_COMPATIBLE
_SPECIFICATION
_VERSIONS