Files
fuel-octane/octane/util/helpers.py
Ilya Kharin b1b4fb084c Use load_yaml to get the astute content
Change-Id: Ib2b04ee06b6fbcc72b76f6a759d950f20b5df469
(cherry picked from commit e235f4012d)
2016-08-16 09:13:24 +00:00

52 lines
1.6 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 re
import yaml
def merge_dicts(base_dict, update_dict):
result = base_dict.copy()
for key, val in update_dict.iteritems():
if key not in result or not isinstance(result[key], dict):
result[key] = val
else:
result[key] = merge_dicts(result[key], val)
return result
def get_astute_dict():
return load_yaml("/etc/fuel/astute.yaml")
def load_yaml(filename):
with open(filename, "r") as f:
return yaml.load(f)
def iterate_parameters(fp):
section = None
for line in fp:
match = re.match(r'^\s*\[(?P<section>[^\]]+)', line)
if match:
section = match.group('section')
yield line, section, None, None
continue
match = re.match(r'^\s*(?P<parameter>[^=\s]+)\s*='
'\s*(?P<value>[^\s.+](?:\s*[^\s.+])*)\s*$', line)
if match:
parameter, value = match.group("parameter", "value")
yield line, section, parameter, value
continue
yield line, section, None, None