blob: 8a3cb95589f94612dac40b3ca646fc82591849fc [file] [log] [blame]
garciaale08395032021-01-15 13:04:05 -03001# -*- coding: utf-8 -*-
2
bravof98fc8f02021-11-04 21:16:00 -03003# Copyright 2021 Whitestack, LLC
garciaale08395032021-01-15 13:04:05 -03004# *************************************************************
5#
6# This file is part of OSM common repository.
7# All Rights Reserved to Whitestack, LLC
8#
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
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
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
19# under the License.
20#
21# For those usages not covered by the Apache License, Version 2.0 please
bravof98fc8f02021-11-04 21:16:00 -030022# contact: agarcia@whitestack.com or fbravo@whitestack.com
garciaale08395032021-01-15 13:04:05 -030023##
24
25"""Python module for interacting with ETSI GS NFV-SOL004 compliant packages
26
27This module provides a SOL004Package class for validating and interacting with
28ETSI SOL004 packages. A valid SOL004 package may have its files arranged according
29to one of the following two structures:
30
31SOL004 with metadata directory SOL004 without metadata directory
32
33native_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
39├── Files ├── Files
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
48 └── charms ├── hooks
49 └── simple │ ├── install
50 ├── config.yaml ...
51 ├── hooks │
52 │ ├── install └── src
53 ... └── charm.py
54 └── src
55 └── charm.py
56"""
57
bravof98fc8f02021-11-04 21:16:00 -030058import datetime
garciaale08395032021-01-15 13:04:05 -030059import os
aticig3dd0db62022-03-04 19:35:45 +030060
61import yaml
62
bravof98fc8f02021-11-04 21:16:00 -030063from .sol_package import SOLPackage
garciaale08395032021-01-15 13:04:05 -030064
65
66class SOL004PackageException(Exception):
67 pass
68
69
bravof98fc8f02021-11-04 21:16:00 -030070class SOL004Package(SOLPackage):
71 _MANIFEST_VNFD_ID = "vnfd_id"
72 _MANIFEST_VNFD_PRODUCT_NAME = "vnfd_product_name"
73 _MANIFEST_VNFD_PROVIDER_ID = "vnfd_provider_id"
74 _MANIFEST_VNFD_SOFTWARE_VERSION = "vnfd_software_version"
75 _MANIFEST_VNFD_PACKAGE_VERSION = "vnfd_package_version"
76 _MANIFEST_VNFD_RELEASE_DATE_TIME = "vnfd_release_date_time"
77 _MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS = (
78 "compatible_specification_versions"
79 )
80 _MANIFEST_VNFM_INFO = "vnfm_info"
81
82 _MANIFEST_ALL_FIELDS = [
83 _MANIFEST_VNFD_ID,
84 _MANIFEST_VNFD_PRODUCT_NAME,
85 _MANIFEST_VNFD_PROVIDER_ID,
86 _MANIFEST_VNFD_SOFTWARE_VERSION,
87 _MANIFEST_VNFD_PACKAGE_VERSION,
88 _MANIFEST_VNFD_RELEASE_DATE_TIME,
89 _MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS,
90 _MANIFEST_VNFM_INFO,
91 ]
92
garciadeblas2644b762021-03-24 09:21:01 +010093 def __init__(self, package_path=""):
bravof98fc8f02021-11-04 21:16:00 -030094 super().__init__(package_path)
garciaale08395032021-01-15 13:04:05 -030095
bravof98fc8f02021-11-04 21:16:00 -030096 def generate_manifest_data_from_descriptor(self):
97 descriptor_path = os.path.join(
98 self._package_path, self.get_descriptor_location()
garciadeblas2644b762021-03-24 09:21:01 +010099 )
bravof98fc8f02021-11-04 21:16:00 -0300100 with open(descriptor_path, "r") as descriptor:
101 try:
102 vnfd_data = yaml.safe_load(descriptor)["vnfd"]
103 except yaml.YAMLError as e:
104 print("Error reading descriptor {}: {}".format(descriptor_path, e))
105 return
garciaale08395032021-01-15 13:04:05 -0300106
bravof98fc8f02021-11-04 21:16:00 -0300107 self._manifest_metadata = {}
108 self._manifest_metadata[self._MANIFEST_VNFD_ID] = vnfd_data.get(
109 "id", "default-id"
garciadeblas2644b762021-03-24 09:21:01 +0100110 )
bravof98fc8f02021-11-04 21:16:00 -0300111 self._manifest_metadata[self._MANIFEST_VNFD_PRODUCT_NAME] = vnfd_data.get(
112 "product-name", "default-product-name"
garciadeblas2644b762021-03-24 09:21:01 +0100113 )
bravof98fc8f02021-11-04 21:16:00 -0300114 self._manifest_metadata[self._MANIFEST_VNFD_PROVIDER_ID] = vnfd_data.get(
115 "provider", "OSM"
garciadeblas2644b762021-03-24 09:21:01 +0100116 )
bravof98fc8f02021-11-04 21:16:00 -0300117 self._manifest_metadata[
118 self._MANIFEST_VNFD_SOFTWARE_VERSION
119 ] = vnfd_data.get("version", "1.0")
120 self._manifest_metadata[self._MANIFEST_VNFD_PACKAGE_VERSION] = "1.0.0"
121 self._manifest_metadata[self._MANIFEST_VNFD_RELEASE_DATE_TIME] = (
122 datetime.datetime.now().astimezone().isoformat()
garciadeblas2644b762021-03-24 09:21:01 +0100123 )
bravof98fc8f02021-11-04 21:16:00 -0300124 self._manifest_metadata[
125 self._MANIFEST_VNFD_COMPATIBLE_SPECIFICATION_VERSIONS
126 ] = "2.7.1"
127 self._manifest_metadata[self._MANIFEST_VNFM_INFO] = "OSM"