Exemple #1
0
def runScript(region,uuid,action):
    #find host ip
    #time.sleep(5)
    hostInfo=InstanceManager().getHostIp(NOVA_DB(region),uuid)
    if not hostInfo:
        print "Can't find host ip by uuid(%s) in Region(%s)" % (uuid,region)
        return "_error500_ Can't find host ip by uuid(%s) in Region(%s)" % (uuid,region)
    print "xxx_",hostInfo["host_ip"]
    host_ip=getConnIp(hostInfo["host_ip"])
    print "---hostip:",host_ip
    su_list=NetWorkFlow().getNetWorkFlows(uuid,region)
    msg={}
    for su in su_list:
        #find vir name by port
        print "-region-%s| -uuid-%s| -action-%s|-network-%s,loop!!!" % (region,uuid,action,su["network_id"])
        port=NetworkFlowManager().getNetInfoByUUIDAndNetId(NEUTRON_DB(su["region"]),su["uuid"],su["network_id"])
        if not port:
            print "-region-%s| -uuid-%s| -action-%s|-network-%s,can't find port!!!" % (region,uuid,action,su["network_id"])
            continue
        virName="tap"+port["id"][0:11]
        netWorkName=port["network_name"]
        network_flow=su["network_flow"]
        script_params="start "+virName+" "+str(network_flow)+" "+str(network_flow)
        #command -------port_id network_flow start tapName 30 30
        script_name=settings.C2_LIMIT_NETWORK_FLOW_SCRIPT
        exe=script_name+" "+script_params
        print "runScript(limit su)--->host_ip:%s,exe:%s" % (host_ip,exe)
        try:
            LOG=c2_ssh.conn(host_ip,exe)
        except Exception,ex:
            print Exception,":",ex
            LOG="SSH exception:%s" % str(ex)
        msg[uuid+"_"+netWorkName]=LOG
        NetWorkFlow().addLog(uuid,region,su["network_id"],netWorkName,LOG,action)
Exemple #2
0
def chgPwd(req,uuid,region,pwd):
    user=framework.getApiUserByToken(req)
    #if not user:
    #return HttpResponse(RTN_500 % "Unknow auth token request.")
    hostInfo=InstanceManager().getHostIp(NOVA_DB(region),uuid)
    if not hostInfo:
        return HttpResponse(RTN_500 % ("Can't find host ip by uuid(%s) in Region(%s)" % (uuid,region)))
    host_ip=hostInfo["host_ip"]

    #change private to public ip
    host_ip=getConnIp(host_ip)

    instid=int(hostInfo["id"])
    vir="instance-%s" % hex(instid)[2:].zfill(8)
    script_name=settings.C2_CHANGE_VIR_PWD_SCRIPT
    exe="%s %s %s" %(script_name,vir,pwd)
    print "runScript--->host_ip:%s,exe:%s" % (host_ip,exe)
    try:
        LOG=c2_ssh.conn(host_ip,exe)
    except Exception,ex:
        print Exception,":",ex
        LOG="SSH exception:%s" % str(ex)