If you maintain and update site structures in another vendor, you can use NetBrain APIs to make the same site updates in NetBrain, such as adding sites and removing devices from a site.
The pseudo-code below describes the main flow in the API script to replace devices in a site.
1. Login to NetBrain API server and get session
2. Set current domain
3. Replace devices to existing site
4. Call Commit to commit the change
5. Call GetSiteTree to confirm that all sites are created and devices are set
6. Logout NetBrain API server
You can refer to the script below to call relative APIs. This sample script first imports a python library maintained by NetBrain and you need to write your own one in practical use.
import netbrain_restful_lib
import time
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
user = "NetBrain"
pwd = "Netbrain"
nb_url = "http(s)://<IP address of NetBrain Web Server>/"
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
tenantName = "Initial Tenant"
domainName = "Use Case"
#################################################################
# Step 1: Login to NetBrain API server and get session
print("Step 1")
token = netbrain_restful_lib.loginSession(nb_url, user, pwd)
print("Token: "+token)
print(netbrain_restful_lib.getTenants(nb_url, token))
print(netbrain_restful_lib.getDomains(nb_url, token))
#Sample results
# token : adf5b560-8e9c-4114-87bb-2eed24f0faff
# tenantList : [{'tenantId': 'a50af282-fa02-012f-a7f7-e410cc7c29d3', 'tenantName': 'Initial Tenant'}]
# domainList : [{'domainName': 'UseCase', 'domainId': '4f747a8b-71da-404b-a05c-e8505aa14725'}]
tenantId = 'fcf8a380-6b11-0fed-1d51-3b4cdef8f238'
domainId = '25b66365-1ab8-4fed-90c9-1307a4047c3d'
# Step 2: Set current domain
print("Step 2")
print(netbrain_restful_lib.loginDomain(nb_url, token, tenantId, domainId))
# Sample results
# loginDomain: Login successfully!
# Step 3: Replace devices to existing site
print("Step 3")
data=[{"sitePath":"My Network/US/CA/San Diego", "devices":["BSTX"]} ]
print(netbrain_restful_lib.createSiteTransaction(nb_url, token))
for i in data:
print(i['sitePath'])
print(i["devices"])
print(netbrain_restful_lib.replaceSiteDevice(nb_url, token, None, i['sitePath'], i["devices"]))
# Sample results
# CreateSiteTransaction: Site transaction created!
# ReplaceSiteDevice: Device moved successfully!
# Step 4: Call Commit to commit the change
print("Step 4")
print(netbrain_restful_lib.commitSiteTransaction(nb_url, token))
# Sample results
# CommitSiteTransaction: Site commit True
# Step 5: Call GetSiteTree to confirm that all sites are created and devices are set
print("Step 5")
print(netbrain_restful_lib.getChildSites(nb_url, token, None, "My Network"))
for i in data:
print(netbrain_restful_lib.getSiteInfo(nb_url, token, None, i['sitePath']))
print(netbrain_restful_lib.getSiteDevice(nb_url, token, None, i['sitePath']))
# Sample results
# GetChildSites: [{'siteId': 'aac212cb-fa84-4ddd-8c0b-18a00ec9c323', 'isContainer': False, 'siteType': 2, 'sitePath': 'My Network/NA/US/MA'}, {'siteId': '3ebb978f-323a-4308-8b38-82fa1a0a135f', 'isContainer': False, 'siteType': 2, 'sitePath': 'My Network/NA/US/CA'}]
# GetSiteInfo: {'isContainer': True, 'siteId': 'ede2ed2b-d5cf-48dd-b341-020330757033', 'sitePath': 'My Network/NA/US', 'siteType': 1}
# GetSiteDevice: [{'mgmtIP': '172.16.8.186', 'id': '06840b62-8a67-4cb2-9ed4-e540ea36fdcf', 'hostname': 'NBUSMA-SW7'}, {'mgmtIP': '172.16.8.194', 'id': '0b152c13-34e0-474e-aa4c-b07fe71cc0b7', 'hostname': 'NBUSMA-R1'}]
# Step 6: Logout Netbrain API server
print("Step 6")
print(netbrain_restful_lib.logoutSession(nb_url, token))
The pseudo-code below describes the main flow in the API script to remove devices from a site.
1. Login to NetBrain API server and get session
2. Set current domain
3. Remove device from leaf site
4. Call Commit to commit the change
5. Call GetSiteTree to confirm that all sites are created and devices are set
6. Logout NetBrain API server
You can refer to the script below to call relative APIs. This sample script first imports a python library maintained by NetBrain and you need to write your own one in practical use.
import netbrain_restful_lib
import time
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
user = "NetBrain"
pwd = "Netbrain"
nb_url = "http(s)://<IP address of NetBrain Web Server>/"
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
tenantName = "Initial Tenant"
domainName = "Use Case"
#################################################################
# Step 1: Login to NetBrain API server and get session
print("Step 1")
token = netbrain_restful_lib.loginSession(nb_url, user, pwd)
print("Token: "+token)
print(netbrain_restful_lib.getTenants(nb_url, token))
print(netbrain_restful_lib.getDomains(nb_url, token))
#Sample results
# token : adf5b560-8e9c-4114-87bb-2eed24f0faff
# tenantList : [{'tenantId': 'a50af282-fa02-012f-a7f7-e410cc7c29d3', 'tenantName': 'Initial Tenant'}]
# domainList : [{'domainName': 'UseCase', 'domainId': '4f747a8b-71da-404b-a05c-e8505aa14725'}]
tenantId = 'fcf8a380-6b11-0fed-1d51-3b4cdef8f238'
domainId = '25b66365-1ab8-4fed-90c9-1307a4047c3d'
# Step 2: Set current domain
print("Step 2")
print(netbrain_restful_lib.loginDomain(nb_url, token, tenantId, domainId))
# Sample results
# loginDomain: Login successfully!
# Step 3: Remove device from leaf site
print("Step 3")
data=[{"sitePath":"My Network/US/CA/San Diego", "devices":["BSTX"]} ]
print(netbrain_restful_lib.createSiteTransaction(nb_url, token))
for i in data:
print(i['sitePath'])
print(i["devices"])
print(netbrain_restful_lib.deleteSiteDevice(nb_url, token, None, i['sitePath'], i["devices"]))
# Sample results
# CreateSiteTransaction: Site transaction created!
# DeleteSiteDevice: Device removed successfully!
# Step 4: Call Commit to commit the change
print("Step 4")
print(netbrain_restful_lib.commitSiteTransaction(nb_url, token))
# Sample results
# CommitSiteTransaction: Site commit True
# Step 5: Call GetSiteTree to confirm that all sites are created and devices are set
print("Step 5")
print(netbrain_restful_lib.getChildSites(nb_url, token, None, "My Network"))
for i in data:
print(netbrain_restful_lib.getSiteInfo(nb_url, token, None, i['sitePath']))
print(netbrain_restful_lib.getSiteDevice(nb_url, token, None, i['sitePath']))
# Sample results
# GetChildSites: [{'siteId': 'aac212cb-fa84-4ddd-8c0b-18a00ec9c323', 'isContainer': False, 'siteType': 2, 'sitePath': 'My Network/NA/US/MA'}, {'siteId': '3ebb978f-323a-4308-8b38-82fa1a0a135f', 'isContainer': False, 'siteType': 2, 'sitePath': 'My Network/NA/US/CA'}]
# GetSiteInfo: {'isContainer': True, 'siteId': 'ede2ed2b-d5cf-48dd-b341-020330757033', 'sitePath': 'My Network/NA/US', 'siteType': 1}
# GetSiteDevice: [{'mgmtIP': '172.16.8.186', 'id': '06840b62-8a67-4cb2-9ed4-e540ea36fdcf', 'hostname': 'NBUSMA-SW7'}, {'mgmtIP': '172.16.8.194', 'id': '0b152c13-34e0-474e-aa4c-b07fe71cc0b7', 'hostname': 'NBUSMA-R1'}]
# Step 6: Logout Netbrain API server
print("Step 6")
print(netbrain_restful_lib.logoutSession(nb_url, token))
The pseudo-code below describes the main flow in the API script to delete a site.
1. Login to NetBrain API server and get session
2. Set current domain
3. Delete site
4. Call Commit to commit the change
5. Call GetSiteTree to confirm that all sites are created and devices are set
6. Logout NetBrain API server
You can refer to the script below to call relative APIs. This sample script first imports a python library maintained by NetBrain and you need to write your own one in practical use.
import netbrain_restful_lib
import time
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
user = "NetBrain"
pwd = "Netbrain"
nb_url = "http(s)://<IP address of NetBrain Web Server>/"
headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}
tenantName = "Initial Tenant"
domainName = "Use Case"
#################################################################
# Step 1: Login to NetBrain API server and get session
print("Step 1")
token = netbrain_restful_lib.loginSession(nb_url, user, pwd)
print("Token: "+token)
print(netbrain_restful_lib.getTenants(nb_url, token))
print(netbrain_restful_lib.getDomains(nb_url, token))
#Sample results
# token : adf5b560-8e9c-4114-87bb-2eed24f0faff
# tenantList : [{'tenantId': 'a50af282-fa02-012f-a7f7-e410cc7c29d3', 'tenantName': 'Initial Tenant'}]
# domainList : [{'domainName': 'UseCase', 'domainId': '4f747a8b-71da-404b-a05c-e8505aa14725'}]
tenantId = 'fcf8a380-6b11-0fed-1d51-3b4cdef8f238'
domainId = '25b66365-1ab8-4fed-90c9-1307a4047c3d'
# Step 2: Set current domain
print("Step 2")
print(netbrain_restful_lib.loginDomain(nb_url, token, tenantId, domainId))
# Sample results
# loginDomain: Login successfully!
# Step 3: Delete Site
print("Step 3")
data=[{"sitePath":"My Network/US/CA/Palo Alto"} ]
print(netbrain_restful_lib.createSiteTransaction(nb_url, token))
for i in data:
print(i['sitePath'])
print(netbrain_restful_lib.deleteSite(nb_url, token, i['sitePath']))
# Sample results
# CreateSiteTransaction: Site transaction created!
# DeleteSite: Deleted successfully!
# Step 4: Call Commit to commit the change
print("Step 4")
print(netbrain_restful_lib.commitSiteTransaction(nb_url, token))
# Sample results
# CommitSiteTransaction: Site commit True
# Step 5: Call GetSiteTree to confirm that all sites are created and devices are set
print("Step 5")
print(netbrain_restful_lib.getChildSites(nb_url, token, None, "My Network"))
for i in data:
print(netbrain_restful_lib.getSiteInfo(nb_url, token, None, i['sitePath']))
print(netbrain_restful_lib.getSiteDevice(nb_url, token, None, i['sitePath']))
# Sample results
# GetChildSites: [{'siteId': 'aac212cb-fa84-4ddd-8c0b-18a00ec9c323', 'isContainer': False, 'siteType': 2, 'sitePath': 'My Network/NA/US/MA'}, {'siteId': '3ebb978f-323a-4308-8b38-82fa1a0a135f', 'isContainer': False, 'siteType': 2, 'sitePath': 'My Network/NA/US/CA'}]
# GetSiteInfo: {'isContainer': True, 'siteId': 'ede2ed2b-d5cf-48dd-b341-020330757033', 'sitePath': 'My Network/NA/US', 'siteType': 1}
# GetSiteDevice: [{'mgmtIP': '172.16.8.186', 'id': '06840b62-8a67-4cb2-9ed4-e540ea36fdcf', 'hostname': 'NBUSMA-SW7'}, {'mgmtIP': '172.16.8.194', 'id': '0b152c13-34e0-474e-aa4c-b07fe71cc0b7', 'hostname': 'NBUSMA-R1'}]
# Step 6: Logout Netbrain API server
print("Step 6")
print(netbrain_restful_lib.logoutSession(nb_url, token))