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.
46 from tests import cached_yaml as yaml
48 from .utils import nested_dict
55 filepath - absolute path to template file.
56 envpath - absolute path to environmnt file.
58 def __init__(self, filepath=None, envpath=None):
63 self.heat_template_version = None
64 self.description = None
65 self.parameter_groups = None
66 self.parameters = None
69 self.conditions = None
74 self.load_env(envpath)
76 def load(self, filepath):
77 """Load the Heat template given a filepath.
79 self.filepath = filepath
80 self.basename = os.path.basename(self.filepath)
81 self.dirname = os.path.dirname(self.filepath)
82 with open(self.filepath) as fi:
83 self.yml = yaml.load(fi)
84 self.heat_template_version = self.yml.get('heat_template_version', None)
85 self.description = self.yml.get('description', '')
86 self.parameter_groups = self.yml.get('parameter_groups', {})
87 self.parameters = self.yml.get('parameters', {})
88 self.resources = self.yml.get('resources', {})
89 self.outputs = self.yml.get('outputs', {})
90 self.conditions = self.yml.get('conditions', {})
92 def load_env(self, envpath):
93 """Load the Environment template given a envpath.
95 self.env = Env(filepath=envpath)
98 def nested_get(dic, *keys):
99 """make utils.nested_dict.get available as a class method.
101 return nested_dict.get(dic, *keys)
105 """An Environment file
110 class Resource(object):
113 def __init__(self, resource_id=None, resource=None):
114 self.resource_id = resource_id or ''
115 self.resource = resource or {}
118 def get_index_var(resource):
119 """Return the index_var for this resource.
121 index_var = nested_dict.get(resource,
123 'index_var') or 'index'