def POST(self): # noqa i = web.input(bras='', action='', ip='') if not i.ip or not i.action or not i.bras: return dumps({ 'status' : Status.ERROR }) if i.bras not in brasses_list: print('dont know dis bras {0}'.format(i.bras)) return dumps({ 'status' : Status.ERROR }) action = H.check_bras_action(i.action) if not action: print('dont know dis action {0}'.format(i.action)) return dumps({ 'status' : Status.ERROR }) ip = H.check_ip(i.ip) if not ip: return dumps({ 'status' : Status.ERROR }) log.save_action(session.name, 'session', 'Делает {0} для сессии {1} на {2}'.format(action, ip, i.bras)) return getattr(brasses_list[i.bras], H.BRAS_FUNCTIONS[action])(ip)
def POST(self): # noqa ''' Возвращает список свободных портов на свитче ''' i = web.input(ip='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) # получим список портов со свитча sw = Switch(swconf, ip) sw_ports = sw.get_local_lldp_ports() if not sw_ports: msg = 'switch {0} dont have lldp ports' print(msg) return dumps({ 'status': Status.EMPTY }) ports = set(sw_ports) # получим список портов которые уже есть в базе db_ports = Topology().get_ports(ip) if db_ports: ports = ports - db_ports return dumps({ 'status': Status.SUCCESS, 'data' : sorted(ports) })
def POST(self): # noqa i = web.input(ip='', port='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) if not i.port: msg = 'no port to del' print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) if i.port.find('.') != -1: msg = 'you cant use dots in portname' print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) port = i.port log.save_action(session.name, 'topadm', 'Удаление порта {0} на свитче {1}'.format(port, ip)) return Topology().delete_link(ip, port)
def POST(self): # noqa log.save_action(session.name, 'cabdiag', 'Попытка сделать кабдиаг') i = web.input(ip='', port='') try: port = int(i.port) except ValueError: msg = 'port not int, port: "{0}"'.format(i.port) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) ip = H.check_ip(i.ip) if not ip: msg = 'not ip' print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'cabdiag', 'Успешный кабдиаг свитч {0} порт {1}'.format(ip, port)) res = swFactory.get_switch_model(ip) if res['status'] != Status.SUCCESS: if res['status'] == Status.NOTFOUND: msg = 'Не смог получить модель свитча!' print('{0} {1}'.format(msg, ip)) return dumps(res) sw = res['sw'] return sw.cable_test(port)
def POST(self): # noqa i = web.input(ip='', port='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) try: port = int(i.port) except ValueError: msg = 'port not int, port: "{0}"'.format(i.port) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) res = swFactory.get_switch_model(ip) log.save_action(session.name, 'macs', 'Просмотр маков на {0} : {1}'.format(ip, port)) if res['status'] != Status.SUCCESS: if res['status'] == Status.NOTFOUND: msg = 'Не смог получить модель свитча!' print('{0} {1}'.format(msg, ip)) return dumps(res) sw = res['sw'] return sw.get_macs(port)
def POST(self): # noqa i = web.input(ip='') ip = H.check_ip(i.ip) if not ip: return dumps({ 'status' : Status.ERROR }) log.save_action(session.name, 'dhcp', 'Просмотр дхцп логов {0}'.format(ip)) return dh.get_dhcp_short_logs(ip)
def POST(self): # noqa i = web.input(srcip='', srcport='', dstip='', dstport='') src_ip = H.check_ip(i.srcip) if not src_ip: msg = 'not src ip "{0}"'.format(i.srcip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) dst_ip = H.check_ip(i.dstip) if not dst_ip: msg = 'not dst ip "{0}"'.format(i.dstip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) if src_ip == dst_ip: msg = 'srcip cant be dstip' print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) if not i.dstport or not i.srcport: msg = 'no dst or src port' print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) if i.dstport.find('.') != -1 or i.srcport.find('.') != -1: msg = 'you cant use dots in portname' print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'topadm', 'Добавление линка между {0} - {1} <=> {2} - {3}'.format( src_ip, i.srcport, dst_ip, i.dstport)) return Topology().add_link(src_ip, i.srcport, dst_ip, i.dstport)
def POST(self): # noqa i = web.input(ip='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) sw = Switch(swconf, ip) return sw.get_snmp_all_ports_status()
def POST(self): # noqa ''' Удаление свитча из базы ''' i = web.input(ip='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'topadm', 'Удаление свитча {0} из топологии'.format(ip)) return Topology().delete_switch(ip)
def GET(self): # noqa ''' Возвращает объект (свитч) из базы ''' i = web.input(inp='') data = H.check_ip(i.inp) if not data: data = H.check_sysname(i.inp) if not data: msg = 'not ip or sysname "{0}"'.format(i.inp) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'topadm', 'Просмотр объекта топологии {0}'.format(data)) return Topology().get_info(data)
def POST(self): # noqa ''' Возвращает список элементов для библиотеки cytoscape и layout ''' i = web.input(inp='') data = H.check_ip(i.inp) if not data: data = H.check_sysname(i.inp) if not data: msg = 'not ip or sysname "{0}"'.format(i.inp) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'topology', 'Просмотр топологии {0}'.format(data)) return Topology().get_topology(data)
def POST(self): # noqa i = web.input(ip='', port='', data='') if not i.ip or not i.port or not i.data: msg = 'wrong (empty) inputs' print(msg) return dumps({ 'status': Status.ERROR, 'msg' : msg }) ip = H.check_ip(i.ip) if not ip: msg = 'wrong ip' print(msg) return dumps({ 'status': Status.ERROR, 'msg' : msg }) # trigger must be 1 for up or 2 for down try: trigger = int(i.data) port = int(i.port) except ValueError: msg = 'wrong port or trigger' print(msg) return dumps({ 'status': Status.ERROR, 'msg' : msg }) if trigger not in (0, 1): msg = 'wrong trigger {0}'.format(trigger) print(msg) return dumps({ 'status': Status.ERROR, 'msg' : msg }) trigger, action = [1, 'поднять'] if trigger == 0 else [0, 'опустить'] log.save_action(session.name, 'ports', 'Пытается {0} порт {1} на свитче {2}'.format(action, port, ip)) sw = Switch(swconf, ip) return sw.change_port_status(port, trigger)
def POST(self): # noqa log.save_action(session.name, 'cabdiagall', 'Попытка сделать масс кабдиаг') i = web.input(ip='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip' return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'cabdiagall', 'Успешный масс кабдиаг свитч {0}'.format(ip)) res = swFactory.get_switch_model(ip) if res['status'] != Status.SUCCESS: if res['status'] == Status.NOTFOUND: msg = 'Не смог получить модель свитча!' print('{0} {1}'.format(msg, ip)) return dumps(res) sw = res['sw'] return sw.cable_test_all()
def POST(self): # noqa i = web.input(bill='', ip='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) bill = H.check_bill(i.bill) if not bill: msg = 'not bill "{0}"'.format(i.bill) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) log.save_action(session.name, 'traffic', 'Просмотр трафика абонента {0}, ip: {1}'.format(bill, ip)) return sb.get_user_traffic(bill, ip)
def POST(self): # noqa i = web.input(inp='') if not i.inp: return dumps({ 'status' : Status.ERROR, 'db' : 'orange' }) log.save_action(session.name, 'ipaddr', 'Поиск в ORANGE {0}'.format(i.inp.encode('utf8'))) bill = H.check_bill(i.inp) ip = None if not bill: ip = H.check_ip(i.inp) if not ip: return dumps({ 'status' : Status.ERROR, 'db' : 'orange' }) res = ora.get_bill_id_for_ip(ip) if res['status'] != Status.SUCCESS: return dumps({ 'status' : Status.ERROR, 'db' : 'orange' }) bill = res['billid'] if not bill: return dumps({ 'status' : Status.EMPTY, 'db' : 'orange' }) if not H.is_region_allowed(bill, session.regions): return dumps({ 'status' : Status.NOAUTH, 'db' : 'orange' }) return ora.get_user_params(bill, ip)
def POST(self): # noqa i = web.input(ip='', port='', curr='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) try: port = int(i.port) except ValueError: msg = 'port not int, port: "{0}"'.format(i.port) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) try: curr = int(i.curr) except ValueError: msg = 'no curr err' print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) res = swFactory.get_switch_model(ip) if res['status'] != Status.SUCCESS: if res['status'] == Status.NOTFOUND: msg = 'Не смог получить модель свитча!' print('{0} {1}'.format(msg, ip)) return dumps(res) sw = res['sw'] return sw.get_count_port_errors(port, curr)
def POST(self): # noqa i = web.input(ip='', port='') ip = H.check_ip(i.ip) if not ip: msg = 'not ip "{0}"'.format(i.ip) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) try: port = int(i.port) except ValueError: msg = 'port not int, port: "{0}"'.format(i.port) print(msg) return dumps({ 'status' : Status.ERROR, 'msg' : msg }) sw = Switch(swconf, ip) return sw.get_snmp_port_status(port)
def POST(self): # noqa i = web.input(billid='', portid='', swip='', swport='') if not i.billid or not i.portid or not i.swip or not i.swport: print('not billid or portid or swip or swport') return dumps({ 'status' : Status.ERROR }) billid = H.check_bill(i.billid) if not billid: print('wrong billid {0}'.format(i.billid)) return dumps({ 'status' : Status.ERROR }) try: portid = int(i.portid) except ValueError: msg = 'portid not int, raw portid: "{0}"'.format(i.portid) print(msg) return dumps({ 'status' : Status.ERROR }) swip = H.check_ip(i.swip) if not swip: msg = 'not switch ip "{0}"'.format(i.swip) print(msg) return dumps({ 'status' : Status.ERROR }) try: swport = int(i.swport) except ValueError: msg = 'swport not int, raw port: "{0}"'.format(i.swport) print(msg) return dumps({ 'status' : Status.ERROR }) log.save_action( session.name, 'reserve', 'Попытка привязать абонента {0} на {1} порт {2}'.format(billid, swip, swport)) res = sb.get_one_subs_id(billid) if res['status'] != Status.SUCCESS: return dumps(res) # есть привязка, освобождаем в оранже if res['portid']: res_in = sb.release_port(res['subsid']) msg = '' if res_in['status'] != Status.SUCCESS: msg = 'Отвязывание абонента {0} с portid {1} прошло с ошибкой!'.format( billid, res['portid']) log.save_action(session.name, 'reserve', msg) return dumps(res_in) msg = 'Успешно отвязал абонента {0} с portid {1}'.format(billid, res['portid']) log.save_action(session.name, 'reserve', msg) # теперь привяжем res = sb.reserve_port(res['subsid'], portid) msg = 'Привязал абонента {0} на {1} порт {2}'.format(billid, swip, swport) if res['status'] != Status.SUCCESS: msg = 'Привязка абонента {0} на {1} порт {2} прошла с ошибкой!'.format(billid, swip, swport) log.save_action(session.name, 'reserve', msg) return dumps(res)
def POST(self): # noqa i = web.input(billid='', portid='', days='', swip='', swport='') if not i.billid or not i.portid or not i.days or not i.swip or not i.swport: print('incorrect parameters {0}'.format(i)) return dumps({ 'status' : Status.ERROR }) billid = H.check_bill(i.billid) if not billid: return dumps({ 'status' : Status.ERROR }) try: portid = int(i.portid) except ValueError: msg = 'port not int, port: "{0}"'.format(i.portid) print(msg) return dumps({ 'status' : Status.ERROR }) try: days = int(i.days) swport = int(i.swport) except ValueError: msg = 'not valid num of days or port: "{0}" "{1}"'.format(i.days, i.swport) print(msg) return dumps({ 'status' : Status.ERROR }) swip = H.check_ip(i.swip) if not swip: print('not switch ip {0}'.format(i.swip)) return dumps({ 'status' : Status.ERROR }) perm = 'relhigh' if days >= 180: perm = 'rellow' if not session.get(perm, False): return dumps({ 'status' : Status.NOAUTH }) log.save_action( session.name, 'release', 'Попытка отвязать абонента {0} с {1} порт {2} portid {3}'.format( billid, swip, swport, portid)) res = sb.get_subs_id_by_portid(billid, portid) if res['status'] != Status.SUCCESS: return dumps(res) perm = 'relhigh' if res['priv'] == 'low': perm = 'rellow' if not session.get(perm, False): return dumps({ 'status' : Status.NOAUTH }) res = sb.release_port(res['subsid']) msg = 'Успешно отвязал абонента {0} c {1} порт {2} portid {3}'.format( billid, swip, swport, portid) if res['status'] != Status.SUCCESS: msg = 'Отвязывание абонента {0} с {1} порт {2} portid {3} прошло с ошибкой!'.format( billid, swip, swport, portid) log.save_action(session.name, 'release', msg) return dumps(res)