1 # Copyright 2016 Cisco Systems, Inc. All rights reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
16 from attrdict import AttrDict
20 def config_load(file_name, from_cfg=None):
21 """Load a yaml file into a config dict, merge with from_cfg if not None
22 The config file content taking precedence in case of duplicate
25 with open(file_name) as fileobj:
26 cfg = AttrDict(yaml.safe_load(fileobj))
28 raise Exception("Configuration file at '{}' was not found. Please use correct path "
29 "and verify it is visible to container if you run nfvbench in container."
38 def config_loads(cfg_text, from_cfg=None):
39 """Same as config_load but load from a string
42 cfg = AttrDict(yaml.load(cfg_text))
52 cfg = config_load('a1.yaml')
53 cfg = config_load('a2.yaml', cfg)
54 cfg = config_loads('color: 500', cfg)