Use netifaces instead of facter to find ip address

Currently, neutron_350.py is using parsed output of `facter -p` in
prescript_000.py which is actually not working fine in terms of getting
the ip of a interface.

This patch is using netifaces python library instead to get the ip
address which is much easier to use and reliable.

Note that netifaces was already a requirement in packstack so it's
included in requirements.txt and as package requirement.

Change-Id: Id4d2b4ca814129c485f491ed91bb6bb99e462114
Resolves: rhbz#1734354
This commit is contained in:
Alfredo Moralejo 2020-09-24 13:33:22 +02:00
parent 3048287985
commit 7ef539bc37

View File

@ -16,7 +16,7 @@
Installs and configures Neutron Installs and configures Neutron
""" """
import re import netifaces
from packstack.installer import basedefs from packstack.installer import basedefs
from packstack.installer import utils from packstack.installer import utils
from packstack.installer import validators from packstack.installer import validators
@ -807,11 +807,10 @@ def create_manifests(config, messages):
n_host, config) n_host, config)
else: else:
iface = config['CONFIG_NEUTRON_OVS_TUNNEL_IF'] iface = config['CONFIG_NEUTRON_OVS_TUNNEL_IF']
ifip = ("ipaddress_%s" % iface)
ifip = re.sub(r'[\.\-\:]', '_', ifip)
try: try:
src_host = config['HOST_DETAILS'][n_host][ifip] src_host = (netifaces.ifaddresses(iface)
except KeyError: [netifaces.AF_INET][0]['addr'])
except Exception:
raise KeyError('Couldn\'t detect ipaddress of ' raise KeyError('Couldn\'t detect ipaddress of '
'interface %s on node %s' % 'interface %s on node %s' %
(iface, n_host)) (iface, n_host))