import netbrain_restful_lib as api import base64 ########## nb_url = "http(s)://<IP address of NetBrain Web Server>/" user = "NetBtain" pwd = "Netbrain" tenantName ='Initial Tenant' domainName = 'Integration' ########## # Step2.1: Login into NetBrain session and get system token. token = api.loginSession(nb_url, user, pwd) print(api.getTenants(nb_url, token)) print(api.getDomains(nb_url, token)) # [{'tenantId': 'cb36f82b-4126-2fef-5310-c3a66f3dae4d', 'tenantName': 'Initial Tenant'}, # {'tenantId': '1aae7b92-520f-4d22-96ed-9ccc77ab5678', 'tenantName': 'TenantName'}] # [{'domainId': '6f9be63d-2290-4121-ae8b-c8fdb53a56ec', 'domainName': 'Integration'}] tenantId = "cb36f82b-4126-2fef-5310-c3a66f3dae4d" domainId = "6f9be63d-2290-4121-ae8b-c8fdb53a56ec" # Step2.2: Set the operation tenant and domain. print(api.loginDomain(nb_url, token, tenantId, domainId)) # loginDomain: Login successfully! # Step2.3: Get the default gateway information of Source IP. sourceIP = "10.30.8.108" api.GetGatewayInfo(nb_url, token, sourceIP) # [{'ip': '10.30.8.105', 'devName': 'HSRP', 'intfName': '21'}, # {'ip': '10.30.8.106', 'devName': 'NBCNBJ-SW1', 'intfName': 'Vlan2100'}, # {'ip': '10.30.8.107', 'devName': 'NBCNBJ-SW2', 'intfName': 'Vlan2100'}] # Step2.4: Trigger Path and get Map ID. stub_name = "PathStub" sourceGwIP = "10.30.8.105" destIP = "10.30.7.108" sourcePort = 80 destPort = 80 TriggerPathInput = { 'domain_setting': { 'tenant_id': tenantId, 'domain_id': domainId }, #Trigger Stub information 'basic_setting': { 'user': user, 'stub_name': stub_name, # Name of the stub you created in NetBrain 'triggered_by':"API Script", }, #Map information (Optional) "map_setting": { "map_create_mode":3, #3 is Path mode "map_path_para": { "source": sourceIP, "source_gateway": sourceGwIP, "destination":destIP, "source_port":sourcePort, "destination_port":destPort } } } map_url = api.TriggerPathMap(nb_url, token, TriggerPathInput) print(map_url) # MapURL: https://integrationlabv71.netbraintech.com/map.html?t=cb36f82b-4126-2fef-5310-c3a66f3dae4d # &d=6f9be63d-2290-4121-ae8b-c8fdb53a56ec&id=145f86ad-de4e-4b7b-9ea9-48c52c20319f&maptype=1 # Step2.5.0: Open Map in API Triggered Tasks. # Step2.5.1: [Optional] Export the Map Visio or Xmap. map_format = "visio" # visio or xmap pages = None # Specify the Map page. If None, all pages will be exported. map_data = api.ExportMap(nb_url, token, map_url, map_format, pages) if map_data: folder = r"D:\\path.vsdx" with open(folder, "wb") as ff: ff.write(base64.b64decode(map_data)) |