merged latest from rel/5.1
This commit is contained in:
commit
615b723270
16 changed files with 165 additions and 751 deletions
|
@ -1,18 +1,27 @@
|
|||
import os
|
||||
|
||||
COREDPY_VERSION = "@PACKAGE_VERSION@"
|
||||
CORE_STATE_DIR = "@CORE_STATE_DIR@"
|
||||
CORE_CONF_DIR = "@CORE_CONF_DIR@"
|
||||
CORE_DATA_DIR = "@CORE_DATA_DIR@"
|
||||
CORE_LIB_DIR = "@CORE_LIB_DIR@"
|
||||
|
||||
VNODED_BIN = "@bindir@/vnoded"
|
||||
VCMD_BIN = "@bindir@/vcmd"
|
||||
BRCTL_BIN = "@brctl_path@/brctl"
|
||||
SYSCTL_BIN = "@sysctl_path@/sysctl"
|
||||
IP_BIN = "@ip_path@/ip"
|
||||
TC_BIN = "@tc_path@/tc"
|
||||
EBTABLES_BIN = "@ebtables_path@/ebtables"
|
||||
QUAGGA_STATE_DIR = "@CORE_STATE_DIR@/run/quagga"
|
||||
MOUNT_BIN = "@mount_path@/mount"
|
||||
UMOUNT_BIN = "@umount_path@/umount"
|
||||
OVS_BIN = "@ovs_vs_path@/ovs-vsctl"
|
||||
OVS_FLOW_BIN = "@ovs_of_path@/ovs-ofctl"
|
||||
|
||||
|
||||
def which(command):
|
||||
for path in os.environ["PATH"].split(os.pathsep):
|
||||
command_path = os.path.join(path, command)
|
||||
if os.path.isfile(command_path) and os.access(command_path, os.X_OK):
|
||||
return command_path
|
||||
|
||||
|
||||
VNODED_BIN = which("vnoded")
|
||||
VCMD_BIN = which("vcmd")
|
||||
BRCTL_BIN = which("brctl")
|
||||
SYSCTL_BIN = which("sysctl")
|
||||
IP_BIN = which("ip")
|
||||
TC_BIN = which("tc")
|
||||
EBTABLES_BIN = which("ebtables")
|
||||
MOUNT_BIN = which("mount")
|
||||
UMOUNT_BIN = which("umount")
|
||||
OVS_BIN = which("ovs-vsctl")
|
||||
OVS_FLOW_BIN = which("ovs-ofctl")
|
||||
|
|
|
@ -360,8 +360,6 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
|
|||
"""
|
||||
try:
|
||||
header = self.request.recv(coreapi.CoreMessage.header_len)
|
||||
if len(header) > 0:
|
||||
logger.debug("received message header: %s", utils.hex_dump(header))
|
||||
except IOError as e:
|
||||
raise IOError("error receiving header (%s)" % e)
|
||||
|
||||
|
@ -378,7 +376,6 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
|
|||
data = ""
|
||||
while len(data) < message_len:
|
||||
data += self.request.recv(message_len - len(data))
|
||||
logger.debug("received message data: %s" % utils.hex_dump(data))
|
||||
if len(data) > message_len:
|
||||
error_message = "received message length does not match received data (%s != %s)" % (
|
||||
len(data), message_len)
|
||||
|
@ -492,7 +489,7 @@ class CoreRequestHandler(SocketServer.BaseRequestHandler):
|
|||
# TODO: hack to associate this handler with this sessions broker for broadcasting
|
||||
# TODO: broker needs to be pulled out of session to the server/handler level
|
||||
if self.master:
|
||||
logger.info("SESSION SET TO MASTER!")
|
||||
logger.info("session set to master")
|
||||
self.session.master = True
|
||||
self.session.broker.session_clients.append(self)
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ Defines server classes and request handlers for TCP and UDP.
|
|||
"""
|
||||
|
||||
import SocketServer
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
@ -72,14 +71,6 @@ class CoreServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
|
|||
for session in self.sessions.values():
|
||||
session.shutdown()
|
||||
|
||||
# if we are a daemon remove pid file
|
||||
if self.config["daemonize"]:
|
||||
pid_file = self.config["pidfile"]
|
||||
try:
|
||||
os.unlink(pid_file)
|
||||
except OSError:
|
||||
logger.exception("error daemon pid file: %s", pid_file)
|
||||
|
||||
# remove server from server list
|
||||
CoreServer.remove_server(self)
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import subprocess
|
|||
import sys
|
||||
|
||||
import fcntl
|
||||
import resource
|
||||
|
||||
from core import CoreCommandError
|
||||
from core import logger
|
||||
|
@ -340,95 +339,6 @@ def sysctl_devname(devname):
|
|||
return devname.replace(".", "/")
|
||||
|
||||
|
||||
def daemonize(rootdir="/", umask=0, close_fds=False, dontclose=(),
|
||||
stdin=os.devnull, stdout=os.devnull, stderr=os.devnull,
|
||||
stdoutmode=0644, stderrmode=0644, pidfilename=None,
|
||||
defaultmaxfd=1024):
|
||||
"""
|
||||
Run the background process as a daemon.
|
||||
|
||||
:param str rootdir: root directory for daemon
|
||||
:param int umask: umask for daemon
|
||||
:param bool close_fds: flag to close file descriptors
|
||||
:param dontclose: dont close options
|
||||
:param stdin: stdin for daemon
|
||||
:param stdout: stdout for daemon
|
||||
:param stderr: stderr for daemon
|
||||
:param int stdoutmode: stdout mode
|
||||
:param int stderrmode: stderr mode
|
||||
:param str pidfilename: pid file name
|
||||
:param int defaultmaxfd: default max file descriptors
|
||||
:return: nothing
|
||||
"""
|
||||
if not hasattr(dontclose, "__contains__"):
|
||||
if not isinstance(dontclose, int):
|
||||
raise TypeError("dontclose must be an integer")
|
||||
dontclose = (int(dontclose),)
|
||||
else:
|
||||
for fd in dontclose:
|
||||
if not isinstance(fd, int):
|
||||
raise TypeError("dontclose must contain only integers")
|
||||
|
||||
# redirect stdin
|
||||
if stdin:
|
||||
fd = os.open(stdin, os.O_RDONLY)
|
||||
os.dup2(fd, 0)
|
||||
os.close(fd)
|
||||
|
||||
# redirect stdout
|
||||
if stdout:
|
||||
fd = os.open(stdout, os.O_WRONLY | os.O_CREAT | os.O_APPEND,
|
||||
stdoutmode)
|
||||
os.dup2(fd, 1)
|
||||
if stdout == stderr:
|
||||
os.dup2(1, 2)
|
||||
os.close(fd)
|
||||
|
||||
# redirect stderr
|
||||
if stderr and (stderr != stdout):
|
||||
fd = os.open(stderr, os.O_WRONLY | os.O_CREAT | os.O_APPEND,
|
||||
stderrmode)
|
||||
os.dup2(fd, 2)
|
||||
os.close(fd)
|
||||
|
||||
if os.fork():
|
||||
# parent exits
|
||||
os._exit(0)
|
||||
|
||||
os.setsid()
|
||||
pid = os.fork()
|
||||
if pid:
|
||||
if pidfilename:
|
||||
try:
|
||||
f = open(pidfilename, "w")
|
||||
f.write("%s\n" % pid)
|
||||
f.close()
|
||||
except IOError:
|
||||
logger.exception("error writing to file: %s", pidfilename)
|
||||
# parent exits
|
||||
os._exit(0)
|
||||
|
||||
if rootdir:
|
||||
os.chdir(rootdir)
|
||||
|
||||
os.umask(umask)
|
||||
if close_fds:
|
||||
try:
|
||||
maxfd = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
||||
if maxfd == resource.RLIM_INFINITY:
|
||||
raise ValueError
|
||||
except:
|
||||
maxfd = defaultmaxfd
|
||||
|
||||
for fd in xrange(3, maxfd):
|
||||
if fd in dontclose:
|
||||
continue
|
||||
try:
|
||||
os.close(fd)
|
||||
except IOError:
|
||||
logger.exception("error closing file descriptor")
|
||||
|
||||
|
||||
def load_config(filename, d):
|
||||
"""
|
||||
Read key=value pairs from a file, into a dict. Skip comments; strip newline characters and spacing.
|
||||
|
|
|
@ -138,8 +138,9 @@ class SimpleLxcNode(PyCoreNode):
|
|||
try:
|
||||
os.kill(self.pid, signal.SIGTERM)
|
||||
os.waitpid(self.pid, 0)
|
||||
except OSError:
|
||||
logger.exception("error killing process")
|
||||
except OSError as e:
|
||||
if e.errno != 10:
|
||||
logger.exception("error killing process")
|
||||
|
||||
# remove node directory if present
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue