Merge "Load the glibc library only once for Pyroute2"
This commit is contained in:
commit
c627d0773f
|
@ -10,6 +10,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import ctypes
|
||||
from ctypes import util as ctypes_util
|
||||
import errno
|
||||
import functools
|
||||
import os
|
||||
|
@ -35,6 +37,15 @@ _IP_VERSION_FAMILY_MAP = {4: socket.AF_INET, 6: socket.AF_INET6}
|
|||
|
||||
NETNS_RUN_DIR = '/var/run/netns'
|
||||
|
||||
_CDLL = None
|
||||
|
||||
|
||||
def _get_cdll():
|
||||
global _CDLL
|
||||
if not _CDLL:
|
||||
_CDLL = ctypes.CDLL(ctypes_util.find_library('c'), use_errno=True)
|
||||
return _CDLL
|
||||
|
||||
|
||||
@lockutils.synchronized("privileged-ip-lib")
|
||||
# NOTE(slaweq): Because of issue with pyroute2.NetNS objects running in threads
|
||||
|
@ -503,7 +514,7 @@ def create_netns(name, **kwargs):
|
|||
:param name: The name of the namespace to create
|
||||
"""
|
||||
try:
|
||||
netns.create(name, **kwargs)
|
||||
netns.create(name, libc=_get_cdll())
|
||||
except OSError as e:
|
||||
if e.errno != errno.EEXIST:
|
||||
raise
|
||||
|
@ -516,7 +527,7 @@ def remove_netns(name, **kwargs):
|
|||
:param name: The name of the namespace to remove
|
||||
"""
|
||||
try:
|
||||
netns.remove(name, **kwargs)
|
||||
netns.remove(name, libc=_get_cdll())
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
raise
|
||||
|
|
Loading…
Reference in New Issue