2016-03-31 16:03:38 +08:00
|
|
|
from flask import session
|
|
|
|
from webViews.view import normalView
|
|
|
|
from webViews.dockletrequest import dockletRequest
|
|
|
|
|
|
|
|
|
|
|
|
class statusView(normalView):
|
|
|
|
template_path = "monitor/status.html"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
2016-08-10 17:16:45 +08:00
|
|
|
data = {}
|
2017-04-09 18:18:12 +08:00
|
|
|
allclusters = dockletRequest.post_to_all('/cluster/list/')
|
|
|
|
for master in allclusters:
|
|
|
|
allclusters[master] = allclusters[master].get('clusters')
|
2017-11-20 00:40:27 +08:00
|
|
|
result = dockletRequest.post('/user/selfQuery/')
|
|
|
|
quotas = result['data']['groupinfo']
|
|
|
|
quotanames = quotas.keys()
|
|
|
|
'''result = dockletRequest.post('/monitor/user/quotainfo/', data)
|
2016-04-14 15:52:44 +08:00
|
|
|
quotainfo = result.get('quotainfo')
|
2016-04-18 10:35:04 +08:00
|
|
|
quotainfo['cpu'] = int(int(quotainfo['cpu']))
|
2017-11-20 00:40:27 +08:00
|
|
|
print(quotainfo)'''
|
2017-04-09 18:18:12 +08:00
|
|
|
allcontainers = {}
|
2016-03-31 16:03:38 +08:00
|
|
|
if (result):
|
|
|
|
containers = {}
|
2017-04-09 18:18:12 +08:00
|
|
|
for master in allclusters:
|
|
|
|
allcontainers[master] = {}
|
|
|
|
for cluster in allclusters[master]:
|
|
|
|
data["clustername"] = cluster
|
|
|
|
message = dockletRequest.post('/cluster/info/', data, master.split("@")[0])
|
|
|
|
if (message):
|
|
|
|
message = message.get('message')
|
|
|
|
else:
|
|
|
|
self.error()
|
|
|
|
allcontainers[master][cluster] = message
|
2017-11-20 00:40:27 +08:00
|
|
|
return self.render(self.template_path, quotas = quotas, quotanames = quotanames, allcontainers = allcontainers, user = session['username'])
|
2016-03-31 16:03:38 +08:00
|
|
|
else:
|
|
|
|
self.error()
|
|
|
|
|
|
|
|
class statusRealtimeView(normalView):
|
|
|
|
template_path = "monitor/statusRealtime.html"
|
|
|
|
node_name = ""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
2017-04-09 18:18:12 +08:00
|
|
|
masterip = self.masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/basic_info/'%(self.node_name), data, masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
basic_info = result.get('monitor').get('basic_info')
|
2017-04-09 18:18:12 +08:00
|
|
|
return self.render(self.template_path, node_name = self.node_name, user = session['username'], container = basic_info, masterip=masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
|
2016-07-24 13:51:01 +08:00
|
|
|
class historyView(normalView):
|
|
|
|
template_path = "monitor/history.html"
|
2017-11-20 00:40:27 +08:00
|
|
|
|
2016-08-07 17:10:18 +08:00
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2017-04-09 18:18:12 +08:00
|
|
|
allvnodes = {}
|
|
|
|
result = dockletRequest.post_to_all('/monitor/user/createdvnodes/', data)
|
|
|
|
for master in result:
|
|
|
|
allvnodes[master] = result[master].get('createdvnodes')
|
|
|
|
return self.render(self.template_path, user = session['username'],allvnodes = allvnodes)
|
2016-08-07 17:10:18 +08:00
|
|
|
|
|
|
|
class historyVNodeView(normalView):
|
|
|
|
template_path = "monitor/historyVNode.html"
|
2016-07-24 13:51:01 +08:00
|
|
|
vnode_name = ""
|
2017-11-20 00:40:27 +08:00
|
|
|
|
2016-07-24 13:51:01 +08:00
|
|
|
@classmethod
|
|
|
|
def get(self):
|
2017-04-09 18:18:12 +08:00
|
|
|
masterip = self.masterip
|
2016-07-24 13:51:01 +08:00
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/history/'%(self.vnode_name), data, masterip)
|
2016-07-24 13:51:01 +08:00
|
|
|
history = result.get('monitor').get('history')
|
|
|
|
return self.render(self.template_path, vnode_name = self.vnode_name, user = session['username'], history = history)
|
|
|
|
|
2016-03-31 16:03:38 +08:00
|
|
|
class hostsRealtimeView(normalView):
|
|
|
|
template_path = "monitor/hostsRealtime.html"
|
|
|
|
com_ip = ""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
2017-04-09 18:18:12 +08:00
|
|
|
masterip = self.masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/cpuconfig/'%(self.com_ip), data,masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
proc = result.get('monitor').get('cpuconfig')
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/osinfo/'%(self.com_ip), data,masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
osinfo = result.get('monitor').get('osinfo')
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/diskinfo/'%(self.com_ip), data,masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
diskinfos = result.get('monitor').get('diskinfo')
|
|
|
|
|
2017-04-09 18:18:12 +08:00
|
|
|
return self.render(self.template_path, com_ip = self.com_ip, user = session['username'],processors = proc, OSinfo = osinfo, diskinfos = diskinfos, masterip = masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
|
|
|
|
class hostsConAllView(normalView):
|
|
|
|
template_path = "monitor/hostsConAll.html"
|
|
|
|
com_ip = ""
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
2017-04-09 18:18:12 +08:00
|
|
|
masterip = self.masterip
|
2016-03-31 16:03:38 +08:00
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/containerslist/'%(self.com_ip), data, masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
containers = result.get('monitor').get('containerslist')
|
|
|
|
containerslist = []
|
|
|
|
for container in containers:
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/basic_info/'%(container), data, masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
basic_info = result.get('monitor').get('basic_info')
|
2017-04-09 18:18:12 +08:00
|
|
|
result = dockletRequest.post('/monitor/vnodes/%s/owner/'%(container), data, masterip)
|
2016-04-25 01:00:06 +08:00
|
|
|
owner = result.get('monitor')
|
2016-04-23 16:37:15 +08:00
|
|
|
basic_info['owner'] = owner
|
2016-03-31 16:03:38 +08:00
|
|
|
containerslist.append(basic_info)
|
2017-04-09 18:18:12 +08:00
|
|
|
return self.render(self.template_path, containerslist = containerslist, com_ip = self.com_ip, user = session['username'], masterip = masterip)
|
2016-03-31 16:03:38 +08:00
|
|
|
|
|
|
|
class hostsView(normalView):
|
|
|
|
template_path = "monitor/hosts.html"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2017-04-09 18:18:12 +08:00
|
|
|
allresult = dockletRequest.post_to_all('/monitor/listphynodes/', data)
|
|
|
|
allmachines = {}
|
|
|
|
for master in allresult:
|
|
|
|
allmachines[master] = []
|
|
|
|
iplist = allresult[master].get('monitor').get('allnodes')
|
|
|
|
for ip in iplist:
|
|
|
|
containers = {}
|
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/containers/'%(ip), data, master.split("@")[0])
|
|
|
|
containers = result.get('monitor').get('containers')
|
|
|
|
result = dockletRequest.post('/monitor/hosts/%s/status/'%(ip), data, master.split("@")[0])
|
|
|
|
status = result.get('monitor').get('status')
|
|
|
|
allmachines[master].append({'ip':ip,'containers':containers, 'status':status})
|
2016-03-31 16:03:38 +08:00
|
|
|
#print(machines)
|
2017-04-09 18:18:12 +08:00
|
|
|
return self.render(self.template_path, allmachines = allmachines, user = session['username'])
|
2016-03-31 16:03:38 +08:00
|
|
|
|
|
|
|
class monitorUserAllView(normalView):
|
|
|
|
template_path = "monitor/monitorUserAll.html"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get(self):
|
|
|
|
data = {
|
|
|
|
"user": session['username'],
|
|
|
|
}
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/listphynodes/', data)
|
2016-03-31 16:03:38 +08:00
|
|
|
userslist = [{'name':'root'},{'name':'libao'}]
|
|
|
|
for user in userslist:
|
2016-04-27 15:59:33 +08:00
|
|
|
result = dockletRequest.post('/monitor/user/%s/clustercnt/'%(user['name']), data)
|
2016-03-31 16:03:38 +08:00
|
|
|
user['clustercnt'] = result.get('monitor').get('clustercnt')
|
|
|
|
return self.render(self.template_path, userslist = userslist, user = session['username'])
|