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()
def get(self): template_values = {} # template_values['next'] = self.get_argument('next', '/') e_id = self.get_argument('e_id') e = Exchange.lookup(e_id) template_values['exchange'] = e self.render_template('/site/exchange_update.html', **template_values)
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')
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')
# -*- coding: utf-8 -*-
from models.order import Order from models.product import Product from models.exchange import Exchange from client.rpc_client import TelnetRpcClient import json, datetime from util import encrypt_util rpc = TelnetRpcClient(options.service_ip) need_do = '' 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}
from models.order import Order from models.product import Product from models.exchange import Exchange from client.rpc_client import TelnetRpcClient import json,datetime from util import encrypt_util rpc = TelnetRpcClient(options.service_ip) need_do = '' 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}