diff options
author | Zhijiang Hu <hu.zhijiang@zte.com.cn> | 2016-12-12 01:07:39 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2016-12-12 01:07:39 +0000 |
commit | a9d85c4781342979b3973515489c94364722f21e (patch) | |
tree | 3180b69590946f3896dd674290da9863fa4886fc /deploy | |
parent | 3c8cec8e50ff959a9a1091ef09c7c6372417e375 (diff) | |
parent | fe857e29005e12799ef50294ef673118b8b0d40e (diff) |
Merge "refactor get_conf"
Diffstat (limited to 'deploy')
-rwxr-xr-x | deploy/get_conf.py | 80 |
1 files changed, 23 insertions, 57 deletions
diff --git a/deploy/get_conf.py b/deploy/get_conf.py index d2b505c8..309b331b 100755 --- a/deploy/get_conf.py +++ b/deploy/get_conf.py @@ -16,56 +16,22 @@ def init(file): return yaml.safe_load(fd) -def networkdecorator(func): - def wrapter(s, seq): - network_list = s.get('networks', []) - result = {} - for network in network_list: - s = func(s, seq, network) - if not s: - continue - result.update(s) - if len(result) == 0: - return "" - else: +def decorator_mk(types): + def decorator(func): + def wrapter(s): + item_list = s.get(types, []) + result = {} + for item in item_list: + ret = func(item) + if ret: + result.update(ret) return result - return wrapter - - -def hostdecorator(func): - def wrapter(s, seq): - host_list = s.get('hosts', []) - result = {} - for host in host_list: - s = func(s, seq, host) - if not s: - continue - result.update(s) - if len(result) == 0: - return "" - else: - return result - return wrapter - - -def decorator(func): - def wrapter(s, seq): - host_list = s.get('hosts', []) - result = [] - for host in host_list: - s = func(s, seq, host) - if not s: - continue - result.append(s) - if len(result) == 0: - return "" - else: - return result - return wrapter + return wrapter + return decorator -@networkdecorator -def network(s, seq, network=None): +@decorator_mk('networks') +def network(network=None): net_plane = network.get('name', '') network.pop('name') map = {} @@ -73,8 +39,8 @@ def network(s, seq, network=None): return map -@hostdecorator -def interface(s, seq, host=None): +@decorator_mk('hosts') +def interface(host=None): hostname = host.get('name', '') interface = host.get('interface', '') map = {} @@ -82,8 +48,8 @@ def interface(s, seq, host=None): return map -@hostdecorator -def role(s, seq, host=None): +@decorator_mk('hosts') +def role(host=None): hostname = host.get('name', '') role = host.get('roles', '') map = {} @@ -91,8 +57,8 @@ def role(s, seq, host=None): return map -@decorator -def host(s, seq, host=None): +@decorator_mk('hosts') +def host(host=None): hostip = host.get('ip', []) passwd = host.get('password', []) map = {} @@ -101,15 +67,15 @@ def host(s, seq, host=None): def network_config_parse(s, dha_file): - network_map = network(s, ',') + network_map = network(s) vip = s.get('internal_vip') return network_map, vip def dha_config_parse(s, dha_file): - host_interface_map = interface(s, ',') - host_role_map = role(s, ',') - host_ip_passwd_map = host(s, ',') + host_interface_map = interface(s) + host_role_map = role(s) + host_ip_passwd_map = host(s) return host_interface_map, host_role_map, host_ip_passwd_map |