(request)
return render_to_response('salt_module_deploy.html', 
           {'ret': ret},context_instance=RequestContext(request))
deploy (nginx/php/mysql..etc) module
deploy (nginx/php/mysql..etc) module
deploy ( nginx / php / mysql .. etc ) module
def module_deploy(request):
    """
    deploy (nginx/php/mysql..etc) module
    """

    ret = [] 
    jid = []
    user = request.user
    if request.method == 'POST':
        action = request.get_full_path().split('=')[1]
        if action == 'deploy':
            tgt = request.POST.get('tgt')
            arg = request.POST.getlist('module')
            tgtcheck = HostList.objects.filter(hostname=tgt)
        if tgtcheck:
            Message.objects.create(type='salt', action='deploy', action_ip=tgt, content='saltstack %s module depoy' % (arg))
            sapi = SaltAPI(url=settings.SALT_API['url'],username=settings.SALT_API['user'],password=settings.SALT_API['password'])  
            if 'sysinit' in arg:                        
                obj = sapi.async_deploy(tgt,arg[-1])    #先执行初始化模块,其他任意
                jid.append(obj)
                arg.remove('sysinit')
                if arg:
                    for i in arg:
                        obj = sapi.async_deploy(tgt,i)     
                        jid.append(obj)
            else:
                for i in arg:
                    obj = sapi.async_deploy(tgt,i)
                    jid.append(obj)
            db = db_operate()
            for i in jid:
                time.sleep(10)
                sql = 'select returns from salt_returns where jid=%s'
                result=db.select_table(settings.RETURNS_MYSQL,sql,str(i))    #通过jid获取执行结果
                ret.append(result)
            #sapi.async_deploy('test-01','zabbix.api')   #调用zabbix.api执行模块监控
        else:
           ret = '亲，目标主机不对，请重新输入'   

    return render_to_response('salt_module_deploy.html', 
           {'ret': ret},context_instance=RequestContext(request))
def module_deploy ( request ) : ret = [ ] jid = [ ] user = request . user if request . method == 'POST' : action = request . get_full_path ( ) . split ( '=' ) [ 1 ] if action == 'deploy' : tgt = request . POST . get ( 'tgt' ) arg = request . POST . getlist ( 'module' ) tgtcheck = HostList . objects . filter ( hostname = tgt ) if tgtcheck : Message . objects . create ( type = 'salt' , action = 'deploy' , action_ip = tgt , content = 'saltstack %s module depoy' % ( arg ) ) sapi = SaltAPI ( url = settings . SALT_API [ 'url' ] , username = settings . SALT_API [ 'user' ] , password = settings . SALT_API [ 'password' ] ) if 'sysinit' in arg : obj = sapi . async_deploy ( tgt , arg [ - 1 ] ) #先执行初始化模块,其他任意 jid . append ( obj ) arg . remove ( 'sysinit' ) if arg : for i in arg : obj = sapi . async_deploy ( tgt , i ) jid . append ( obj ) else : for i in arg : obj = sapi . async_deploy ( tgt , i ) jid . append ( obj ) db = db_operate ( ) for i in jid : time . sleep ( 10 ) sql = 'select returns from salt_returns where jid=%s' result = db . select_table ( settings . RETURNS_MYSQL , sql , str ( i ) ) #通过jid获取执行结果 ret . append ( result ) #sapi.async_deploy('test-01','zabbix.api')   #调用zabbix.api执行模块监控 else : ret = '亲，目标主机不对，请重新输入'    return render_to_response ( 'salt_module_deploy.html' , { 'ret' : ret } , context_instance = RequestContext ( request ) )