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