1 ##############################################################################
2 # Copyright (c) 2017 Tim Rozet (trozet@redhat.com) and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
16 from apex.common.exceptions import ApexDeployException
18 """Parser functions for overcloud/openstack output"""
21 def parse_nova_output(in_file):
23 Parses nova list output into a dictionary format for node name and ip
24 :param in_file: json format from openstack server list
25 :return: dictionary format for {"node name": "node ip"}
27 if not os.path.isfile(in_file):
28 raise FileNotFoundError(in_file)
30 with open(in_file, 'r') as fh:
31 nova_list = json.load(fh)
33 for server in nova_list:
34 ip_match = re.search('([0-9]+\.){3}[0-9]+', server['Networks'])
36 logging.error("Unable to find IP in nova output "
37 "{}".format(pprint.pformat(server, indent=4)))
38 raise ApexDeployException("Unable to parse IP from nova output")
40 node_dict[server['Name']] = ip_match.group(0)
43 raise ApexDeployException("No overcloud nodes found in: {}".format(
48 def parse_overcloudrc(in_file):
50 Parses overcloudrc into a dictionary format for key and value
52 :return: dictionary format for {"variable": "value"}
54 logging.debug("Parsing overcloudrc file {}".format(in_file))
55 if not os.path.isfile(in_file):
56 raise FileNotFoundError(in_file)
58 with open(in_file, 'r') as fh:
59 lines = fh.readlines()
60 kv_pattern = re.compile('^export\s+([^\s]+)=([^\s]+)$')
62 if 'export' not in line:
65 res = re.search(kv_pattern, line.strip())
67 creds[res.group(1)] = res.group(2)
68 logging.debug("os cred found: {}, {}".format(res.group(1),
71 logging.debug("os cred not found in: {}".format(line))
76 def parse_ifcfg_file(in_file):
78 Parses ifcfg file information
80 :return: dictionary of ifcfg key value pairs
91 with open(in_file, 'r') as fh:
93 for param in ifcfg_params.keys():
94 match = re.search("^\s*{}=(.*)$".format(param), line)
96 ifcfg_params[param] = match.group(1)