Fix a bug of data read from file in container.py

This commit is contained in:
Firmlyzhu 2018-12-19 16:00:15 +08:00
parent 2e250b5cb2
commit 0cf2574d14
1 changed files with 5 additions and 10 deletions

View File

@ -6,6 +6,7 @@ from utils import env, imagemgr
from utils.lvmtool import sys_run, check_volume from utils.lvmtool import sys_run, check_volume
from worker.monitor import Container_Collector, History_Manager from worker.monitor import Container_Collector, History_Manager
import lxc import lxc
from utils import model
class Container(object): class Container(object):
def __init__(self, addr, etcdclient): def __init__(self, addr, etcdclient):
@ -320,17 +321,11 @@ IP=%s
# list containers in FS_PREFIX/global/... on this host as global # list containers in FS_PREFIX/global/... on this host as global
def diff_containers(self): def diff_containers(self):
[status, localcontainers] = self.list_containers() [status, localcontainers] = self.list_containers()
globalpath = self.fspath+"/global/users/" containers = model.Container.query.all()
users = os.listdir(globalpath)
globalcontainers = [] globalcontainers = []
for user in users: for con in containers:
clusters = os.listdir(globalpath+user+"/clusters") if con.host == self.addr:
for cluster in clusters: globalcontainers.append(con.containername)
clusterfile = open(globalpath+user+"/clusters/"+cluster, 'r')
clusterinfo = json.loads(clusterfile.read())
for container in clusterinfo['containers']:
if container['host'] == self.addr:
globalcontainers.append(container['containername'])
both = [] both = []
onlylocal = [] onlylocal = []
onlyglobal = [] onlyglobal = []