tuning-box/tuning_box/library/levels_hierarchy.py
Alexander Kislitsky bbbc3d848f Resource values/overrides moved to library
Implementation of resource values operations moved to library.
Filtration of resource definition with respect to envirionment id
implemented.
Implementation of resource overrides operations moved to library.
All business logic finally moved from the app to the library.

Change-Id: If5d14699e56485761ca6c54bd8bbf34dd21e9155
2016-08-17 15:34:26 +00:00

42 lines
1.5 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.
import werkzeug
from tuning_box import db
def iter_environment_level_values(environment, levels):
env_levels = db.EnvironmentHierarchyLevel.get_for_environment(environment)
level_pairs = zip(env_levels, levels)
parent_level_value = None
for env_level, (level_name, level_value) in level_pairs:
if env_level.name != level_name:
raise werkzeug.exceptions.BadRequest(
"Unexpected level name '{0}'. Expected '{1}'.".format(
level_name, env_level.name))
level_value_db = db.get_or_create(
db.EnvironmentHierarchyLevelValue,
level=env_level,
parent=parent_level_value,
value=level_value,
)
yield level_value_db
parent_level_value = level_value_db
def get_environment_level_value(environment, levels):
level_value = None
for level_value in iter_environment_level_values(environment, levels):
pass
return level_value