Browse Source

Merge "Implement "list_ns_pids" inside Neutron" into stable/stein

tags/14.2.0
Zuul 2 months ago
committed by Gerrit Code Review
parent
commit
64de8049ad
1 changed files with 30 additions and 0 deletions
  1. +30
    -0
      neutron/privileged/agent/linux/ip_lib.py

+ 30
- 0
neutron/privileged/agent/linux/ip_lib.py View File

@@ -12,6 +12,7 @@

import errno
import functools
import os
import socket

from neutron_lib import constants
@@ -35,6 +36,8 @@ LOG = logging.getLogger(__name__)

_IP_VERSION_FAMILY_MAP = {4: socket.AF_INET, 6: socket.AF_INET6}

NETNS_RUN_DIR = '/var/run/netns'


@lockutils.synchronized("privileged-ip-lib")
# NOTE(slaweq): Because of issue with pyroute2.NetNS objects running in threads
@@ -205,6 +208,33 @@ def open_namespace(namespace):
pass


@privileged.default.entrypoint
def list_ns_pids(namespace):
"""List namespace process PIDs

Based on Pyroute2.netns.ns_pids(). Remove when
https://github.com/svinota/pyroute2/issues/633 is fixed.
"""
ns_pids = []
try:
ns_path = os.path.join(NETNS_RUN_DIR, namespace)
ns_inode = os.stat(ns_path).st_ino
except OSError:
return ns_pids

for pid in os.listdir('/proc'):
if not pid.isdigit():
continue
try:
pid_path = os.path.join('/proc', pid, 'ns', 'net')
if os.stat(pid_path).st_ino == ns_inode:
ns_pids.append(int(pid))
except OSError:
continue

return ns_pids


def _translate_ip_device_exception(e, device=None, namespace=None):
if e.code == errno.ENODEV:
raise NetworkInterfaceNotFound(device=device, namespace=namespace)


Loading…
Cancel
Save