summaryrefslogtreecommitdiffstats
path: root/deploy/get_conf.py
diff options
context:
space:
mode:
authorYao Lu <lu.yao135@zte.com.cn>2016-11-17 16:02:52 +0800
committerYao Lu <lu.yao135@zte.com.cn>2016-11-19 09:36:40 +0000
commitea776f2faf1d99c49d3dcf256fd0eda840c83639 (patch)
tree45429fe147e03fb99446faa688bf29242c416c04 /deploy/get_conf.py
parent463ab9c7337079a68491d2eccb1e3778a8ec4479 (diff)
add common config and parse it to prepare deploy
Change-Id: I864082b885a4c7117f0b546da602e9580e8ccf46 Signed-off-by: Yao Lu <lu.yao135@zte.com.cn>
Diffstat (limited to 'deploy/get_conf.py')
-rwxr-xr-xdeploy/get_conf.py123
1 files changed, 123 insertions, 0 deletions
diff --git a/deploy/get_conf.py b/deploy/get_conf.py
new file mode 100755
index 00000000..37cacb51
--- /dev/null
+++ b/deploy/get_conf.py
@@ -0,0 +1,123 @@
+#!/usr/bin/python
+##############################################################################
+# Copyright (c) 2016 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# lu.yao135@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import yaml
+
+
+def init(file):
+ with open(file) as fd:
+ return yaml.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:
+ 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
+
+
+@networkdecorator
+def network(s, seq, network=None):
+ net_plane = network.get('name', '')
+ network.pop('name')
+ map = {}
+ map[net_plane] = network
+ return map
+
+
+@hostdecorator
+def interface(s, seq, host=None):
+ hostname = host.get('name', '')
+ interface = host.get('interface', '')[0]
+ map = {}
+ map[hostname] = interface
+ return map
+
+
+@hostdecorator
+def role(s, seq, host=None):
+ hostname = host.get('name', '')
+ role = host.get('roles', '')
+ map = {}
+ map[hostname] = role
+ return map
+
+
+@decorator
+def host(s, seq, host=None):
+ hostip = host.get('ip', [])
+ passwd = host.get('password', [])
+ map = {}
+ map = {'ip': hostip, 'passwd': passwd}
+ return map
+
+
+def network_config_parse(s, dha_file):
+ 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, ',')
+ return host_interface_map, host_role_map, host_ip_passwd_map
+
+
+def config(dha_file, network_file):
+ data = init(dha_file)
+ host_interface_map, host_role_map, host_ip_passwd_map = \
+ dha_config_parse(data, dha_file)
+ data = init(network_file)
+ network_map, vip = network_config_parse(data, network_file)
+ return host_interface_map, host_role_map, \
+ host_ip_passwd_map, network_map, vip