Beispiel #1
0
 def GET(self):
     input = web.input()
     ylvmopt = YlvmOpt()
     try:
         lvm = ylvmopt.list()
     except:
         print "-----------  get message error,"
         raise web.internalerror(message="get message error,")
     limit = int(input.rows)  #每页显示行。
     sord = input.sord  #排序关键字
     sidx = input.sidx  #升序还是降序
     page = input.page  #申请的第几页
     count = len(lvm)
     if count == 0:
         rows = {'id': '', 'cell': ['', '', '']}
     else:
         for i in lvm:
             i['id'] = int(i['id'])
         NS = sort_dict_list(lvm, sord, sidx)
         count = len(NS)
         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
         rows = []
         for i in range(start, end):
             n = NS[i]
             size = n['size']
             n['size'] = ((int(size) / 1024) / 1024) / 1024
             rows.append({
                 'id': n['name'],
                 'cell': [n['id'], n['name'], n['size']]
             })
     results = {
         'total': str(total_pages),
         'page': str(page),
         'records': str(count),
         'rows': rows
     }
     web.header("Content-Type", "application/json")
     return json.dumps(results)
Beispiel #2
0
 def GET(self):
     x = web.input()
     print x
     print 'in rsrc get,conf'
     try:
         cf = confOpt.get_conf()
     except:
         print "------------ get conf error,"
         raise web.internalerror(message="get conf error,")
     limit = int(x.rows)  #每页显示行。
     sord = x.sord  #排序关键字
     sidx = x.sidx  #升序还是降序
     page = x.page  #申请的第几页
     cf = utils.sort_dict_list(cf, sord, sidx)
     count = len(cf)
     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
     rows = []
     if count == 0:
         rows = {'id': '', 'cell': ['', '', '', '']}
     else:
         for i in range(start, end):
             option = cf[i]
             rows.append({
                 'id':
                 option['key'],
                 'cell': [
                     option['catagory'], option['key'], option['value'],
                     option['doc']
                 ]
             })
     results = {
         'total': str(total_pages),
         'page': str(page),
         'records': str(count),
         'rows': rows
     }
     web.header("Content-Type", "application/json")
     return json.dumps(results)
Beispiel #3
0
Datei: flvm.py Projekt: e42s/uss
 def GET(self):
     input = web.input()
     ylvmopt = YlvmOpt()
     try:
         lvm = ylvmopt.list()
     except:
         print "-----------  get message error,"
         raise web.internalerror(message = "get message error,")
     limit = int(input.rows) #每页显示行。
     sord = input.sord #排序关键字
     sidx = input.sidx #升序还是降序
     page = input.page #申请的第几页
     count = len(lvm)
     if count == 0:
         rows={'id':'', 'cell':['', '', '']}
     else:
         for i in lvm:
             i['id'] = int(i['id'])
         NS = sort_dict_list(lvm, sord, sidx)
         count = len(NS)
         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
         rows = []
         for i in range(start, end):
            n = NS[i]
            size = n['size']
            n['size'] = ((int(size)/1024)/1024)/1024
            rows.append({'id':n['name'],
                          'cell':[n['id'], n['name'], n['size']]})
     results = {
         'total'   : str(total_pages),
         'page'    : str(page),
         'records' : str(count),
         'rows'    : rows
         }
     web.header("Content-Type", "application/json")
     return json.dumps(results)
Beispiel #4
0
Datei: conf.py Projekt: e42s/uss
 def GET(self):
     x = web.input()
     print x
     print 'in rsrc get,conf'
     try:
         cf = confOpt.get_conf()
     except:
         print "------------ get conf error,"
         raise web.internalerror(message = "get conf error,")
     limit = int(x.rows) #每页显示行。
     sord = x.sord #排序关键字
     sidx = x.sidx #升序还是降序
     page = x.page #申请的第几页
     cf = utils.sort_dict_list(cf, sord, sidx)
     count = len(cf)
     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
     rows = []
     if count == 0:
         rows={'id':'', 'cell':['', '', '', '']}
     else:
         for i in range(start, end):
             option = cf[i]
             rows.append({'id':option['key'],
                          'cell':[
                              option['catagory'], option['key'], 
                              option['value'], option['doc']]})
     results = {
         'total'   : str(total_pages),
         'page'    : str(page),
         'records' : str(count),
         'rows'    : rows
         }
     web.header("Content-Type", "application/json")
     return json.dumps(results)
Beispiel #5
0
    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)
Beispiel #6
0
class Rsrc:
    @login_required
    def GET(self, status="joined"):
        input = web.input()

        nm = []
        try:
            nm = bridge_node.node_srvc_list()
        except Exception, err:
            print "----------- %s, get message error: %s" % (edog_host,
                                                             str(err))
            raise web.internalerror(message="%s, get message error" %
                                    (edog_host))
            pass

        count = 0
        if nm:
            count = len(nm)

        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
        if end > count: end = count

        rows = []
        nm_new = []
        for n in nm:
            j = {}
            j["id"] = n["id"]
            j["ip"] = n["ip"]
            j["hostname"] = n["hostname"]
            j["status"] = n["status"]
            j["cpu"] = round(n['load']['cpu_used'],
                             2) if n['load']['cpu_used'] else ''
            j["load"] = round(n['load']['avg5'],
                              2) if n['load']['avg5'] else ''
            j["mem"] = round(float(n['mem']['total']-n['mem']['free'])/float(n['mem']['total']), 2) \
                                            if n['mem']['free'] and n['mem']['total'] \
                                            else ''
            j["swap"] = round(float(n['swap']['total']-n['swap']['free'])/float(n['swap']['total']), 2) \
                                            if n['swap']['free'] and n['swap']['total'] \
                                            else ''
            nw_in = 0
            nw_out = 0
            try:
                nw_in = round(float(n['nw']['in']) / (1024 * 1024), 2)
                nw_out = round(float(n['nw']['out']) / (1024 * 1024), 2)
            except:
                nw_in = ''
                nw_out = ''
            j["nw"] = str(nw_in) + ", " + str(nw_out)
            j["drvs"] = round(float(n['disk']['used'])/float(n['disk']['total']), 3) \
                                            if n['disk']['used'] and n['disk']['total'] \
                                            else ''
            j["srvc"] = n["srvc"]
            j["cluster"] = n["cluster"]
            nm_new.append(j)

        nm = sort_dict_list(nm_new, sord, sidx)
        if nm:
            for i in range(start, end):
                n = nm[i]
                #######################################################
                try:
                    if status == 'joined':
                        if n['cluster'] == -1 or n['cluster'] == None:
                            continue
                    elif status == 'exited':
                        if n['cluster'] > -1:
                            continue
                except:
                    continue
            #######################################################

                cpu_used = n["cpu"]
                load_avg5 = n["load"]
                mem_used_percent = n["mem"]
                swap_used_percent = n["swap"]
                disk_used_percent = n["drvs"]
                nw_in_out = n["nw"]

                ###########################################################################
                opt_edit = '<button onclick="node_edit(%d);">编辑</button>' % n[
                    'id']
                opt_del = '<button onclick="node_del(%d);">删除</button>' % n[
                    'id']

                opt_join = '<button onclick="node_join(%d);">加入</button>' % n[
                    'id']
                opt_exit = '<button onclick="node_exit(%d);">脱离</button>' % n[
                    'id']

                if status == 'joined':
                    operations = opt_exit
                elif status == 'exited':
                    operations = opt_del + opt_join
                else:
                    continue
                ###########################################################################

                rows.append({
                    'id':
                    n['id'],
                    'cell': [
                        n['id'], n['ip'], n['hostname'], n['status'], cpu_used,
                        load_avg5, mem_used_percent, swap_used_percent,
                        nw_in_out, disk_used_percent, n['srvc'], operations
                    ]
                })

        results = {
            'total': str(total_pages),
            'page': str(page),
            'records': str(count),
            'rows': rows
        }
        web.header("Content-Type", "application/json")
        return json.dumps(results)
Beispiel #7
0
Datei: node.py Projekt: e42s/uss
    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)