Example #1
0
def do_command(fileadd, ipadd, username, password):
    keys={}
    if read(fileadd):
        keys = json.loads(read(fileadd))
    keys[ipadd] = [username, password]
    write(json.dumps(keys), fileadd)
    return json.dumps({'response_code':'250'})#成功
Example #2
0
def do_command(fileadd, ipadd, username, password):
    keys = {}
    if read(fileadd):
        keys = json.loads(read(fileadd))
    keys[ipadd] = [username, password]
    print keys
    write(json.dumps(keys), fileadd)
    return json.dumps({"response_code": "250"})  # 成功
Example #3
0
def on_request(ch, method, props, body):     
    try:
        if read(key_file):
            username, password = json.loads(read(key_file))[localIP]#here is the switch address 
            keys = json.loads(body) 
            switch_name = keys['switch_name']
            print " received from %s" % (switch_name,)
            port_name = keys['port_name']
            host = keys['host']
            bandwidth = keys['bandwidth']
            response = do_command(switch_name, host, port_name, username, password, bandwidth)
            print "拯救地球 !!!"
        else:
            response = json.dumps({'response_code':'4587'})#密码错
    except:
            response = json.dumps({'response_code':'4588'})#操作错
    ch.basic_publish(exchange='',  
                     routing_key=props.reply_to,
                     properties=pika.BasicProperties(correlation_id=\
                                                         props.correlation_id),
                     body=str(response))
    ch.basic_ack(delivery_tag=method.delivery_tag)
Example #4
0
def on_request(ch, method, props, body):     
    try:
        if read(key_file):
            keys = json.loads(encrypt_util.decode(body)) 
            host = keys['host']   
            username, password = json.loads(read(key_file))[host]#here is the switch address 
            switch_name = keys['switch_name']       
            port_name = keys['port_name']     
            bandwidth = keys['bandwidth']  
            vlan = keys['vlan']  
            response = do_command(switch_name, host, vlan, username, password, bandwidth)    
            print "拯救地球 !!!"
        else:
            response = json.dumps({'response_code':'4587'})#密码错
    except:
            response = json.dumps({'response_code':'4588'})#操作错
    ch.basic_publish(exchange='',
                     routing_key=props.reply_to,
                     properties=pika.BasicProperties(correlation_id=\
                                                         props.correlation_id),
                     body=str(response))
    ch.basic_ack(delivery_tag=method.delivery_tag)