def job_package(): # Log.info("请异步发送") need_do = '' orders = Order.get_working_orders() for order in orders: product = Product.lookup(order['p_id']) exchange = Exchange.get_exchange(order['e_id']) packages = Package.getPackageByName(order['package_id']) for package in packages: need_do = need_do+json.dumps({'port':product['port'],'bandwidth':order['bandwidth'],\ 'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \ 'package_id':package['package_name']}) # Order.finish_order(order['_id']) need_back = '' orders = Order.get_back_orders() for order in orders: custom_time = order['custom_time'] product = Product.lookup(order['p_id']) exchange = Exchange.look(order['e_id']) packages = Package.getPackageByName(order['package_id']) for package in packages: need_back = need_back+json.dumps({'port':product['port'],'ex_bandwidth':order['bandwidth'],\ 'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \ 'package_id':package['package_name']}) # Order.back_order(order['_id']) print 'set_package_job end at ', datetime.datetime.now()
def job_package(): # Log.info("请异步发送") need_do = '' orders = Order.get_working_orders() for order in orders: product = Product.lookup(order['p_id']) exchange = Exchange.get_exchange(order['e_id']) packages = Package.getPackageByName(order['package_id']) for package in packages: need_do = need_do+json.dumps({'port':product['port'],'bandwidth':order['bandwidth'],\ 'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \ 'package_id':package['package_name']}) # Order.finish_order(order['_id']) need_back='' orders = Order.get_back_orders() for order in orders: custom_time = order['custom_time'] product = Product.lookup(order['p_id']) exchange = Exchange.look(order['e_id']) packages = Package.getPackageByName(order['package_id']) for package in packages: need_back = need_back+json.dumps({'port':product['port'],'ex_bandwidth':order['bandwidth'],\ 'status':order['status'],'port_name':product['port'], 'ipAddress':exchange['ipAddress'], \ 'package_id':package['package_name']}) # Order.back_order(order['_id']) print 'set_package_job end at ',datetime.datetime.now()
# -*- coding: utf-8 -*-
def main(): from models.product import Product from models.order import Order from models.package import Package # from views.paginator import Paginator from models.exchange import Exchange # # from datetime import datetime # start = datetime(2010, 4, 1) # end = datetime(2015, 5, 1) # for exchange in Exchange.get_status_exchanges(1): need_do = [] orders = Order.get_working_orders(1, exchange["_id"]) for order in orders: print order["custom_time"] product = Product.lookup(order["p_id"]) exchange = Exchange.get_exchange(order["e_id"]) package = Package.lookup(order["package_id"]) # need_do = need_do + json.dumps({'switch_name':exchange['ename'],'port':product['port'], 'bandwidth':order['bandwidth'], \ # 'port_name':product['port'], 'ipAddress':exchange['ipAddress'],'o_id':order['_id'] }) need_do.append( json.dumps( { "switch_name": exchange["ename"], "port": product["port"], "port_name": product["port"], "host": exchange["ipAddress"], "bandwidth": order["bandwidth"], } ) ) if len(need_do) > 0: cmd = json.dumps({"switch_name": exchange["ename"], "host": exchange["ipAddress"], "orders": need_do}) # print cmd print len(cmd) print cmd print "-----------" keys = json.loads(cmd) print keys["host"] print keys["orders"] ################################################## # if read(key_file): # keys = json.loads(encrypt_util.decode(body)) if 1 == 1: keys = json.loads(cmd) host = keys["host"] username, password = json.loads(read(key_file))[host] # here is the switch address values = keys["orders"] switch_name = keys["switch_name"] ################################################################### # switch_name = keys['switch_name'] # port_name = keys['port_name'] # bandwidth = keys['bandwidth'] # vlan = keys['vlan'] response = do_command(switch_name, host, username, password, values)