Enable Removal of veths
This commit is contained in:
+31
-12
@@ -129,6 +129,35 @@ def endpoint_container_network_gwpriority(n, e):
|
||||
return 0
|
||||
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'])
|
||||
def net_get_capabilities():
|
||||
return jsonify({
|
||||
@@ -265,18 +294,8 @@ def endpoint_info():
|
||||
def delete_endpoint():
|
||||
req = request.get_json(force=True)
|
||||
|
||||
if_host, _if_container = veth_pair(req['EndpointID'])
|
||||
if_host = interface.GetInterface(LIBRARY, 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)
|
||||
if_host, _ = veth_pair(req['EndpointID'])
|
||||
remove_veth(if_host)
|
||||
|
||||
return jsonify({})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user