[VVP] Added new three new reports
[vvp/validation-scripts.git] / ice_validator / tests / structures.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
7 #
8 # Unless otherwise specified, all software contained herein is licensed
9 # under the Apache License, Version 2.0 (the "License");
10 # you may not use this software except in compliance with the License.
11 # You may obtain 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,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20 #
21 #
22 #
23 # Unless otherwise specified, all documentation contained herein is licensed
24 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 # you may not use this documentation except in compliance with the License.
26 # You may obtain a copy of the License at
27 #
28 #             https://creativecommons.org/licenses/by/4.0/
29 #
30 # Unless required by applicable law or agreed to in writing, documentation
31 # distributed under the License is distributed on an "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 # See the License for the specific language governing permissions and
34 # limitations under the License.
35 #
36 # ============LICENSE_END============================================
37 #
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
39 #
40
41 """structures
42 """
43
44 import os
45
46 import yaml
47
48 from .utils import nested_dict
49
50 VERSION = "1.4.0"
51
52
53 class Heat(object):
54     """A Heat template.
55     filepath - absolute path to template file.
56     envpath - absolute path to environmnt file.
57     """
58
59     def __init__(self, filepath=None, envpath=None):
60         self.filepath = None
61         self.basename = None
62         self.dirname = None
63         self.yml = None
64         self.heat_template_version = None
65         self.description = None
66         self.parameter_groups = None
67         self.parameters = None
68         self.resources = None
69         self.outputs = None
70         self.conditions = None
71         if filepath:
72             self.load(filepath)
73         self.env = None
74         if envpath:
75             self.load_env(envpath)
76
77     def load(self, filepath):
78         """Load the Heat template given a filepath.
79         """
80         self.filepath = filepath
81         self.basename = os.path.basename(self.filepath)
82         self.dirname = os.path.dirname(self.filepath)
83         with open(self.filepath) as fi:
84             self.yml = yaml.load(fi)
85         self.heat_template_version = self.yml.get("heat_template_version", None)
86         self.description = self.yml.get("description", "")
87         self.parameter_groups = self.yml.get("parameter_groups", {})
88         self.parameters = self.yml.get("parameters", {})
89         self.resources = self.yml.get("resources", {})
90         self.outputs = self.yml.get("outputs", {})
91         self.conditions = self.yml.get("conditions", {})
92
93     def load_env(self, envpath):
94         """Load the Environment template given a envpath.
95         """
96         self.env = Env(filepath=envpath)
97
98     @staticmethod
99     def nested_get(dic, *keys):
100         """make utils.nested_dict.get available as a class method.
101         """
102         return nested_dict.get(dic, *keys)
103
104
105 class Env(Heat):
106     """An Environment file
107     """
108
109     pass
110
111
112 class Resource(object):
113     """A Resource
114     """
115
116     def __init__(self, resource_id=None, resource=None):
117         self.resource_id = resource_id or ""
118         self.resource = resource or {}
119
120     @staticmethod
121     def get_index_var(resource):
122         """Return the index_var for this resource.
123         """
124         index_var = nested_dict.get(resource, "properties", "index_var") or "index"
125         return index_var