# Copyright (C) 2014 INRIA
#
# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
import base64
-import cPickle
+import pickle
import errno
import logging
import os
from optparse import OptionParser, SUPPRESS_HELP
-from netnswrapper import NetNSWrapper
+from nepi.resources.netns.netnswrapper import NetNSWrapper
class NetNSWrapperMessage:
CREATE = "CREATE"
while '\n' not in chunk:
try:
chunk = conn.recv(1024)
- except (OSError, socket.error), e:
+ except (OSError, socket.error) as e:
if e[0] != errno.EINTR:
raise
# Ignore eintr errors
def decode(item):
item = base64.b64decode(item).rstrip()
- return cPickle.loads(item)
+ return pickle.loads(item)
- decoded = map(decode, msg.split("|"))
+ decoded = list(map(decode, msg.split("|")))
# decoded message
dmsg_type = decoded.pop(0)
return (dmsg_type, dargs, dkwargs)
def send_reply(conn, reply):
- encoded = base64.b64encode(cPickle.dumps(reply))
+ encoded = base64.b64encode(pickle.dumps(reply))
conn.send("%s\n" % encoded)
def get_options():
enable_dump = False):
###### wrapper instantiation
+ if level == logging.DEBUG:
+ from syslog import LOG_DEBUG
+ import netns
+ netns.environ.set_log_level(LOG_DEBUG)
wrapper = NetNSWrapper(loglevel=level, enable_dump = enable_dump)
try:
(msg_type, args, kwargs) = recv_msg(conn)
- except socket.timeout, e:
+ except socket.timeout as e:
# Ingore time-out
continue
## configure logging
FORMAT = "%(asctime)s %(name)s %(levelname)-4s %(message)s"
level = logging.DEBUG if verbose else logging.INFO
-
+
logging.basicConfig(format = FORMAT, level = level)
## Run the server