except: print("Edge doesn't exist") sys.exit(1) # Check uplink IP address --------------------------------------------------- # Get uplink IP address print('\nChecking the uplink IP address') pe['routerId'] = nsx.getuplinkip(edgeid) if pe['routerId'] == 'None': print("Uplink port vNIC_0 has no Ip address") sys.exit(1) # Configure Router ID ----------------------------------------------------- # Define XML Body - Global Routing > router ID xml_routerID = createbody("templates/routerid.j2", pe) # Configure Router ID print('\nConfiguring Router ID') nsx.cfgglobrouting(xml_routerID, edgeid) # Configure BGP peering ----------------------------------------------------- # Define XML Body - BGP xml_BGP = createbody("templates/bgp.j2", pe['bgp']) # Configure BGP print('\nConfiguring BGP peering') nsx.cfgbgp(xml_BGP, edgeid)
for i in range(len(pe['static'])): if pe['static'][i]['route'] != '0.0.0.0/0': pe['redistrib'].append(pe['static'][i]) cprint('These static routes will be redistributed into BGP: ', 'yellow') print('Note: dupplicate routes and the default route have been removed') for i in range(len(pe['redistrib'])): print(pe['redistrib'][i]['route'] + ' -> ' + pe['redistrib'][i]['next_hop'] + ' -> vnic-' + str(pe['redistrib'][i]['vnic']) + ', AD ' + str(pe['redistrib'][i]['admin_distance'])) print('\n') cprint(pe['banner'], 'yellow') agree = raw_input("Do you want to apply these changes? y/n[N]: " or 'N') # Proceed with updating the configuration if agree != "Y" and agree != "y": print("Script execution canceled") sys.exit(1) else: # Configure route redistribution from Static to BGP routing ------------------------ # Define XML Body - Redistribution xml_Redistrib = createbody("templates/bgp_redistrib.j2", pe) # print(xml_Redistrib) # Configure redistribution print('\nReconfiguring BGP and route redistribution from Static to BGP') nsx.cfgbgp(xml_Redistrib, edgeid)