Skip to content

Commit cfe7ed7

Browse files
committed
IPv6 addr handling for setipalias
1 parent 29e2f44 commit cfe7ed7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

templates/octaviaamphoracontroller/bin/setipalias.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/python3
22
import sys
33
import os
4+
import ipaddress
45
from pyroute2 import IPRoute
56

67
try:
@@ -30,12 +31,15 @@
3031
sys.exit(1)
3132

3233
ipfile = open(filename, "r")
33-
ipaddress = ipfile.read()
34+
ipaddr = ipfile.read()
3435
ipfile.close()
35-
if ipaddress:
36+
if ipaddr:
3637
current_addresses = ip.get_addr(label=interface_name)
3738
# TODO(beagles): check IPv6, IIUC the library will do some translation of
3839
# mask but it might not be what we want.
39-
if ipaddress not in current_addresses:
40-
ip.addr('add', index = octavia_interface[0], address=ipaddress, mask=32)
40+
if ipaddr not in current_addresses:
41+
mask_value = 32
42+
if ipaddress.ip_address(ipaddr).version == 6:
43+
mask_value = 128
44+
ip.addr('add', index = octavia_interface[0], address=ipaddr, mask=mask_value)
4145
ip.close()

0 commit comments

Comments
 (0)