Exemple #1
0
def minions(request):
    current_page = int(request.GET.get("page",0))
    page_sum = 15
    page_extra = 3
    grains = salt_api.overview(request).values()
    try:
        cursor = connection.cursor()
        host_num = cursor.execute('select host_id,time from \
            (select host_id,time from salt.salt_result order \
            by id desc ) as b group by host_id;')
        hosts_time = cursor.fetchall()
        now = datetime.datetime.now()
        times_diff = {}
        for host_time in hosts_time:
           time_dist = now - host_time[1]
           times_diff[host_time[0]] = str(time_dist).split('.')[0]
    except:
        times_diff = {}
    for grain in grains:
        grain['IP'] = grain['id'].split('.')[0].replace('_','.')
        grain['time_diff'] = times_diff.get(grain['id'],'无')
    context = common.my_page(request,len(grains))
    context['page_tables'] = grains[current_page*page_sum:(current_page+1)*page_sum]
    print "*" * 60
    return render_to_response('default/auto_minions.html', context)
Exemple #2
0
def minions(request):
    current_page = int(request.GET.get("page", 0))
    page_sum = 15
    page_extra = 3
    grains = salt_api.overview(request).values()
    try:
        cursor = connection.cursor()
        host_num = cursor.execute('select host_id,time from \
            (select host_id,time from salt.salt_result order \
            by id desc ) as b group by host_id;')
        hosts_time = cursor.fetchall()
        now = datetime.datetime.now()
        times_diff = {}
        for host_time in hosts_time:
            time_dist = now - host_time[1]
            times_diff[host_time[0]] = str(time_dist).split('.')[0]
    except:
        times_diff = {}
    for grain in grains:
        grain['IP'] = grain['id'].split('.')[0].replace('_', '.')
        grain['time_diff'] = times_diff.get(grain['id'], '无')
    context = common.my_page(request, len(grains))
    context['page_tables'] = grains[current_page *
                                    page_sum:(current_page + 1) * page_sum]
    print "*" * 60
    return render_to_response('default/auto_minions.html', context)
Exemple #3
0
def detail(request):
    target = request.GET.get('target', '')
    if target:
        grain = salt_api.overview(request)
        state = salt_api.get_state(target)
    state = repr(json.dumps(state, sort_keys=True, indent=4))
    state = state.replace('\\n', '<br/>').replace(' ', '&nbsp;')
    context = {'grain': grain, 'state': state}
    return render_to_response('default/auto_detail.html', context)
Exemple #4
0
def detail(request):
    target = request.GET.get('target','')
    if target:
        grain = salt_api.overview(request)
        state = salt_api.get_state(target)
    state = repr(json.dumps(state,sort_keys=True, indent=4))
    state = state.replace('\\n','<br/>').replace(' ','&nbsp;')
    context = {
            'grain':grain,
            'state':state
        }
    return render_to_response('default/auto_detail.html', context)
Exemple #5
0
def service(request):
    context = {}
    context.update(csrf(request))
    if request.method == 'GET':
        id = request.GET.get('id','')
        if id:
            Service.objects.get(id=id).delete()
        services = Service.objects.all()
        context['services'] = services
        salt_list = salt_api.overview()
        return render_to_response('default/auto_service.html', context)
        #return render_to_response('default/auto_sidebar.html',context,context_instance=RequestContext(request))
    else:
        service_name = u'%s' %  request.POST.get('name','')
        service_tgt  = request.POST.get('tgt','')
        if service_name and service_tgt:
            try:
                new_service = Service(name=service_name,target=service_tgt)
                new_service.save()
            except:
                raise
        return render_to_response('default/auto_service_table.html', context)
Exemple #6
0
def service(request):
    context = {}
    context.update(csrf(request))
    if request.method == 'GET':
        id = request.GET.get('id', '')
        if id:
            Service.objects.get(id=id).delete()
        services = Service.objects.all()
        context['services'] = services
        salt_list = salt_api.overview()
        return render_to_response('default/auto_service.html', context)
        #return render_to_response('default/auto_sidebar.html',context,context_instance=RequestContext(request))
    else:
        service_name = u'%s' % request.POST.get('name', '')
        service_tgt = request.POST.get('tgt', '')
        if service_name and service_tgt:
            try:
                new_service = Service(name=service_name, target=service_tgt)
                new_service.save()
            except:
                raise
        return render_to_response('default/auto_service_table.html', context)
Exemple #7
0
def overview(request):
    context = {}
    context.update(csrf(request))
    grains = salt_api.overview(request).values()
    minions_os = {}
    minions_virtual = {}
    for grain in grains:
        try:
            minions_os[grain['osfullname']+grain['osrelease']] += 1
            minions_virtual[grain['virtual']] += 1
        except KeyError:
            minions_os[grain['osfullname']+grain['osrelease']] = 1
            minions_virtual[grain['virtual']] = 1
    try:
        cursor = connection.cursor()
        host_num = cursor.execute("select id,fun,time,success from  \
		(select id,fun,time,success from salt.salt_returns where \
		success='0' order by id desc) as b group by id limit 10;")
        hosts = cursor.fetchall()
        print hosts
        error_host = []
        for host in hosts:
            error_host.append({
              'id':host[0],
              'fun':host[1],
              'time':host[2],
              'success':host[3]
              })
    except:
        error_host = []


    context['minions_os'] = minions_os
    context['minions_virtual'] = minions_virtual
    context['minions_num'] = len(grains)
    context['error_host'] = error_host
    return render_to_response('default/auto_overview.html', context)
Exemple #8
0
def overview(request):
    context = {}
    context.update(csrf(request))
    grains = salt_api.overview(request).values()
    minions_os = {}
    minions_virtual = {}
    for grain in grains:
        try:
            minions_os[grain['osfullname'] + grain['osrelease']] += 1
            minions_virtual[grain['virtual']] += 1
        except KeyError:
            minions_os[grain['osfullname'] + grain['osrelease']] = 1
            minions_virtual[grain['virtual']] = 1
    try:
        cursor = connection.cursor()
        host_num = cursor.execute("select id,fun,time,success from  \
		(select id,fun,time,success from salt.salt_returns where \
		success='0' order by id desc) as b group by id limit 10;")
        hosts = cursor.fetchall()
        print hosts
        error_host = []
        for host in hosts:
            error_host.append({
                'id': host[0],
                'fun': host[1],
                'time': host[2],
                'success': host[3]
            })
    except:
        error_host = []

    context['minions_os'] = minions_os
    context['minions_virtual'] = minions_virtual
    context['minions_num'] = len(grains)
    context['error_host'] = error_host
    return render_to_response('default/auto_overview.html', context)