Skip to content

Commit 0317087

Browse files
committed
Fix addr exists check on the network attachment
Fixes a bug where the setipalias cannot be re-run in a pod. Should not be an issue during normal use but useful for testing and debugging.
1 parent cfe7ed7 commit 0317087

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

templates/octaviaamphoracontroller/bin/setipalias.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import os
44
import ipaddress
5+
import netifaces
56
from pyroute2 import IPRoute
67

78
try:
@@ -34,9 +35,10 @@
3435
ipaddr = ipfile.read()
3536
ipfile.close()
3637
if ipaddr:
37-
current_addresses = ip.get_addr(label=interface_name)
38-
# TODO(beagles): check IPv6, IIUC the library will do some translation of
39-
# mask but it might not be what we want.
38+
# Get our current addresses so we can avoid trying to set the
39+
# same address again.
40+
ifaceinfo = netifaces.ifaddresses(interface_name)[netifaces.AF_INET]
41+
current_addresses = [x['addr'] for x in ifaceinfo]
4042
if ipaddr not in current_addresses:
4143
mask_value = 32
4244
if ipaddress.ip_address(ipaddr).version == 6:

0 commit comments

Comments
 (0)