From 9b8a9a7135284019e214916d3e4626104db66cd0 Mon Sep 17 00:00:00 2001 From: zhuyj17 Date: Sun, 27 May 2018 17:09:09 +0800 Subject: [PATCH] Tidy worker codes --- src/com/log.py | 2 -- src/{ => com}/model.py | 2 +- src/master/network.py | 4 ++-- src/{ => worker}/monitor.py | 9 ++++----- src/worker/worker.py | 9 ++++++--- 5 files changed, 13 insertions(+), 13 deletions(-) rename src/{ => com}/model.py (99%) rename src/{ => worker}/monitor.py (99%) diff --git a/src/com/log.py b/src/com/log.py index ddb2ee1..46568e1 100755 --- a/src/com/log.py +++ b/src/com/log.py @@ -32,7 +32,6 @@ def initlogging(name='docklet'): LOG_LEVEL = logging.CRITIAL else: LOG_LEVEL = logging.DEBUG - logger = logging.getLogger(name) # Configure logging to log to a file, making a new file at midnight and keeping the last 3 day's data # Give the logger a unique name (good practice) @@ -47,7 +46,6 @@ def initlogging(name='docklet'): handler.setFormatter(formatter) # Attach the handler to the logger logger.addHandler(handler) - # Replace stdout with logging to file at INFO level sys.stdout = RedirectLogger(logger, logging.INFO) # Replace stderr with logging to file at ERROR level diff --git a/src/model.py b/src/com/model.py similarity index 99% rename from src/model.py rename to src/com/model.py index 6dafa35..fcc1ac9 100755 --- a/src/model.py +++ b/src/com/model.py @@ -34,7 +34,7 @@ import os, json from itsdangerous import TimedJSONWebSignatureSerializer as Serializer from itsdangerous import SignatureExpired, BadSignature -import env +from com import env fsdir = env.getenv('FS_PREFIX') diff --git a/src/master/network.py b/src/master/network.py index 5e9e7c2..ef7924d 100755 --- a/src/master/network.py +++ b/src/master/network.py @@ -1,9 +1,9 @@ #!/usr/bin/python3 import json, sys, netifaces, threading -from nettools import netcontrol,ovscontrol +from com.nettools import netcontrol,ovscontrol -from log import logger +from com.log import logger # getip : get ip from network interface # ifname : name of network interface diff --git a/src/monitor.py b/src/worker/monitor.py similarity index 99% rename from src/monitor.py rename to src/worker/monitor.py index 65aa4f5..c0793b1 100755 --- a/src/monitor.py +++ b/src/worker/monitor.py @@ -17,18 +17,17 @@ Design:Monitor mainly consists of three parts: Collectors, Master_Collector and ''' -import subprocess,re,os,etcdlib,psutil,math,sys +import subprocess,re,os,psutil,math,sys import time,threading,json,traceback,platform -import env +from com import env, etcdlib import lxc import xmlrpc.client from datetime import datetime -from model import db,VNode,History,BillingHistory,VCluster,PortMapping -from log import logger +from com.model import db,VNode,History,BillingHistory,VCluster,PortMapping +from com.log import logger from httplib2 import Http from urllib.parse import urlencode -from httprest import post_to_user # billing parameters a_cpu = 500 # seconds diff --git a/src/worker/worker.py b/src/worker/worker.py index 0e9828f..a6305b3 100755 --- a/src/worker/worker.py +++ b/src/worker/worker.py @@ -2,14 +2,16 @@ # first init env import sys -sys.path.append("../") +if sys.path[0].endswith("worker"): + sys.path[0] = sys.path[0][:-6] from com import env, tools config = env.getenv("CONFIG") -#tools.loadenv(config) +#config = "/opt/docklet/local/docklet-running.conf" +tools.loadenv(config) # must import logger after initlogging, ugly from com.log import initlogging -#initlogging("docklet-worker") +initlogging("docklet-worker") from com.log import logger import xmlrpc.server, sys, time @@ -19,6 +21,7 @@ from com import etcdlib, proxytool from worker import container, monitor from com.nettools import netcontrol,ovscontrol,portcontrol from worker.lvmtool import new_group, recover_group +from master import network ################################################################## # Worker