Load the glibc library only once for Pyroute2
Load the glibc library only once, needed in the Pyroute2 methods to
create and delete a network namespace.
Conflicts:
neutron/privileged/agent/linux/ip_lib.py
Change-Id: I95b7b7008f4788a98ef871c4b7aecea839ff2310
Closes-Bug: #1854462
(cherry picked from commit af8a812240
)
This commit is contained in:
parent
5ee6e5bb31
commit
0e14524c6b
|
@ -10,6 +10,8 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import ctypes
|
||||||
|
from ctypes import util as ctypes_util
|
||||||
import errno
|
import errno
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
@ -26,6 +28,15 @@ from neutron import privileged
|
||||||
|
|
||||||
_IP_VERSION_FAMILY_MAP = {4: socket.AF_INET, 6: socket.AF_INET6}
|
_IP_VERSION_FAMILY_MAP = {4: socket.AF_INET, 6: socket.AF_INET6}
|
||||||
|
|
||||||
|
_CDLL = None
|
||||||
|
|
||||||
|
|
||||||
|
def _get_cdll():
|
||||||
|
global _CDLL
|
||||||
|
if not _CDLL:
|
||||||
|
_CDLL = ctypes.CDLL(ctypes_util.find_library('c'), use_errno=True)
|
||||||
|
return _CDLL
|
||||||
|
|
||||||
|
|
||||||
def _get_scope_name(scope):
|
def _get_scope_name(scope):
|
||||||
"""Return the name of the scope (given as a number), or the scope number
|
"""Return the name of the scope (given as a number), or the scope number
|
||||||
|
@ -318,7 +329,7 @@ def create_netns(name, **kwargs):
|
||||||
:param name: The name of the namespace to create
|
:param name: The name of the namespace to create
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
netns.create(name, **kwargs)
|
netns.create(name, libc=_get_cdll())
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.EEXIST:
|
if e.errno != errno.EEXIST:
|
||||||
raise
|
raise
|
||||||
|
@ -332,6 +343,7 @@ def remove_netns(name, **kwargs):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
netns.remove(name, **kwargs)
|
netns.remove(name, **kwargs)
|
||||||
|
netns.remove(name, libc=_get_cdll())
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in New Issue