Advertise the correct address when using IPv6

Parse the output of "ip route get $IP" taking
IPv6 into consideration. Also wrap the IP address
in square brackets if it is IPv6.

Change-Id: Ifc44e5aa3c5b814b6ceba04461bb68fe1d75c22b
Closes-Bug: #1650533
This commit is contained in:
Derek Higgins
2016-12-16 12:59:55 +00:00
parent a6b09f2fa8
commit 9f5f664080
7 changed files with 85 additions and 2 deletions

@ -22,6 +22,7 @@ import sys
import netifaces
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import netutils
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
@ -213,3 +214,9 @@ def interface_has_carrier(interface_name):
LOG.debug('No carrier information for interface %s',
interface_name)
return False
def wrap_ipv6(ip):
if netutils.is_valid_ipv6(ip):
return "[%s]" % ip
return ip