Initial commit
[ta/config-manager.git] / cmframework / test / mocked_dependencies / cmdatahandlers / api / utils.py
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 def is_virtualized():
17     return False
18
19
20 def get_own_hwmgmt_ip():
21     return '1.2.3.4'
22
23
24 def flatten_config_data(jsondata):
25     result = {}
26     for key, value in jsondata.iteritems():
27         try:
28             result[key] = json.dumps(value)
29         except Exception as exp:
30             result[key] = value
31     return result
32
33
34 def unflatten_config_data(props):
35     propsjson = {}
36     for name, value in props.iteritems():
37         try:
38             propsjson[name] = json.loads(value)
39         except Exception as exp:
40             propsjson[name] = value
41     return propsjson