1 |
|
# -*- coding: utf-8 -*- |
2 |
|
|
3 |
|
# Copyright 2021 Whitestack, LLC |
4 |
|
# ************************************************************* |
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 |
22 |
|
# contact: fbravo@whitestack.com |
23 |
|
## |
24 |
|
|
25 |
0 |
"""Python module for interacting with ETSI GS NFV-SOL007 compliant packages |
26 |
|
|
27 |
|
This module provides a SOL007Package class for validating and interacting with |
28 |
|
ETSI SOL007 packages. A valid SOL007 package may have its files arranged according |
29 |
|
to one of the following two structures: |
30 |
|
|
31 |
|
SOL007 with metadata directory SOL007 without metadata directory |
32 |
|
|
33 |
|
native_charm_vnf/ native_charm_vnf/ |
34 |
|
├── TOSCA-Metadata ├── native_charm_nsd.mf |
35 |
|
│ └── TOSCA.meta ├── native_charm_nsd.yaml |
36 |
|
├── manifest.mf ├── ChangeLog.txt |
37 |
|
├── Definitions ├── Licenses |
38 |
|
│ └── native_charm_nsd.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 |
|
|
58 |
0 |
import datetime |
59 |
0 |
import os |
60 |
|
|
61 |
0 |
import yaml |
62 |
|
|
63 |
0 |
from .sol_package import SOLPackage |
64 |
|
|
65 |
|
|
66 |
0 |
class SOL007PackageException(Exception): |
67 |
0 |
pass |
68 |
|
|
69 |
|
|
70 |
0 |
class SOL007Package(SOLPackage): |
71 |
0 |
_MANIFEST_NSD_INVARIANT_ID = "nsd_invariant_id" |
72 |
0 |
_MANIFEST_NSD_NAME = "nsd_name" |
73 |
0 |
_MANIFEST_NSD_DESIGNER = "nsd_designer" |
74 |
0 |
_MANIFEST_NSD_FILE_STRUCTURE_VERSION = "nsd_file_structure_version" |
75 |
0 |
_MANIFEST_NSD_RELEASE_DATE_TIME = "nsd_release_date_time" |
76 |
0 |
_MANIFEST_NSD_COMPATIBLE_SPECIFICATION_VERSIONS = ( |
77 |
|
"compatible_specification_versions" |
78 |
|
) |
79 |
|
|
80 |
0 |
_MANIFEST_ALL_FIELDS = [ |
81 |
|
_MANIFEST_NSD_INVARIANT_ID, |
82 |
|
_MANIFEST_NSD_NAME, |
83 |
|
_MANIFEST_NSD_DESIGNER, |
84 |
|
_MANIFEST_NSD_FILE_STRUCTURE_VERSION, |
85 |
|
_MANIFEST_NSD_RELEASE_DATE_TIME, |
86 |
|
_MANIFEST_NSD_COMPATIBLE_SPECIFICATION_VERSIONS, |
87 |
|
] |
88 |
|
|
89 |
0 |
def __init__(self, package_path=""): |
90 |
0 |
super().__init__(package_path) |
91 |
|
|
92 |
0 |
def generate_manifest_data_from_descriptor(self): |
93 |
0 |
descriptor_path = os.path.join( |
94 |
|
self._package_path, self.get_descriptor_location() |
95 |
|
) |
96 |
0 |
with open(descriptor_path, "r") as descriptor: |
97 |
0 |
try: |
98 |
0 |
nsd_data = yaml.safe_load(descriptor)["nsd"] |
99 |
0 |
except yaml.YAMLError as e: |
100 |
0 |
print("Error reading descriptor {}: {}".format(descriptor_path, e)) |
101 |
0 |
return |
102 |
|
|
103 |
0 |
self._manifest_metadata = {} |
104 |
0 |
self._manifest_metadata[self._MANIFEST_NSD_INVARIANT_ID] = nsd_data.get( |
105 |
|
"id", "default-id" |
106 |
|
) |
107 |
0 |
self._manifest_metadata[self._MANIFEST_NSD_NAME] = nsd_data.get( |
108 |
|
"name", "default-name" |
109 |
|
) |
110 |
0 |
self._manifest_metadata[self._MANIFEST_NSD_DESIGNER] = nsd_data.get( |
111 |
|
"designer", "OSM" |
112 |
|
) |
113 |
0 |
self._manifest_metadata[ |
114 |
|
self._MANIFEST_NSD_FILE_STRUCTURE_VERSION |
115 |
|
] = nsd_data.get("version", "1.0") |
116 |
0 |
self._manifest_metadata[self._MANIFEST_NSD_RELEASE_DATE_TIME] = ( |
117 |
|
datetime.datetime.now().astimezone().isoformat() |
118 |
|
) |
119 |
0 |
self._manifest_metadata[ |
120 |
|
self._MANIFEST_NSD_COMPATIBLE_SPECIFICATION_VERSIONS |
121 |
|
] = "2.7.1" |