2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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.
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
28 # https://creativecommons.org/licenses/by/4.0/
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.
36 # ============LICENSE_END============================================
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
48 from .utils import nested_dict
55 filepath - absolute path to template file.
56 envpath - absolute path to environmnt file.
59 def __init__(self, filepath=None, envpath=None):
64 self.heat_template_version = None
65 self.description = None
66 self.parameter_groups = None
67 self.parameters = None
70 self.conditions = None
75 self.load_env(envpath)
77 def load(self, filepath):
78 """Load the Heat template given a filepath.
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", {})
93 def load_env(self, envpath):
94 """Load the Environment template given a envpath.
96 self.env = Env(filepath=envpath)
99 def nested_get(dic, *keys):
100 """make utils.nested_dict.get available as a class method.
102 return nested_dict.get(dic, *keys)
106 """An Environment file
112 class Resource(object):
116 def __init__(self, resource_id=None, resource=None):
117 self.resource_id = resource_id or ""
118 self.resource = resource or {}
121 def get_index_var(resource):
122 """Return the index_var for this resource.
124 index_var = nested_dict.get(resource, "properties", "index_var") or "index"