diff --git a/src/env.py b/src/com/env.py similarity index 100% rename from src/env.py rename to src/com/env.py diff --git a/src/etcdlib.py b/src/com/etcdlib.py similarity index 100% rename from src/etcdlib.py rename to src/com/etcdlib.py diff --git a/src/imagemgr.py b/src/com/imagemgr.py similarity index 99% rename from src/imagemgr.py rename to src/com/imagemgr.py index 0e97f6d..86f66fb 100755 --- a/src/imagemgr.py +++ b/src/com/imagemgr.py @@ -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')) diff --git a/src/log.py b/src/com/log.py similarity index 99% rename from src/log.py rename to src/com/log.py index ccf2bb7..ddb2ee1 100755 --- a/src/log.py +++ b/src/com/log.py @@ -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": diff --git a/src/nettools.py b/src/com/nettools.py similarity index 99% rename from src/nettools.py rename to src/com/nettools.py index ee5f8ba..98621b3 100755 --- a/src/nettools.py +++ b/src/com/nettools.py @@ -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 diff --git a/src/proxytool.py b/src/com/proxytool.py similarity index 97% rename from src/proxytool.py rename to src/com/proxytool.py index b1d4f0e..69b071c 100755 --- a/src/proxytool.py +++ b/src/com/proxytool.py @@ -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: diff --git a/src/tools.py b/src/com/tools.py similarity index 100% rename from src/tools.py rename to src/com/tools.py diff --git a/src/updatebase.py b/src/com/updatebase.py similarity index 99% rename from src/updatebase.py rename to src/com/updatebase.py index a811c8b..7c54e4e 100755 --- a/src/updatebase.py +++ b/src/com/updatebase.py @@ -1,7 +1,7 @@ #!/usr/bin/python3 import os, shutil -from log import logger +from com.log import logger def aufs_remove(basefs): try: diff --git a/src/network.py b/src/master/network.py similarity index 100% rename from src/network.py rename to src/master/network.py diff --git a/src/container.py b/src/worker/container.py similarity index 98% rename from src/container.py rename to src/worker/container.py index 9f78861..203e150 100755 --- a/src/container.py +++ b/src/worker/container.py @@ -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): diff --git a/src/lvmtool.py b/src/worker/lvmtool.py similarity index 96% rename from src/lvmtool.py rename to src/worker/lvmtool.py index c030a2d..7a83933 100755 --- a/src/lvmtool.py +++ b/src/worker/lvmtool.py @@ -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)) - - diff --git a/src/worker.py b/src/worker/worker.py similarity index 96% rename from src/worker.py rename to src/worker/worker.py index a629cbc..0e9828f 100755 --- a/src/worker.py +++ b/src/worker/worker.py @@ -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