deb-heat/heat/engine/parameter_groups.py
Steven Hardy 70112c103a Move logging to use oslo_log library
The oslo-incubator log modlule has been removed, so port to the oslo_log
library.  Note this uses the new (non namespaced, e.g oslo.log) import
convention, we'll need to align other imports in a future commit.

Some import reordering was required due to pedantic H30[57] checks, and
the services have all been converted to initialize the oslo_log library
as this is done differently to the log.py in incubator.

Change-Id: Ib5a97123fe1b287bc531e42d7887c13ba6205628
2015-02-17 09:23:34 +00:00

71 lines
2.7 KiB
Python

#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from heat.common import exception
from heat.common.i18n import _
LOG = logging.getLogger(__name__)
PARAMETER_GROUPS = 'parameter_groups'
PARAMETERS = 'parameters'
class ParameterGroups(object):
'''
The ParameterGroups specified by the stack's template.
'''
def __init__(self, tmpl):
self.tmpl = tmpl
self.parameters = tmpl.parameters(None, {}, param_defaults={})
LOG.debug(self.tmpl)
LOG.debug(self.parameters)
self.parameter_names = []
if self.parameters:
self.parameter_names = [param for param in self.parameters]
self.parameter_groups = tmpl.get(PARAMETER_GROUPS)
def validate(self):
'''
Validate that a parameter belongs to only one Parameter Group
and that each parameter name references a valid parameter.
'''
LOG.debug('Validating Parameter Groups.')
LOG.debug(self.parameter_names)
if self.parameter_groups is not None:
# Loop through groups and validate parameters
grouped_parameters = []
for group in self.parameter_groups:
parameters = group.get(PARAMETERS)
if parameters is None:
raise exception.StackValidationFailed(message=_(
'Parameters must be provided for '
'each Parameter Group.'))
for param in parameters:
# Check if param has been added to a previous group
if param in grouped_parameters:
raise exception.StackValidationFailed(message=_(
'The %s parameter must be assigned to one '
'Parameter Group only.') % param)
else:
grouped_parameters.append(param)
# Check that grouped parameter references a valid Parameter
if param not in self.parameter_names:
raise exception.StackValidationFailed(message=_(
'The Parameter name (%s) does not reference '
'an existing parameter.') % param)