tidy worker codes

This commit is contained in:
zhuyj17 2018-05-27 15:52:45 +08:00
parent fbe88b0cbb
commit c486930d8f
12 changed files with 37 additions and 38 deletions

View File

@ -20,12 +20,11 @@ from configparser import ConfigParser
from io import StringIO
import os,sys,subprocess,time,re,datetime,threading,random
import xmlrpc.client
from model import db, Image
from com.model import db, Image
from log import logger
import env
from lvmtool import *
import updatebase
from com.log import logger
from com import env, updatebase
from worker.lvmtool import *
import requests
master_port = str(env.getenv('MASTER_PORT'))

View File

@ -6,7 +6,7 @@ import argparse
import sys
import time # this is only being used as part of the example
import os
import env
from com import env
# logger should only be imported after initlogging has been called
logger = None
@ -17,7 +17,7 @@ def initlogging(name='docklet'):
homepath = env.getenv('FS_PREFIX')
LOG_FILENAME = homepath + '/local/log/' + name + '.log'
LOG_LIFE = env.getenv('LOG_LIFE')
LOG_LEVEL = env.getenv('LOG_LEVEL')
if LOG_LEVEL == "DEBUG":

View File

@ -1,7 +1,8 @@
#!/usr/bin/python3
import subprocess, env, threading
from log import logger
import subprocess, threading
from com.log import logger
from com import env
class ipcontrol(object):
@staticmethod

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3
import requests, json
import env
from com import env
proxy_api_port = env.getenv("PROXY_API_PORT")
proxy_control="http://localhost:"+ str(proxy_api_port) +"/api/routes"
@ -22,7 +22,7 @@ def set_route(path, target):
except:
return [False, 'Connect Failed']
return [True, 'set ok']
def delete_route(path):
path='/'+path.strip('/')
try:

View File

@ -1,7 +1,7 @@
#!/usr/bin/python3
import os, shutil
from log import logger
from com.log import logger
def aufs_remove(basefs):
try:

View File

@ -1,12 +1,10 @@
#!/usr/bin/python3
import subprocess, os, json
import imagemgr
import network
from log import logger
import env
from lvmtool import sys_run, check_volume
from monitor import Container_Collector, History_Manager
from com.log import logger
from com import env, imagemgr
from worker.lvmtool import sys_run, check_volume
from worker.monitor import Container_Collector, History_Manager
import lxc
class Container(object):

View File

@ -1,7 +1,8 @@
#!/usr/bin/python3
import env,subprocess,os,time
from log import logger
import subprocess,os,time
from com.log import logger
from com import env
def sys_run(command,check=False):
Ret = subprocess.run(command, stdout = subprocess.PIPE, stderr = subprocess.STDOUT, shell=True, check=check)
@ -45,12 +46,12 @@ def new_group(group_name, size = "5000", file_path = "/opt/docklet/local/docklet
logger.error(e)
logger.info("initialize lvm group:%s with size %sM success" % (group_name,size))
return True
elif storage == "disk":
disk = env.getenv("DISK")
if disk is None:
logger.error("use disk for story without a physical disk")
return False
return False
#check vg
Ret = sys_run("vgdisplay " + group_name)
if Ret.returncode == 0:
@ -63,8 +64,8 @@ def new_group(group_name, size = "5000", file_path = "/opt/docklet/local/docklet
except Exception as e:
logger.error(e)
logger.info("initialize lvm group:%s with size %sM success" % (group_name,size))
return True
return True
else:
logger.info("unknown storage type:" + storage)
return False
@ -85,7 +86,7 @@ def recover_group(group_name,file_path="/opt/docklet/local/docklet-storage"):
time.sleep(1)
#recover vg
Ret = sys_run("vgdisplay " + group_name)
if Ret.returncode != 0:
if Ret.returncode != 0:
Ret = sys_run("vgcreate %s /dev/loop0" % group_name)
if Ret.returncode != 0:
logger.error("create VG %s failed:%s" % (group_name,Ret.stdout.decode('utf-8')))
@ -96,10 +97,10 @@ def recover_group(group_name,file_path="/opt/docklet/local/docklet-storage"):
disk = env.getenv("DISK")
if disk is None:
logger.error("use disk for story without a physical disk")
return False
return False
#recover vg
Ret = sys_run("vgdisplay " + group_name)
if Ret.returncode != 0:
if Ret.returncode != 0:
Ret = sys_run("vgcreate %s %s" % (group_name,disk))
if Ret.returncode != 0:
logger.error("create VG %s failed:%s" % (group_name,Ret.stdout.decode('utf-8')))
@ -161,5 +162,3 @@ def delete_volume(group_name, volume_name):
return False
else:
logger.info("lv %s in vg %s does not exists" % (volume_name,group_name))

View File

@ -1,22 +1,24 @@
#!/usr/bin/python3
# first init env
import env, tools
import sys
sys.path.append("../")
from com import env, tools
config = env.getenv("CONFIG")
tools.loadenv(config)
#tools.loadenv(config)
# must import logger after initlogging, ugly
from log import initlogging
initlogging("docklet-worker")
from log import logger
from com.log import initlogging
#initlogging("docklet-worker")
from com.log import logger
import xmlrpc.server, sys, time
from socketserver import ThreadingMixIn
import threading
import etcdlib, network, container
from nettools import netcontrol,ovscontrol,portcontrol
import monitor, proxytool
from lvmtool import new_group, recover_group
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
##################################################################
# Worker