feature: sol004 and sol007
[osm/osmclient.git] / osmclient / common / sol004_package.py
1 # Copyright ETSI Contributors and Others.
2 #
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
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
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
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 """Python module for interacting with ETSI GS NFV-SOL004 compliant packages.
17
18 This module provides a SOL004Package class for validating and interacting with
19 ETSI SOL004 packages. A valid SOL004 package may have its files arranged according
20 to one of the following two structures:
21
22 SOL004 with metadata directory SOL004 without metadata directory
23
24 native_charm_vnf/ native_charm_vnf/
25 ├── TOSCA-Metadata ├── native_charm_vnfd.mf
26 │ └── TOSCA.meta ├── native_charm_vnfd.yaml
27 ├── manifest.mf ├── ChangeLog.txt
28 ├── Definitions ├── Licenses
29 │ └── native_charm_vnfd.yaml │ └── license.lic
30 ├── Files ├── Files
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
39 └── charms ├── hooks
40 └── simple │ ├── install
41 ├── config.yaml ...
42 ├── hooks │
43 │ ├── install └── src
44 ... └── charm.py
45 └── src
46 └── charm.py
47 """
48
49 import yaml
50 import datetime
51 import os
52 from .sol_package import SOLPackage
53
54
55 class SOL004PackageException(Exception):
56 pass
57
58
59 class SOL004Package(SOLPackage):
60 _MANIFEST_VNFD_ID = "vnfd_id"
61 _MANIFEST_VNFD_PRODUCT_NAME = "vnfd_product_name"
62 _MANIFEST_VNFD_PROVIDER_ID = "vnfd_provider_id"
63 _MANIFEST_VNFD_SOFTWARE_VERSION = "vnfd_software_version"
64 _MANIFEST_VNFD_PACKAGE_VERSION = "vnfd_package_version"
65 _MANIFEST_VNFD_RELEASE_DATE_TIME = "vnfd_release_date_time"
66 _MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS = (
67 "compatible_specification_versions"
68 )
69 _MANIFEST_VNFM_INFO = "vnfm_info"
70
71 _MANIFEST_ALL_FIELDS = [
72 _MANIFEST_VNFD_ID,
73 _MANIFEST_VNFD_PRODUCT_NAME,
74 _MANIFEST_VNFD_PROVIDER_ID,
75 _MANIFEST_VNFD_SOFTWARE_VERSION,
76 _MANIFEST_VNFD_PACKAGE_VERSION,
77 _MANIFEST_VNFD_RELEASE_DATE_TIME,
78 _MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS,
79 _MANIFEST_VNFM_INFO,
80 ]
81
82 def __init__(self, package_path=""):
83 super().__init__(package_path)
84
85 def generate_manifest_data_from_descriptor(self):
86 descriptor_path = os.path.join(
87 self._package_path, self.get_descriptor_location()
88 )
89 with open(descriptor_path, "r") as descriptor:
90 try:
91 vnfd_data = yaml.safe_load(descriptor)["vnfd"]
92 except yaml.YAMLError as e:
93 print("Error reading descriptor {}: {}".format(descriptor_path, e))
94 return
95
96 self._manifest_metadata = {}
97 self._manifest_metadata[self._MANIFEST_VNFD_ID] = vnfd_data.get(
98 "id", "default-id"
99 )
100 self._manifest_metadata[self._MANIFEST_VNFD_PRODUCT_NAME] = vnfd_data.get(
101 "product-name", "default-product-name"
102 )
103 self._manifest_metadata[self._MANIFEST_VNFD_PROVIDER_ID] = vnfd_data.get(
104 "provider", "OSM"
105 )
106 self._manifest_metadata[
107 self._MANIFEST_VNFD_SOFTWARE_VERSION
108 ] = vnfd_data.get("version", "1.0")
109 self._manifest_metadata[self._MANIFEST_VNFD_PACKAGE_VERSION] = "1.0.0"
110 self._manifest_metadata[self._MANIFEST_VNFD_RELEASE_DATE_TIME] = (
111 datetime.datetime.now().astimezone().isoformat()
112 )
113 self._manifest_metadata[
114 self._MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS
115 ] = "2.7.1"
116 self._manifest_metadata[self._MANIFEST_VNFM_INFO] = "OSM"