예제 #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")     
예제 #2
0
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()
예제 #3
0
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()
예제 #4
0
    def post(self):
        oname = self.get_username()
        ipAddress = self.get_argument("ipAddress", None)
        ename = self.get_argument("ename", None)
        elogo = self.get_argument("elogo", None)
        print "this is {}".format(elogo)
        etype = self.get_argument("etype", 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, elogo, etype)
        #         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")
예제 #5
0
파일: bootstrap.py 프로젝트: hc990/let
    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()
예제 #6
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)
     rpc = TelnetRpcClient(options.service_ip)
     Exchange.insert(ename,oname,ipAddress)
     response = rpc.call("key_queue",json.dumps({'fileadd':options.telnet_key_dir,'ipadd':ipAddress,'username':tusername,"password":tpassword}))
     self.redirect("/manage")     
     
     
     
     
예제 #7
0
 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)
예제 #8
0
    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)
예제 #9
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)
     rpc = TelnetRpcClient(options.service_ip)
     Exchange.insert(ename, oname, ipAddress)
     response = rpc.call(
         "key_queue",
         json.dumps({
             'fileadd': options.telnet_key_dir,
             'ipadd': ipAddress,
             'username': tusername,
             "password": tpassword
         }))
     self.redirect("/manage")
예제 #10
0
 def get(self):
     oname = self.get_username()
     template_values = {}
     #page info
     page = self.get_argument('page', 1)
     page = page if page >= 1 else 1
     #get the document count param
     count = self.get_argument('count', 10)
     count = count if count >= 1 else 10
     exchanges = Exchange.get_exchanges(oname)
     paginator = Paginator(exchanges, page, count, len(exchanges))
     template_values['paginator'] = paginator
     template_values['status'] = ''
     self.render_template('/site/exchange.html', **template_values)
예제 #11
0
 def get(self): 
     oname = self.get_username()
     template_values = {}
     #page info
     page = self.get_argument('page', 1)
     page = page if page >= 1 else 1
     #get the document count param
     count = self.get_argument('count', 10)
     count = count if count >= 1 else 10
     exchanges = Exchange.get_exchanges(oname)
     paginator = Paginator(exchanges, page, count, len(exchanges))
     template_values['paginator'] = paginator
     template_values['status'] = ''
     self.render_template('/site/exchange.html', **template_values)
예제 #12
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')       
예제 #13
0
 def post(self):
     oname = self.get_username()
     ename = self.get_argument("ename", None)
     status = self.get_argument("status", None)  
     template_values = {}
     #page info
     page = self.get_argument('page', 1)
     page = page if page >= 1 else 1
     #get the document count param
     count = self.get_argument('count', 10)
     count = count if count >= 1 else 10
     if status is not None:
         template_values['status'] = status
     else:
         template_values['status'] = ''
     exchanges = Exchange.get_condition_exchanges(oname,ename,template_values['status'])
     paginator = Paginator(exchanges, page, count, len(exchanges))
     template_values['paginator'] = paginator
     template_values['ename'] = ename
     self.render_template('/site/exchange.html', **template_values)#/site/bandwidth.html
예제 #14
0
 def post(self):
     oname = self.get_username()
     ename = self.get_argument("ename", None)
     status = self.get_argument("status", None)
     template_values = {}
     #page info
     page = self.get_argument('page', 1)
     page = page if page >= 1 else 1
     #get the document count param
     count = self.get_argument('count', 10)
     count = count if count >= 1 else 10
     if status is not None:
         template_values['status'] = status
     else:
         template_values['status'] = ''
     exchanges = Exchange.get_condition_exchanges(oname, ename,
                                                  template_values['status'])
     paginator = Paginator(exchanges, page, count, len(exchanges))
     template_values['paginator'] = paginator
     template_values['ename'] = ename
     self.render_template('/site/exchange.html',
                          **template_values)  #/site/bandwidth.html
예제 #15
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')
예제 #16
0
 def post(self):
     e_id = self.get_argument('e_id')
     ip = self.get_argument('ip')
     Exchange.updateExchangeIp(e_id, ip)
     self.finish("success")
예제 #17
0
 def post(self):
     _cid = self.get_argument("e_id", None)
     Exchange.updateExchange(_cid, 1)
     self.finish("finished")
예제 #18
0
파일: db_test.py 프로젝트: hc990/let
# -*- coding: utf-8 -*-
예제 #19
0
# -*- coding: utf-8 -*-
예제 #20
0
# -*- coding: utf-8 -*-
예제 #21
0
 def post(self):
     _cid = self.get_argument("e_id", None)
     Exchange.updateExchange(_cid, 0)  
     self.finish("finished")  
예제 #22
0
# -*- coding: utf-8 -*-
예제 #23
0
# simbolos de tres exchanges (NASDAQ, NYSE y AMEX).

# interactive brokers es una plataforma de compra y venta de acciones.
# los simbolos son empresas (TSLA para Tesla, APPL para Apple).
# los exchanges son mercados (NYSE para bolsa de New York).

# recuerda las sabias palabras del tío Bob:
'''A comment is a failure to express yourself in code.
   If you fail, then write a comment; but try not to fail.'''
# si haces comentarios, es mejor que estén en ingles

import csv
import os
from models.exchange import Exchange

os.remove("symbols.csv")
file = open('symbols.csv', 'w')
file.truncate()
writer = csv.writer(file)
list_result = []
exchanges = ['nasdaq', 'nyse', 'amex']

for exchanger_name in exchanges:
    exchanger = Exchange(exchanger_name)
    data_from_exchanger = exchanger.get_data()
    list_result.extend(
        [data for data in data_from_exchanger if data not in list_result])

for val in list_result:
    writer.writerow(val)
file.close()
예제 #24
0
 def post(self):   
     e_id = self.get_argument('e_id')
     ip = self.get_argument('ip')
     Exchange.updateExchangeIp(e_id,ip)
     self.finish("success")
     
예제 #25
0
파일: db_test.py 프로젝트: hc990/let
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)
예제 #26
0
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}
예제 #27
0
# -*- coding: utf-8 -*-
예제 #28
0
파일: test.py 프로젝트: hc990/let
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}