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 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()
Ejemplo n.º 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()
Ejemplo n.º 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")
Ejemplo n.º 5
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.º 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")     
     
     
     
     
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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')       
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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')
Ejemplo n.º 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")
Ejemplo n.º 17
0
 def post(self):
     _cid = self.get_argument("e_id", None)
     Exchange.updateExchange(_cid, 1)
     self.finish("finished")
Ejemplo n.º 18
0
Archivo: db_test.py Proyecto: hc990/let
# -*- coding: utf-8 -*-
Ejemplo n.º 19
0
# -*- coding: utf-8 -*-
Ejemplo n.º 20
0
# -*- coding: utf-8 -*-
Ejemplo n.º 21
0
 def post(self):
     _cid = self.get_argument("e_id", None)
     Exchange.updateExchange(_cid, 0)  
     self.finish("finished")  
Ejemplo n.º 22
0
# -*- coding: utf-8 -*-
Ejemplo n.º 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()
Ejemplo n.º 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")
     
Ejemplo n.º 25
0
Archivo: db_test.py Proyecto: 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)
Ejemplo n.º 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}
Ejemplo n.º 27
0
# -*- coding: utf-8 -*-
Ejemplo n.º 28
0
Archivo: test.py Proyecto: 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}