def main(): print('config.network_devices: ', settings.config['network_device'].keys()) print('mounted: ', topology.mounted_nodes()) print('unmounted: ', topology.unmounted_nodes()) print('connected: ', topology.connected_nodes()) print('disconnected: ', topology.disconnected_nodes())
def main(): for device_name in topology.connected_nodes(): print('%s:' % device_name) for interface_name in topology_interface.interface_names(device_name): #print('Interface Properties for %s:' % interface_name) interface_properties = topology_interface.interface_properties(device_name, interface_name) print('\t', interface_name, '-->', interface_properties)
def main(): for device_name in topology.connected_nodes(): print('%s:' % device_name) for interface_name in topology_interface.interface_names(device_name): #print('Interface Properties for %s:' % interface_name) interface_configuration = topology_interface.interface_configuration(device_name, interface_name) print('\t', interface_name, '-->', interface_configuration)
def main(): device_list=settings.config['network_device'] #dismount each nodes mounted_list = topology.mounted_nodes() if mounted_list: for device_name in mounted_list: topology.dismount(device_name) print('all devices dismount.') #mount each nodes unmounted_list = topology.unmounted_nodes() if unmounted_list: for device_name in unmounted_list: mount_device(device_name) print('mount %s' % device_name) time.sleep(1) print('mount each nodes.') time.sleep(5) connected_list = topology.connected_nodes() print('connected: ', connected_list) #mount each disconnected nodes mounted_list = topology.mounted_nodes() while len(device_list)!=len(connected_list): print('%s devices connected' % len(connected_list)) for device_name in device_list: if device_name in connected_list: continue else: if device_name in mounted_list: topology.dismount(device_name) print('dismount %s' % device_name) time.sleep(1) mount_device(device_name) print('mount %s' % device_name) time.sleep(3) if device_name in topology.connected_nodes(): print('connected %s success' % device_name) else: print('connected %s failed' % device_name) connected_list = topology.connected_nodes() print('all devices are connected!', connected_list)
def main(): for device_name in topology.connected_nodes(): print('%s:' % device_name) for interface_name in topology_interface.interface_names(device_name): #print('Interface Properties for %s:' % interface_name) interface_properties = topology_interface.interface_properties( device_name, interface_name) print( '\t', interface_name, '-->', interface_properties['interface'][0]['state'].encode('utf-8'))
def connected_all_devices(): print(pydoc.plain(pydoc.render_doc(topology.mount))) unmounted_list = topology.unmounted_nodes() if unmounted_list: for device_name in unmounted_list: mount_device(device_name) # time.sleep(15) else: print('There are no (configured) devices unmounted.') print(pydoc.plain(pydoc.render_doc(topology.connected))) print('connected: ', topology.connected_nodes())
def main(): connected_nodes = topology.connected_nodes() if connected_nodes: node_id = connected_nodes[0] interface_names = topology_interface.interface_names(node_id) if interface_names: interface_name = interface_names[0] print('Shutting down interface %s on %s' % (interface_name, node_id)) topology_interface.interface_shutdown(node_id, interface_name) else: print('No interfaces on %s' % node_id) else: print('No connected devices')
def main(): connected_nodes = topology.connected_nodes() if connected_nodes: node_id = connected_nodes[0] interface_names = topology_interface.interface_names(node_id) if interface_names: interface_name = interface_names[0] print('Starting up interface %s on %s' % (interface_name, node_id)) topology_interface.interface_startup(node_id, interface_name) else: print('No interfaces on %s' % node_id) else: print('No connected devices')
def main(): device_list = settings.config['network_device'] connected_list = topology.connected_nodes() if len(connected_list) != len(device_list): print('not all devices are connected!') return device_1 = 'iosxrv-1' device_2 = 'iosxrv-2' device_3 = 'iosxrv-3' device_4 = 'iosxrv-4' device_5 = 'iosxrv-5' device_6 = 'iosxrv-6' device_7 = 'iosxrv-7' device_8 = 'iosxrv-8' interface_0 = 'GigabitEthernet0/0/0/0' interface_1 = 'GigabitEthernet0/0/0/1' interface_2 = 'GigabitEthernet0/0/0/2' interface_3 = 'GigabitEthernet0/0/0/3' interface_4 = 'GigabitEthernet0/0/0/4' interface_5 = 'GigabitEthernet0/0/0/5' interface_6 = 'GigabitEthernet0/0/0/6' #add static route for flow 1 destination_network = to_ip_network('100.0.0.0', '24') #device_1 next_hop_address = '10.0.12.2' discription = 'for flow 1: to device_2' add_static_route(device_1, destination_network, next_hop_address, discription, 0) #device_2 next_hop_address = '198.18.1.34' discription = 'for flow 1: to device_5' add_static_route(device_2, destination_network, next_hop_address, discription, 0) #device_8 next_hop_address = '10.0.28.2' discription = 'for flow 1: to device_2' add_static_route(device_8, destination_network, next_hop_address, discription, 0) #display print('add route for flow 1 (to 100.0.0.0/24): ', device_8, ' -> ', device_2) #add static route for flow 2 destination_network = to_ip_network('200.0.0.0', '24') #device_1 next_hop_address = '10.0.12.2' discription = 'for flow 2: to device_2' add_static_route(device_1, destination_network, next_hop_address, discription, 0) #device_2 next_hop_address = '198.18.1.34' discription = 'for flow 2: to device_5' add_static_route(device_2, destination_network, next_hop_address, discription, 0) #device_8 next_hop_address = '10.0.18.1' discription = 'for flow 2: to device_1' add_static_route(device_8, destination_network, next_hop_address, discription, 0) #display print('add route for flow 2 (to 200.0.0.0/24): ', device_8, ' -> ', device_1, ' -> ', device_2) #add static route for flow 3 destination_network = to_ip_network('50.0.0.0', '24') next_hop_address = '198.18.1.32' discription = 'for flow 3: to device_3' add_static_route(device_8, destination_network, next_hop_address, discription, 0) #display print('add route for flow 3 (to 50.0.0.0/24): ', device_8, ' -> black_hole') #display static route print('\n') routes = static_route_list(device_8) print('static route table', device_8) print_table(routes)
def main(): device_list=settings.config['network_device'] connected_list = topology.connected_nodes() if len(connected_list) != len(device_list): print('not all devices are connected!') return device_1 = 'iosxrv-1' device_2 = 'iosxrv-2' device_3 = 'iosxrv-3' device_4 = 'iosxrv-4' device_5 = 'iosxrv-5' device_6 = 'iosxrv-6' device_7 = 'iosxrv-7' device_8 = 'iosxrv-8' interface_0 = 'GigabitEthernet0/0/0/0' interface_1 = 'GigabitEthernet0/0/0/1' interface_2 = 'GigabitEthernet0/0/0/2' interface_3 = 'GigabitEthernet0/0/0/3' interface_4 = 'GigabitEthernet0/0/0/4' interface_5 = 'GigabitEthernet0/0/0/5' interface_6 = 'GigabitEthernet0/0/0/6' #add static route for flow 1 destination_network = to_ip_network('100.0.0.0', '24') #device_1 next_hop_address = '10.0.12.2' add_static_route(device_1, destination_network, next_hop_address, 0) #device_2 next_hop_address = '198.18.1.34' add_static_route(device_2, destination_network, next_hop_address, 0) #device_8 next_hop_address = '10.0.28.2' add_static_route(device_8, destination_network, next_hop_address, 0) #display print('add route for flow 1 (to 100.0.0.0/24): ', device_8, ' -> ', device_2) #add static route for flow 2 destination_network = to_ip_network('200.0.0.0', '24') #device_1 next_hop_address = '10.0.12.2' add_static_route(device_1, destination_network, next_hop_address, 0) #device_2 next_hop_address = '198.18.1.34' add_static_route(device_2, destination_network, next_hop_address, 0) #device_8 next_hop_address = '10.0.18.1' add_static_route(device_8, destination_network, next_hop_address, 0) #display print('add route for flow 2 (to 200.0.0.0/24): ', device_8, ' -> ', device_1, ' -> ', device_2) #add static route for flow 3 destination_network = to_ip_network('50.0.0.0', '24') next_hop_address = '198.18.1.32' add_static_route(device_8, destination_network, next_hop_address, 0) #display print('add route for flow 3 (to 50.0.0.0/24): ', device_8, ' -> black_hole') #display static route print('\n') routes = static_route_list(device_8) print('static route table', device_8) print_table(routes)
def main(): print(pydoc.plain(pydoc.render_doc(topology.connected))) print('connected: ', topology.connected_nodes())
def main(): for device_name in topology.connected_nodes(): for capability_name in topology.capability(device_name): print(device_name, capability_name)
def main(): for device_name in topology.connected_nodes(): print('Management Interface for %s:' % device_name, topology_interface.management_interface_name(device_name))
def main(): print("config.network_devices: ", settings.config["network_device"].keys()) print("mounted: ", topology.mounted_nodes()) print("unmounted: ", topology.unmounted_nodes()) print("connected: ", topology.connected_nodes()) print("disconnected: ", topology.disconnected_nodes())
def main(): #device_list=settings.config['network_device'] device_list = settings.config['network_device'] connected_list = topology.connected_nodes() if len(connected_list) != len(device_list): print('not all devices are connected!') return device_1 = 'iosxrv-1' device_2 = 'iosxrv-2' device_3 = 'iosxrv-3' device_4 = 'iosxrv-4' device_5 = 'iosxrv-5' device_6 = 'iosxrv-6' device_7 = 'iosxrv-7' device_8 = 'iosxrv-8' interface_0 = 'GigabitEthernet0/0/0/0' interface_1 = 'GigabitEthernet0/0/0/1' interface_2 = 'GigabitEthernet0/0/0/2' interface_3 = 'GigabitEthernet0/0/0/3' interface_4 = 'GigabitEthernet0/0/0/4' interface_5 = 'GigabitEthernet0/0/0/5' interface_6 = 'GigabitEthernet0/0/0/6' #change path for flow 1 destination_network = to_ip_network('100.0.0.0', '24') prior_next_hop = '10.0.28.2' second_next_hop = '10.0.18.1' if (interface_configuration_tuple(device_2, interface_2).shutdown == False) & (interface_configuration_tuple( device_8, interface_2).shutdown == False): link_status = 'up' else: link_status = 'down' #loop #for i in range(100): while True: #check the link if (interface_configuration_tuple(device_2, interface_2).shutdown == False) & (interface_configuration_tuple( device_8, interface_2).shutdown == False): new_status = 'up' #print('link: device_2 <-> device_8 is OK') else: new_status = 'down' #print('link: device_2 <-> device_8 is fail') #link status unchange if link_status == new_status: print('device_2 <-> device_8 link status unchange') time.sleep(1) continue #link status up -> down elif (link_status == 'up') & (new_status == 'down'): delete_static_route(device_8, destination_network, 1) add_static_route(device_8, destination_network, second_next_hop, 1) print( 'device_2 <-> device_8 link status from up to down: delete prior_route, add second_route, at last for 10s' ) link_status = new_status time.sleep(10) #link status down -> up elif (link_status == 'down') & (new_status == 'up'): delete_static_route(device_8, destination_network, 1) add_static_route(device_8, destination_network, prior_next_hop, 1) print( 'device_2 <-> device_8 link status from down to up: delete second_route, add prior_route' ) link_status = new_status time.sleep(3)
def main(): device_list=settings.config['network_device'] connected_list = topology.connected_nodes() if len(connected_list) != len(device_list): print('not all devices are connected!') return device_1 = 'iosxrv-1' device_2 = 'iosxrv-2' device_3 = 'iosxrv-3' device_4 = 'iosxrv-4' device_5 = 'iosxrv-5' device_6 = 'iosxrv-6' device_7 = 'iosxrv-7' device_8 = 'iosxrv-8' interface_0 = 'GigabitEthernet0/0/0/0' interface_1 = 'GigabitEthernet0/0/0/1' interface_2 = 'GigabitEthernet0/0/0/2' interface_3 = 'GigabitEthernet0/0/0/3' interface_4 = 'GigabitEthernet0/0/0/4' interface_5 = 'GigabitEthernet0/0/0/5' interface_6 = 'GigabitEthernet0/0/0/6' #link device_1 to device_2 initial = interface_configuration_tuple(device_1, interface_0) #print_table(initial) ip_address = '10.0.12.1' ip_netmask = '255.255.255.0' description = 'connect to device_2' interface_configuration_update(device_1, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False) print_table(interface_configuration_tuple(device_1, interface_0)) #link device_2 to device_1 initial = interface_configuration_tuple(device_2, interface_0) #print_table(initial) ip_address = '10.0.12.2' ip_netmask = '255.255.255.0' description = 'connect to device_1' interface_configuration_update(device_2, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False) print_table(interface_configuration_tuple(device_2, interface_0)) #display print('set link device_1 <-> device_2') #link device_1 to device_8 initial = interface_configuration_tuple(device_1, interface_5) #print_table(initial) ip_address = '10.0.18.1' ip_netmask = '255.255.255.0' description = 'connect to device_8' interface_configuration_update(device_1, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False) print_table(interface_configuration_tuple(device_1, interface_5)) #link device_8 to device_1 initial = interface_configuration_tuple(device_8, interface_1) #print_table(initial) ip_address = '10.0.18.8' ip_netmask = '255.255.255.0' description = 'connect to device_1' interface_configuration_update(device_8, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False) print_table(interface_configuration_tuple(device_8, interface_1)) #display print('set link device_1 <-> device_8') #link device_2 to device_8 initial = interface_configuration_tuple(device_2, interface_2) #print_table(initial) ip_address = '10.0.28.2' ip_netmask = '255.255.255.0' description = 'connect to device_8' interface_configuration_update(device_2, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False) print_table(interface_configuration_tuple(device_2, interface_2)) #link device_8 to device_2 initial = interface_configuration_tuple(device_8, interface_2) #print_table(initial) ip_address = '10.0.28.8' ip_netmask = '255.255.255.0' description = 'connect to device_2' interface_configuration_update(device_8, initial.name, description=description, address=ip_address, netmask=ip_netmask, shutdown=False) print_table(interface_configuration_tuple(device_8, interface_2)) #display print('set link device_2 <-> device_8')
def main(): for device_name in topology.connected_nodes(): print('Interface Names for %s:' % device_name, topology_interface.interface_names(device_name))
''' #create static route : iosxrv-1 iosxrv-5 device_name1 = 'iosxrv-1' request_content1 = {'Cisco-IOS-XR-ip-static-cfg:vrf-prefix': [{'prefix': '27.27.27.27', 'vrf-route': {'vrf-next-hops': {'next-hop-address': [{'next-hop-address': '45.0.0.27'}]}}, 'prefix-length': 32}]} response1 = odl_http_post(_static_route_url_template, {'node-id' : device_name1}, 'application/json', request_content1, expected_status_code=[204, 409]) device_name5 = 'iosxrv-5' request_content5 = {'Cisco-IOS-XR-ip-static-cfg:vrf-prefix': [{'prefix': '21.21.21.21', 'vrf-route': {'vrf-next-hops': {'next-hop-address': [{'next-hop-address': '45.0.0.21'}]}}, 'prefix-length': 32}]} response5 = odl_http_post(_static_route_url_template, {'node-id' : device_name5}, 'application/json', request_content5, expected_status_code=[204, 409]) #read interface state for every 5 second count = 0 for i in range(0,9): flag = True for device_name in topology.connected_nodes(): #print('%s:' % device_name) if device_name == "iosxrv-1": for interface_name in topology_interface.interface_names(device_name): #print('Interface Properties for %s:' % interface_name) if interface_name == "GigabitEthernet0/0/0/4": interface_properties = topology_interface.interface_properties(device_name, interface_name) print('\t', interface_name, '-->', interface_properties['interface'][0]['state'].encode('utf-8')) interface_status = interface_properties['interface'][0]['state'].encode('utf-8') #if interface status is shutdown, count++ if interface_status == "im-state-up": pass else: flag = False
def main(): #device_list=settings.config['network_device'] device_list = settings.config['network_device'] connected_list = topology.connected_nodes() if len(connected_list) != len(device_list): print('not all devices are connected!') return device_1 = 'iosxrv-1' device_2 = 'iosxrv-2' device_3 = 'iosxrv-3' device_4 = 'iosxrv-4' device_5 = 'iosxrv-5' device_6 = 'iosxrv-6' device_7 = 'iosxrv-7' device_8 = 'iosxrv-8' interface_0 = 'GigabitEthernet0/0/0/0' interface_1 = 'GigabitEthernet0/0/0/1' interface_2 = 'GigabitEthernet0/0/0/2' interface_3 = 'GigabitEthernet0/0/0/3' interface_4 = 'GigabitEthernet0/0/0/4' interface_5 = 'GigabitEthernet0/0/0/5' interface_6 = 'GigabitEthernet0/0/0/6' #change path for flow 1 destination_network = to_ip_network('100.0.0.0', '24') prior_next_hop = '10.0.28.2' second_next_hop = '10.0.18.1' if (interface_configuration_tuple(device_2, interface_2).shutdown == False) & (interface_configuration_tuple(device_8, interface_2).shutdown == False): link_status = 'up' else: link_status = 'down' #loop #for i in range(100): while True: #check the link if (interface_configuration_tuple(device_2, interface_2).shutdown == False) & (interface_configuration_tuple(device_8, interface_2).shutdown == False): new_status = 'up' #print('link: device_2 <-> device_8 is OK') else: new_status = 'down' #print('link: device_2 <-> device_8 is fail') #link status unchange if link_status == new_status: print('device_2 <-> device_8 link status unchange') time.sleep(1) continue #link status up -> down elif (link_status == 'up') & (new_status == 'down'): delete_static_route(device_8, destination_network, 1) add_static_route(device_8, destination_network, second_next_hop, 1) print('device_2 <-> device_8 link status from up to down: delete prior_route, add second_route, at last for 10s') link_status = new_status time.sleep(10) #link status down -> up elif (link_status == 'down') & (new_status == 'up'): delete_static_route(device_8, destination_network, 1) add_static_route(device_8, destination_network, prior_next_hop, 1) print('device_2 <-> device_8 link status from down to up: delete second_route, add prior_route') link_status = new_status time.sleep(3)