Exemple #1
0
 def save_interfaces_state_db(self, template='internet_ufinet.yml'):
     template_data = yaml.load(open(template).read())
     methods = ['set_interfaces']
     for device_group, data in template_data.items():
         if 'network' in data:
             devices = Devices(self.master, network=data['network'])
         else:
             devices = Devices(self.master, ip_list=data['devices'])
         devices.remove_duplicates_db()
         devices.execute(methods=methods, thread_window=10)
         for filter_ in data['filters']:
             devices.execute(methods=["save_interfaces_states"],
                             kwargs={
                                 ip: {
                                     "save_interfaces_states": {
                                         'filters': filter_
                                     }
                                 }
                                 for ip in devices.keys()
                             },
                             thread_window=25)
             devices.execute(methods=["correct_ip_interfaces"],
                             thread_window=55)
Exemple #2
0
#     "ip_seed_router": "172.17.22.52",
#     "process_id": '502', "area": '502008', 'network_name': 'RCE_GUATEMALA'
# }
# dbd = ospf_database(isp=isp, source='real_time', **honduras)
#
# hn_ips = list(dbd.devices.devices.keys())
# with open("hn_ips", "w") as f:
#     f.write('\n'.join(hn_ips))

with open("hn_ips", "r") as f:
    ips = [line.replace("\n", "") for line in f]

devs = Devices(ip_list=ips, master=isp.master, check_up=True)
methods = {'set_ip_ospf_interfaces', 'set_interfaces_snmp'}
kwargs = {dev.ip: {'set_ospf_interfaces': {'as_ospf': '504'}} for dev in devs}
devs.execute(methods=methods)

data_devices = {}
suffix = ' L3:MPLOSP D:B L1:DP '
for dev in devs:
    data_devices[dev.ip] = []
    for index, ospf_data in dev.ospf_interfaces.items():
        data_config = f' interface {index} \n description {suffix} {dev.interfaces[index].description}'
        data_devices[dev.ip].append()

pickle.dump(data_devices, open("hn.p", "wb"))

# pickle.dump(def_dict,open( "gt.p", "wb" ))
# pprint(def_dict)
# def_dict = pickle.load(open( "gt.p", "rb" ))
# ips = list(def_dict.keys())
Exemple #3
0
connection = master.db_connect()
with connection.cursor() as cursor:
    cursor.execute(sql)
    data = cursor.fetchall()
    uids = {row['net_device_uid'] for row in data}
window = 15
for diagram in diagrams:
    not_polled = set(diagram.state.devices_uid.keys()).difference(uids)
    if not_polled:
        ips = [diagram.state.devices_uid[k].ip for k in not_polled]
        ips_uid = {diagram.state.devices_uid[k].ip: k for k in not_polled}
        top_ten_ips = ips[0:window - 1] if len(ips) > window else ips
        ips_uid = {ip: ips_uid[ip] for ip in top_ten_ips}
        break

#
#
devs = Devices(master=Master(), ip_list=top_ten_ips, check_up=False)
for dev in devs:
    dev.uid = ips_uid[dev.ip]
devs.add_snmp_event(event='interfaces', type='asyc')

devs.execute(methods=["set_snmp_community"], thread_window=50)
devs.execute_processes(methods=["set_interfaces_snmp"], thread_window=50)
#
#
# asyncio.get_event_loop().run_until_complete(devs.interfaces_async())
#
#
devs.save_interfaces()
Exemple #4
0
from model.Devices import Devices
from config.Master import Master
from model.Diagram import Diagram
import asyncio
import datetime

top_ten_ips = ['172.16.30.247']
#
devs = Devices(master=Master(), ip_list=top_ten_ips, check_up=False)
devs.devices['172.16.30.247'].uid_db()

devs.add_snmp_event(event='interfaces', type='asyc')

devs.devices['172.16.30.247'].community = 'pnrw-all'
devs.execute(methods=['set_interfaces_snmp'])
#
#
# asyncio.get_event_loop().run_until_complete(devs.set_interfaces_snmp())

print(devs.devices['172.16.30.247'].interfaces['BVI2150'].util_in)
#
#