def GET(self): highlight = '<span class="highlight">%s</span>' healthy = '<span class="healthy">%s</span>' lowlight = '<span class="lowlight">%s</span>' def get_status(prefix, serv_list): running_list = [x for x in serv_list if x['status'] == 'running'] stopped_list = [x for x in serv_list if x['status'] == 'shutoff'] total = len(serv_list) running = len(running_list) stopped = len(stopped_list) delta = total - running - stopped result = '%s[%d/%d]' % (prefix, running, total) if total > 0 and running == total: result = '<a type=%s>%s</a>' % (prefix.lower(), healthy % result) elif total > 0 and running != total: if delta == 0: result = '<a type=%s>%s</a>' % (prefix.lower(), highlight % result) else: result = '<a type=%s>%s</a>' % (prefix.lower(), lowlight % result) else: result = '' return result def analyse_srvc(): ######################################################################## serv_status = ' '.join([ get_status('C60', services['c60']), get_status('MDS', services['mds']), get_status('RJNLD', services['rjnld']), get_status('CDS', services['cds']) ]) fs_status = ' '.join([ get_status('NFS', services['nfs']), get_status('Proxy', services['proxy']), get_status('CIFS', services['cifs']), get_status('FTP', services['ftp']), get_status('HTTP', services['http']) ]) return serv_status, fs_status ######################################################################## try: services = bridge_srvc.srvc_list() if services: serv_status, fs_status = analyse_srvc() else: serv_status = '' fs_status = '' except Exception, e: print e print "--------- %s, get message error, srvc_list" % (edog_host) raise web.internalerror("%s, get message error" % (edog_host))
def node_srvc_list(): """给node这个数据结构添加一个srvc的项 """ #这个函数上上面函数的重构,测试通过后删除上面的函数, zhangjunfeng def highlight(string): return '<span class="highlight">%s</span>'%str(string) def healthy(string): return '<span class="healthy">%s</span>'%str(string) try: services = bridge_srvc.srvc_list() nodes = rest_moni(host=edog_host, port=edog_port) except: raise if nodes == {'result':'empty'}: return None elif not nodes: return None #service 和nodes 的格式参考 #print 'node_srvc_list, service:%s'%str(services) #print 'node_srvc_list, nodes:%s'%str(nodes) def get_service_part(node, services, serviceName, serviceShort): service_list = services[serviceName] n_service_list = [] for service in service_list: if node['ip'] == service['ip']: n_service_list.append(service) service_running_list = [] for service in n_service_list: if service['status'] == 'running': service_running_list.append(service) len_service_running = len(service_running_list) len_service = len(n_service_list) service_part = '' if len_service>0: if len_service_running != len_service: service_part = highlight('%s[%d/%d]'% (serviceShort, len_service_running, len_service)) else: service_part = healthy('%s[%d/%d]'% (serviceShort, len_service_running, len_service)) return service_part service_dict = {'mds':'M', 'c60':'L', 'cds':'C', 'rjnld':'R', 'proxy':'P', 'nfs':'N', 'cifs':'S', 'ftp':'F', 'http':'H'} for n in nodes: ####################################################### # if not n['cluster'] > -1: continue ####################################################### def l(serviceName): return get_service_part(n, services, serviceName, service_dict[serviceName]) n['srvc'] = ' '.join([ l('mds'), l('c60'), l('cds'), l('rjnld'), '<br/>', l('proxy'), l('nfs'), l('cifs'), l('ftp'), l('http')]) return nodes
def GET(self, type="all"): input = web.input() limit = int(input.rows) #每页显示行。 sord = input.sord #排序关键字 sidx = input.sidx #升序还是降序 page = input.page #申请的第几页 try: services = bridge_srvc.srvc_list() except: raise ss = [] if type == 'all': ss = services['c60'] + services['mds'] + services['cds'] elif type in ['c60', 'mds', 'cds']: ss = services[type] else: ss = [] if ss: count = len(ss)#记录总数 total_pages = count/limit if count%limit != 0: total_pages += 1 start = (int(page) - 1) * limit end = int(page) * limit if end > count: end = count #现在还不支持limit rows = [] for i in range(start, end): s = ss[i] id = s['n'] ip = s['ip'] type = s['type'] status = s['status'] pid = s['pid'] rows.append({'id':ip, 'cell':[ip, type, id, status, pid]}) results = { 'total' : str(total_pages), 'page' : str(page), 'records' : str(count), 'rows' : rows } else: results = { 'total' : 0, 'page' : str(page), 'records' : 0, 'rows' : [] } web.header("Content-Type", "application/json") return json.dumps(results)
def GET(self): highlight = '<span class="highlight">%s</span>' healthy = '<span class="healthy">%s</span>' lowlight = '<span class="lowlight">%s</span>' def get_status(prefix, serv_list): running_list = [x for x in serv_list if x['status'] == 'running'] stopped_list = [x for x in serv_list if x['status'] == 'shutoff'] total = len(serv_list) running = len(running_list) stopped = len(stopped_list) delta = total - running - stopped result = '%s[%d/%d]' % (prefix, running, total) if total>0 and running == total: result = '<a type=%s>%s</a>' % (prefix.lower(), healthy % result) elif total>0 and running != total: if delta == 0: result = '<a type=%s>%s</a>' % (prefix.lower(), highlight % result) else: result = '<a type=%s>%s</a>' % (prefix.lower(), lowlight % result) else: result = '' return result def analyse_srvc(): ######################################################################## serv_status = ' '.join([ get_status('C60', services['c60']), get_status('MDS', services['mds']), get_status('RJNLD', services['rjnld']), get_status('CDS', services['cds']) ]) fs_status = ' '.join([ get_status('NFS', services['nfs']), get_status('Proxy', services['proxy']), get_status('CIFS', services['cifs']), get_status('FTP', services['ftp']), get_status('HTTP', services['http']) ]) return serv_status, fs_status ######################################################################## try: services = bridge_srvc.srvc_list() if services: serv_status, fs_status = analyse_srvc() else: serv_status = '' fs_status = '' except Exception, e: print e print "--------- %s, get message error, srvc_list" % (edog_host) raise web.internalerror("%s, get message error" % (edog_host))
def GET(self, type="all"): input = web.input() limit = int(input.rows) #每页显示行。 sord = input.sord #排序关键字 sidx = input.sidx #升序还是降序 page = input.page #申请的第几页 try: services = bridge_srvc.srvc_list() except: raise ss = [] if type == 'all': ss = services['c60'] + services['mds'] + services['cds'] elif type in ['c60', 'mds', 'cds']: ss = services[type] else: ss = [] if ss: count = len(ss) #记录总数 total_pages = count / limit if count % limit != 0: total_pages += 1 start = (int(page) - 1) * limit end = int(page) * limit if end > count: end = count #现在还不支持limit rows = [] for i in range(start, end): s = ss[i] id = s['n'] ip = s['ip'] type = s['type'] status = s['status'] pid = s['pid'] rows.append({'id': ip, 'cell': [ip, type, id, status, pid]}) results = { 'total': str(total_pages), 'page': str(page), 'records': str(count), 'rows': rows } else: results = {'total': 0, 'page': str(page), 'records': 0, 'rows': []} web.header("Content-Type", "application/json") return json.dumps(results)
def GET(self): input = web.input() mytype='proxy' services = bridge_srvc.srvc_list(type=mytype) proxy_list = services[mytype] count = 0 if proxy_list: count = len(proxy_list) limit = int(input.rows) #每页显示行。 sord = input.sord #排序关键字 sidx = input.sidx #升序还是降序 page = input.page #申请的第几页 total_pages = count/limit if count%limit != 0: total_pages += 1 start = (int(page) - 1) * limit end = int(page) * limit print start, end if end > count: end = count rows = [] if proxy_list: for proxy in proxy_list: id = proxy['n'] ip = proxy['ip'] nodes = bridge_node.node_list(ip=ip) node = nodes[0] server = node['hostname'] rows.append({'id':id, 'cell':[id, ip, server, '']}) results = { 'total' : str(total_pages), 'page' : str(page), 'records' : str(count), 'rows' : rows } web.header("Content-Type", "application/json") return json.dumps(results)
def GET(self): input = web.input() mytype = 'proxy' services = bridge_srvc.srvc_list(type=mytype) proxy_list = services[mytype] count = 0 if proxy_list: count = len(proxy_list) limit = int(input.rows) #每页显示行。 sord = input.sord #排序关键字 sidx = input.sidx #升序还是降序 page = input.page #申请的第几页 total_pages = count / limit if count % limit != 0: total_pages += 1 start = (int(page) - 1) * limit end = int(page) * limit print start, end if end > count: end = count rows = [] if proxy_list: for proxy in proxy_list: id = proxy['n'] ip = proxy['ip'] nodes = bridge_node.node_list(ip=ip) node = nodes[0] server = node['hostname'] rows.append({'id': id, 'cell': [id, ip, server, '']}) results = { 'total': str(total_pages), 'page': str(page), 'records': str(count), 'rows': rows } web.header("Content-Type", "application/json") return json.dumps(results)
def GET(self, type="all"): input = web.input() limit = int(input.rows) #每页显示行。 sord = input.sord #排序关键字 sidx = input.sidx #升序还是降序 page = input.page #申请的第几页 try: services = bridge_srvc.srvc_list() except: print "-------- %s, get message error" % (edog_host) raise web.internalerror(message="%s get message error," % (edog_host)) ss = [] if type == 'all': for k, v in services.iteritems(): ss += v elif type in get_service_list(): ss = services[type] elif type == 'all_log': #因为在日志的操作中也调用的这个方法, #和node不同的地方是all,所以添加了这个else判断。 for k, v in services.iteritems(): ss += v else: ss = [] if ss: count = len(ss) #记录总数 total_pages = count / limit if count % limit != 0: total_pages += 1 start = (int(page) - 1) * limit end = int(page) * limit if end > count: end = count ss = sort_dict_list(ss, sord, sidx) rows = [] if ss: for i in range(start, end): s = ss[i] n = s['n'] ip = s['ip'] type = s['type'] status = s['status'] pid = s['pid'] id = ":".join([str(ip), type, str(n)]) argv = "'" + id + "'" opt_start = '<button onclick="srvc_opt(%s, %s);">启动</button>' % ( argv, "'" + 'start' + "'") opt_stop = '<button onclick="srvc_opt(%s, %s);">关闭</button>' % ( argv, "'" + 'stop' + "'") if status == 'running': opt = opt_stop else: opt = opt_start rows.append({ 'id': id, 'cell': [ip, type, n, status, pid, opt] }) results = { 'total': str(total_pages), 'page': str(page), 'records': str(count), 'rows': rows } else: results = {'total': 0, 'page': str(page), 'records': 0, 'rows': []} web.header("Content-Type", "application/json") return json.dumps(results)
def _node_srvc_list(): #这个函数需要重构, zhangjunfeng ,这个函数重构完成,命名为node_srvc_list, highlight = '<span class="highlight">%s</span>' healthy = '<span class="healthy">%s</span>' try: services = bridge_srvc.srvc_list() nodes = rest_moni(host=edog_host, port=edog_port) except: raise if nodes == {'result':'empty'}: return None elif not nodes: return None print 'node_srvc_list, service:%s'%service c60_list = services['c60'] mds_list = services['mds'] rjnld_list = services['rjnld'] cds_list = services['cds'] nfs_list = services['nfs'] proxy_list = services['proxy'] http_list = services['http'] cifs_list = services['cifs'] ftp_list = services['ftp'] for n in nodes: ####################################################### # if not n['cluster'] > -1: # continue ####################################################### n_mds_list = [] n_cds_list = [] n_c60_list = [] n_rjnld_list = [] n_nfs_list = [] n_cifs_list = [] n_ftp_list = [] n_http_list = [] n_proxy_list = [] for mds in mds_list: if n['ip'] == mds['ip']: n_mds_list.append(mds) for cds in cds_list: if n['ip'] == cds['ip']: n_cds_list.append(cds) for c60 in c60_list: if n['ip'] == c60['ip']: n_c60_list.append(c60) for rjnld in rjnld_list: if n['ip'] == rjnld['ip']: n_rjnld_list.append(rjnld) for nfs in nfs_list: if n['ip'] == nfs['ip']: n_nfs_list.append(nfs) for cifs in cifs_list: if n['ip'] == cifs['ip']: n_cifs_list.append(cifs) for ftp in ftp_list: if n['ip'] == ftp['ip']: n_ftp_list.append(ftp) for http in http_list: if n['ip'] == http['ip']: n_http_list.append(http) for proxy in proxy_list: if n['ip'] == proxy['ip']: n_proxy_list.append(proxy) mds_running_list = [] for mds in n_mds_list: if mds['status'] == 'running': mds_running_list.append(mds) len_mds_running = len(mds_running_list) len_mds = len(n_mds_list) cds_running_list = [] for cds in n_cds_list: if cds['status'] == 'running': cds_running_list.append(cds) len_cds_running = len(cds_running_list) len_cds = len(n_cds_list) c60_running_list = [] for c60 in n_c60_list: if c60['status'] == 'running': c60_running_list.append(c60) len_c60_running = len(c60_running_list) len_c60 = len(n_c60_list) rjnld_running_list = [] for rjnld in n_rjnld_list: if rjnld['status'] == 'running': rjnld_running_list.append(rjnld) len_rjnld_running = len(rjnld_running_list) len_rjnld = len(n_rjnld_list) nfs_running_list = [] for nfs in n_nfs_list: if nfs['status'] == 'running': nfs_running_list.append(nfs) len_nfs_running = len(nfs_running_list) len_nfs = len(n_nfs_list) cifs_running_list = [] for cifs in n_cifs_list: if cifs['status'] == 'running': cifs_running_list.append(cifs) len_cifs_running = len(cifs_running_list) len_cifs = len(n_cifs_list) ftp_running_list = [] for ftp in n_ftp_list: if ftp['status'] == 'running': ftp_running_list.append(ftp) len_ftp_running = len(ftp_running_list) len_ftp = len(n_ftp_list) http_running_list = [] for http in n_http_list: if http['status'] == 'running': http_running_list.append(http) len_http_running = len(http_running_list) len_http = len(n_http_list) proxy_running_list = [] for proxy in n_proxy_list: if proxy['status'] == 'running': proxy_running_list.append(proxy) len_proxy_running = len(proxy_running_list) len_proxy = len(n_proxy_list) ################################################################################### mds_part = '' if len_mds>0: if len_mds_running != len_mds: mds_part = highlight % ('M[%d/%d]' % (len_mds_running, len_mds)) else: mds_part = healthy % ('M[%d/%d]' % (len_mds_running, len_mds)) ################################################################################### c60_part = '' if len_c60>0: if len_c60_running != len_c60: c60_part = highlight % ('L[%d/%d]' % (len_c60_running, len_c60)) else: c60_part = healthy % ('L[%d/%d]' % (len_c60_running, len_c60)) ################################################################################### rjnld_part = '' if len_rjnld>0: if len_rjnld_running != len_rjnld: rjnld_part = highlight % ('R[%d/%d]' % (len_rjnld_running, len_rjnld)) else: rjnld_part = healthy % ('R[%d/%d]' % (len_rjnld_running, len_rjnld)) ################################################################################### cds_part = '' if len_cds>0: if len_cds_running != len_cds: cds_part = highlight % ('C[%d/%d]' % (len_cds_running, len_cds)) else: cds_part = healthy % ('C[%d/%d]' % (len_cds_running, len_cds)) ################################################################################### proxy_part = '' if len_proxy>0: if len_proxy_running != len_proxy: proxy_part = highlight % ('P[%d/%d]' % (len_proxy_running, len_proxy)) else: proxy_part = healthy % ('P[%d/%d]' % (len_proxy_running, len_proxy)) ################################################################################### nfs_part = '' if len_nfs>0: if len_nfs_running != len_nfs: nfs_part = highlight % ('N[%d/%d]' % (len_nfs_running, len_nfs)) else: nfs_part = healthy % ('N[%d/%d]' % (len_nfs_running, len_nfs)) ################################################################################### cifs_part = '' if len_cifs>0: if len_cifs_running != len_cifs: cifs_part = highlight % ('S[%d/%d]' % (len_cifs_running, len_cifs)) else: cifs_part = healthy % ('S[%d/%d]' % (len_cifs_running, len_cifs)) ################################################################################### ftp_part = '' if len_ftp>0: if len_ftp_running != len_ftp: ftp_part = highlight % ('F[%d/%d]' % (len_ftp_running, len_ftp)) else: ftp_part = healthy % ('F[%d/%d]' % (len_ftp_running, len_ftp)) ################################################################################### http_part = '' if len_http>0: if len_http_running != len_http: http_part = highlight % ('H[%d/%d]' % (len_http_running, len_http)) else: http_part = healthy % ('H[%d/%d]' % (len_http_running, len_http)) ################################################################################### n['srvc'] = ' '.join([ mds_part, c60_part, cds_part, rjnld_part, '<br/>', proxy_part, nfs_part, cifs_part, ftp_part, http_part]) return node
def GET(self, type="all"): input = web.input() limit = int(input.rows) #每页显示行。 sord = input.sord #排序关键字 sidx = input.sidx #升序还是降序 page = input.page #申请的第几页 try: services = bridge_srvc.srvc_list() except: print "-------- %s, get message error"%(edog_host) raise web.internalerror(message = "%s get message error,"%(edog_host)) ss = [] if type == 'all': for k, v in services.iteritems(): ss += v elif type in get_service_list(): ss = services[type] elif type == 'all_log': #因为在日志的操作中也调用的这个方法, #和node不同的地方是all,所以添加了这个else判断。 for k, v in services.iteritems(): ss += v else: ss = [] if ss: count = len(ss)#记录总数 total_pages = count/limit if count%limit != 0: total_pages += 1 start = (int(page) - 1) * limit end = int(page) * limit if end > count: end = count ss = sort_dict_list(ss, sord, sidx) rows = [] if ss: for i in range(start, end): s = ss[i] n = s['n'] ip = s['ip'] type = s['type'] status = s['status'] pid = s['pid'] id = ":".join([str(ip), type, str(n)]) argv = "'"+id+"'" opt_start = '<button onclick="srvc_opt(%s, %s);">启动</button>'%(argv, "'"+'start'+"'") opt_stop = '<button onclick="srvc_opt(%s, %s);">关闭</button>'%(argv, "'"+'stop'+"'") if status == 'running': opt = opt_stop else: opt = opt_start rows.append({'id':id, 'cell':[ip, type, n, status, pid, opt]}) results = { 'total' : str(total_pages), 'page' : str(page), 'records' : str(count), 'rows' : rows } else: results = { 'total' : 0, 'page' : str(page), 'records' : 0, 'rows' : [] } web.header("Content-Type", "application/json") return json.dumps(results)