Enable Removal of veths

This commit is contained in:
2026-01-28 21:30:57 +01:00
parent 990027ac86
commit eaa2e4a378
+31 -12
View File
@@ -129,6 +129,35 @@ def endpoint_container_network_gwpriority(n, e):
return 0 return 0
return None return None
def remove_veth(host_ifname):
logger.info('Removing veth %s', host_ifname)
if LIBRARY == 'NDB':
if_host = interface.GetInterface(LIBRARY, if_host)
bridge = net_bridge(req['NetworkID'])
interface.DelPort(LIBRARY, bridge.ifname, if_host.ifname)
interface.RemoveInterface(LIBRARY, if_host.ifname)
logger.info('Removed veth for endpoint %s on ()', endpoint)
else:
logger.info('Deleting veth via shell: %s', host_ifname)
try:
subprocess.run(
['ip', 'link', 'del', host_ifname],
stdout=subprocess.DEVNULL,
stderr=subprocess.PIPE,
check=True
)
logger.info('Deleted veth %s', host_ifname)
except subprocess.CalledProcessError as e:
if b'Cannot find device' in e.stderr:
logger.info('Veth %s already gone', host_ifname)
else:
logger.warning(
'Failed to delete veth %s: %s',
host_ifname,
e.stderr.decode().strip()
)
@app.route('/NetworkDriver.GetCapabilities', methods=['POST']) @app.route('/NetworkDriver.GetCapabilities', methods=['POST'])
def net_get_capabilities(): def net_get_capabilities():
return jsonify({ return jsonify({
@@ -265,18 +294,8 @@ def endpoint_info():
def delete_endpoint(): def delete_endpoint():
req = request.get_json(force=True) req = request.get_json(force=True)
if_host, _if_container = veth_pair(req['EndpointID']) if_host, _ = veth_pair(req['EndpointID'])
if_host = interface.GetInterface(LIBRARY, if_host) remove_veth(if_host)
try:
if LIBRARY == 'NDB':
bridge = net_bridge(req['NetworkID'])
interface.DelPort(LIBRARY, bridge.ifname, if_host.ifname)
else:
interface.DelPort(LIBRARY, 'dummy0', if_host.ifname)
interface.RemoveInterface(LIBRARY, if_host.ifname)
except Exception as e:
logger.exception(e)
return jsonify({}) return jsonify({})