Пример #1
0
def get_jid_result(request):
    '''
    @note: 获取salt任务的执行结果
    '''
    job_id = request.GET.get('jid', '')

    client = SaltApi('saltstack')
    result = client.get_jid_result(job_id)

    fail_list = ['command not found', 'error']

    for i in fail_list:
        if i in result:

            #result = dict(json.loads(client.get_jid_result(job_id)))['info']  # salt_2016.11.1 新版本使用该语句
            # result = json.loads(client.get_jobs(JID))['return'][0]['data'] # salt_2015.5.10 老版本使用该语句
            return HttpResponse("执行失败!")
Пример #2
0
def salt_jid_result(request):
    '''
    @note: 获取salt任务的执行结果
    '''
    job_id = request.GET.get('jid', '')

    try:
        client = SaltApi('saltstack')
        result_data = dict(
            json.loads(client.get_jid_result(job_id))['info'][0])['Result']
        result = simplejson.dumps(result_data, sort_keys=True, indent='    ')
        return render_mako_context(
            request, '/home_application/opsplatform/salt_jid_result.html',
            {"result": result})
    except Exception, e:
        result = e
        return render_mako_context(
            request, '/home_application/opsplatform/salt_jid_result.html',
            {"result": result})