Fix flushing error on container stop
This commit is contained in:
@@ -7,6 +7,8 @@ import time
|
||||
import threading
|
||||
import subprocess
|
||||
|
||||
from os import path
|
||||
|
||||
import pyroute2
|
||||
from pyroute2.netlink.rtnl import rtypes
|
||||
import docker
|
||||
@@ -333,10 +335,13 @@ class ContainerDHCPManager:
|
||||
def _on_event(self, dhcp, event_type, _event):
|
||||
if event_type == udhcpc.EventType.DECONFIG:
|
||||
logger.info('[dhcp container] DECONFIG Event %s', _event)
|
||||
if path.lexists('{dhcp.netns}'):
|
||||
logger.info('[dhcp container] Flushing IP addresses')
|
||||
subprocess.check_call(['nsenter', f'-n{dhcp.netns}', '--', '/sbin/ip', 'address', 'flush', 'dev',
|
||||
str(dhcp.iface['ifname'])], timeout=1, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL)
|
||||
else:
|
||||
logger.info('[dhcp container] Container gone, can\'t flush IP addresses')
|
||||
elif event_type == udhcpc.EventType.RENEW or event_type == udhcpc.EventType.BOUND:
|
||||
if event_type == udhcpc.EventType.RENEW:
|
||||
logger.info('[dhcp container] RENEW Event %s', _event)
|
||||
|
||||
Reference in New Issue
Block a user