Ejemplo n.º 1
0
 def post(self):  
     oname = self.get_username()
     ipAddress = self.get_argument("ipAddress", None)
     ename = self.get_argument("ename", None)
     tusername = self.get_argument("tusername", None)
     tpassword = self.get_argument("tpassword", None)
     if not tusername or not tpassword:
         # do something
         self.flash.error = "You must enter a username and password to proceed. Please try again."
         self.redirect("/add_exchange")
         return
     
     if tpassword != self.get_argument("tpassword2", None) :
         self.flash.error = "Passwords do not match. Please try again."
         self.redirect("/add_exchange")
         return
     Exchange.insert(ename,oname,ipAddress)
     rpc = TelnetRpcClient(options.service_ip)
     msg = json.dumps({'fileadd':options.telnet_key_dir, \
                                                 'ipadd':ipAddress,'username':tusername,"password":tpassword})
     from util import encrypt_util  
     encoded = encrypt_util.encode(msg)
     response = rpc.call("key_queue",encoded)
     Log.info(response)
     ##加密传输入保存
     self.redirect("/get_exchanges")     
Ejemplo n.º 2
0
    def post(self):
        oname = self.get_username()
        ipAddress = self.get_argument("ipAddress", None)
        ename = self.get_argument("ename", None)
        tusername = self.get_argument("tusername", None)
        tpassword = self.get_argument("tpassword", None)
        if not tusername or not tpassword:
            # do something
            self.flash.error = "You must enter a username and password to proceed. Please try again."
            self.redirect("/add_exchange")
            return

        if tpassword != self.get_argument("tpassword2", None):
            self.flash.error = "Passwords do not match. Please try again."
            self.redirect("/add_exchange")
            return
        Exchange.insert(ename, oname, ipAddress)
        rpc = TelnetRpcClient(options.service_ip)
        msg = json.dumps({'fileadd':options.telnet_key_dir, \
                                                    'ipadd':ipAddress,'username':tusername,"password":tpassword})
        from util import encrypt_util
        encoded = encrypt_util.encode(msg)
        response = rpc.call("key_queue", encoded)
        Log.info(response)
        ##加密传输入保存
        self.redirect("/get_exchanges")
Ejemplo n.º 3
0
    def set_bandwidth_job():
        from models.order import Order 
        from models.product import Product  
        from models.exchange import Exchange 
        from client.rpc_client import TelnetRpcClient    
        from tornado.options import options
        import json 
        from util import encrypt_util
        Log.info(" [x] Requesting")  
        Log.info('set_bandwidth_job start at ', datetime.datetime.now())
        need_do = ''
        Log.info("请异步发送")
        orders = Order.get_working_orders()
        for order in orders:    
            product = Product.lookup(order['p_id'])
            exchange = Exchange.lookup(product['e_id'])  
            need_do = need_do+json.dumps({'switch_name':exchange['ename'],"vlan":product['vlan'], \
                            "port_name":product['port'], "host":exchange['ipAddress'], \
                            "bandwidth":order['bandwidth']})
            Order.finish_order(order['_id'])         
        need_back=''
        orders = Order.get_back_orders()
        for order in orders:
            product = Product.lookup(order['p_id'])
            exchange = Exchange.lookup(product['e_id'])  
            need_back = need_back+json.dumps({'switch_name':exchange['ename'],"vlan":product['vlan'], \
                            "port_name":product['port'], "host":exchange['ipAddress'], \
                            "bandwidth":order['bandwidth']})
            Order.back_order(order['_id'])
        orders = {}   
        flag = False  
        if(need_do!=''):
            orders['need_do']=need_do
            flag = True
        if(need_back!=''):
            orders['need_back']=need_back
            flag = True
        if(flag!=True):
            rpc = TelnetRpcClient(options.service_ip)
            encoded = encrypt_util.encode(str(orders))
            response = rpc.call("rpc_queue",encoded)
        Log.info('set_bandwidth_job end at ', datetime.datetime.now())
        Log.info(response)
#        rpc = TelnetRpcClient('192.168.0.2')
#        orders = Order.get_working_orders()
#        for order in orders:
#            product = Product.lookup(order['p_id'])
#            exchange = Exchange.lookup(product['e_id']) 
#            response = rpc.call(json.dumps({'switch_name':'TelnetManage3560', "vlan":product['vlan'],
#                            "port_name":product['port'], "host":exchange['ipAddress'], "bandwidth":product['ctype']*order['percent']/100}))
        print 'set_bandwidth_job end at ', datetime.datetime.now()
Ejemplo n.º 4
0
 def post(self):   
     e_id = self.get_argument('e_id')
     e = Exchange.lookup(e_id)
     tusername = self.get_argument('username')
     newPw = self.get_argument('new_pw')
     newPw2 = self.get_argument('new_pw_again')
     if newPw != newPw2 :
         self.flash.error = "Passwords do not match, please try again"
         self.redirect("/exchange_up")
         return
     tpassword =newPw  
     rpc = TelnetRpcClient(options.service_ip)
     msg = json.dumps({'fileadd':options.telnet_key_dir,'ipadd':e['ipAddress'],'username':tusername,"password":tpassword})
     from util import encrypt_util
     encoded = encrypt_util.encode(msg)
     response = rpc.call("key_queue",encoded)
     Log.info(response)
     self.flash.success = "Successfully updated password"
     self.redirect('/exchange_up')       
Ejemplo n.º 5
0
 def post(self):
     e_id = self.get_argument('e_id')
     e = Exchange.lookup(e_id)
     tusername = self.get_argument('username')
     newPw = self.get_argument('new_pw')
     newPw2 = self.get_argument('new_pw_again')
     if newPw != newPw2:
         self.flash.error = "Passwords do not match, please try again"
         self.redirect("/exchange_up")
         return
     tpassword = newPw
     rpc = TelnetRpcClient(options.service_ip)
     msg = json.dumps({
         'fileadd': options.telnet_key_dir,
         'ipadd': e['ipAddress'],
         'username': tusername,
         "password": tpassword
     })
     from util import encrypt_util
     encoded = encrypt_util.encode(msg)
     response = rpc.call("key_queue", encoded)
     Log.info(response)
     self.flash.success = "Successfully updated password"
     self.redirect('/exchange_up')
Ejemplo n.º 6
0
orders = Order.get_working_orders()
for order in orders:
    product = Product.lookup(order['p_id'])
    exchange = Exchange.lookup(product['e_id'])
    need_do = need_do+json.dumps({'switch_name':exchange['ename'],"vlan":product['port'], \
                    "port_name":product['port'], "host":exchange['ipAddress'], \
                    "bandwidth":order['bandwidth'],"flag":1})
    Order.finish_order(order['_id'])
need_back = ''
orders = Order.get_back_orders()
for order in orders:
    product = Product.lookup(order['p_id'])
    exchange = Exchange.lookup(product['e_id'])
    need_back = need_back+json.dumps({'switch_name':exchange['ename'],"vlan":product['port'], \
                    "port_name":product['port'], "host":exchange['ipAddress'], \
                    "bandwidth":order['bandwidth'],"flag":0})
    Order.back_order(order['_id'])

orders = {"1": need_do, "0": need_back}
encoded = encrypt_util.encode(str(orders))
response = rpc.call("rpc_queue", encoded)

print response
#        rpc = TelnetRpcClient('192.168.0.2')
#        orders = Order.get_working_orders()
#        for order in orders:
#            product = Product.lookup(order['p_id'])
#            exchange = Exchange.lookup(product['e_id'])
#            response = rpc.call(json.dumps({'switch_name':'TelnetManage3560', "vlan":product['vlan'],
#                            "port_name":product['port'], "host":exchange['ipAddress'], "bandwidth":product['ctype']*order['percent']/100}))
print 'set_bandwidth_job end at ', datetime.datetime.now()
Ejemplo n.º 7
0
Archivo: test.py Proyecto: hc990/let
orders = Order.get_working_orders()
for order in orders:    
    product = Product.lookup(order['p_id'])
    exchange = Exchange.lookup(product['e_id'])  
    need_do = need_do+json.dumps({'switch_name':exchange['ename'],"vlan":product['port'], \
                    "port_name":product['port'], "host":exchange['ipAddress'], \
                    "bandwidth":order['bandwidth'],"flag":1})
    Order.finish_order(order['_id'])         
need_back=''
orders = Order.get_back_orders()
for order in orders:
    product = Product.lookup(order['p_id'])
    exchange = Exchange.lookup(product['e_id'])
    need_back = need_back+json.dumps({'switch_name':exchange['ename'],"vlan":product['port'], \
                    "port_name":product['port'], "host":exchange['ipAddress'], \
                    "bandwidth":order['bandwidth'],"flag":0})
    Order.back_order(order['_id'])

orders = {"1":need_do,"0":need_back}  
encoded = encrypt_util.encode(str(orders))
response = rpc.call("rpc_queue",encoded)

print response
#        rpc = TelnetRpcClient('192.168.0.2')
#        orders = Order.get_working_orders()
#        for order in orders:
#            product = Product.lookup(order['p_id'])
#            exchange = Exchange.lookup(product['e_id']) 
#            response = rpc.call(json.dumps({'switch_name':'TelnetManage3560', "vlan":product['vlan'],
#                            "port_name":product['port'], "host":exchange['ipAddress'], "bandwidth":product['ctype']*order['percent']/100}))
print 'set_bandwidth_job end at ', datetime.datetime.now()