Package: catalystwan
Cisco Catalyst WAN SDK is a package for creating simple and parallel automatic requests via official Manager API. It is intended to serve as a multiple session handler (provider, provider as a tenant, tenant). The library is not dependent on environment which is being run in, you just need a connection to any Manager.Installationpip install catalystwanSession usage exampleOur session is an extension torequests.Sessiondesigned to make it easier to communicate via API calls with SDWAN Manager. We provide ready to use authentication, you have to simply provide the Manager url, username and password as as if you were doing it through a GUI.fromcatalystwan.sessionimportcreate_manager_sessionurl="example.com"username="admin"password="password123"withcreate_manager_session(url=url,username=username,password=password)assession:session.get("/dataservice/device")# When interacting with the SDWAN Manager API without using a context manager, it's important# to manually execute the `close()` method to release the user session resource.session=create_manager_session(url=url,username=username,password=password)session.get("/dataservice/device")session.close()Ensure that theclose()method is called after you have finished using the session to maintain optimal resource management and avoid potential errors.API usage examplesGet devices(click to expand)devices=session.api.devices.get()Admin Tech(click to expand)admin_tech_file=session.api.admin_tech.generate("172.16.255.11")session.api.admin_tech.download(admin_tech_file)session.api.admin_tech.delete(admin_tech_file)Speed test(click to expand)devices=session.api.devices.get()speedtest=session.api.speedtest.speedtest(devices[0],devices[1])Upgrade device(click to expand)# Prepare devices listvsmarts=session.api.devices.get().filter(personality=Personality.VSMART)image="viptela-20.7.2-x86_64.tar.gz"# Upload imagesession.api.repository.upload_image(image)# Install softwareinstall_task=session.api.software.install(devices=vsmarts,image=image)# Check action statusinstall_task.wait_for_completed()Get alarms(click to expand)To get all alarms:alarms=session.api.alarms.get()To get all not viewed alarms:not_viewed_alarms=session.api.alarms.get().filter(viewed=False)To get all alarms from pastnhours:n=24alarms_from_n_hours=session.api.alarms.get(from_time=n)To get all critical alarms from pastnhours:n=48critical_alarms=session.api.alarms.get(from_time=n).filter(severity=Severity.CRITICAL)Users(click to expand)# Get all userssession.api.users.get()# Create usernew_user=User(username="new_user",password="new_user",group=["netadmin"],description="new user")session.api.users.create(new_user)# Update user datanew_user_update=UserUpdateRequest(username="new_user",group=["netadmin","netops"],locale="en_US",description="updated-new_user-description")session.api.users.update(new_user_update)# Update user passwordsession.api.users.update_password("new_user","n3W-P4s$w0rd")# Reset usersession.api.users.reset("new_user")# Delete usersession.api.users.delete("new_user")# Get current user authentication type and rolesession.api.users.get_auth_type()session.api.users.get_role()User Groups(click to expand)# Get all user groupssession.api.user_groups.get()# Create user groupgroup=UserGroup("new_user_group",[])group.enable_read({"Audit Log","Alarms"})group.enable_read_and_write({"Device Inventory"})session.api.user_groups.create(group)# Update user groupgroup.disable({"Alarms"})session.api.user_groups.update(group)# Delete user groupsession.api.user_groups.delete(group.group_name)Sessions(click to expand)# Get all active sessionsactive_sessions=session.api.sessions.get()# Invalidate sessions for given usernew_user_sessions=active_sessions.filter(raw_username="new_user")session.api.sessions.invalidate(new_user_sessions)Resource Groups(click to expand)# get resource groupssession.api.resource_groups.get()# create resource groupnew_resource_group=ResourceGroup(name="new_resource_group",desc="Custom Resource Group #1",siteIds=[])session.api.resource_groups.create(new_resource_group)# update resource groupresource_group=session.api.resource_groups.get().filter(name="new_resource_group").single_or_default()updated_resource_group=ResourceGroupUpdateRequest(id=resource_group.id,name=resource_group.name,desc="Custom Resource Group #1 with updated description and site ids",siteIds=[200])# switch to resource group viewsession.api.resource_groups.switch("new_resource_group")# delete resource groupsession.api.resource_groups.delete(resource_group.id)Tenant management(click to expand)api=session.api.tenant_management# create tenantstenants=[Tenant(name="tenant1",orgName="CiscoDevNet",subDomain="alpha.bravo.net",desc="This is tenant for unit tests",edgeConnectorEnable=True,edgeConnectorSystemIp="172.16.255.81",edgeConnectorTunnelInterfaceName="GigabitEthernet1",wanEdgeForecast=1,)]create_task=api.create(tenants)create_task.wait_for_completed()# list all tenantstenants_data=api.get_all()# pick tenant from list by nametenant=tenants_data.filter(name="tenant1").single_or_default()# get selected tenant idtenant_id=tenant.tenant_id# get vsession id of selected tenantvsessionid=api.vsession_id(tenant_id)# delete tenant by idsdelete_task=api.delete([tenant_id])delete_task.wait_for_completed()# othersapi.get_hosting_capacity_on_vsmarts()api.get_statuses()api.get_vsmart_mapping()Tenant migration(click to expand)frompathlibimportPathfromcatalystwan.sessionimportcreate_manager_sessionfromcatalystwan.models.tenantimportTenantExportfromcatalystwan.workflows.tenant_migrationimportmigration_workflowtenant=TenantExport(name="mango",desc="Mango tenant description",org_name="Provider Org-Mango Inc",subdomain="mango.fruits.com",wan_edge_forecast=100,migration_key="MangoTenantMigrationKey",# only for SDWAN Manager >= 20.13is_destination_overlay_mt=True,# only for SDWAN Manager >= 20.13)withcreate_manager_session(url="10.0.1.15",username="st-admin",password="")asorigin_session,\create_manager_session(url="10.9.0.16",username="mt-provider-admin",password="")astarget_session:migration_workflow(origin_session=origin_session,target_session=target_session,workdir=Path("workdir"),tenant=tenant,validator="10.9.12.26")migration_workflowperforms multi-step migration procedure according toMigrate Single-Tenant Cisco SD-WAN Overlay to Multitenant Cisco SD-WAN DeploymentSince 20.13 also MT to ST is supported (just provide suitable origin/target sessions, andis_destination_overlay_mtparameter)Each step of themigration_workflowprocedure can be executed independently using api methods:export_tenant,download,import_tenant,store_token,migrate_networkorigin_api=origin_session.api.tenant_migration_apitarget_api=target_session.api.tenant_migration_apitenant_file=Path("~/tenant.tar.gz")token_file=Path("~/tenant-token.txt")# exportexport_task=origin_api.export_tenant(tenant=tenant)remote_filename=export_task.wait_for_file()# downloadorigin_api.download(export_path,remote_filename)# importimport_task=target_api.import_tenant(export_path,tenant.migration_key)import_task.wait_for_completed()# get tokenmigration_id=import_task.import_info.migration_token_query_params.migration_idtarget_api.store_token(migration_id,token_path)# migrate networkmigrate_task=origin_api.migrate_network(token_path)migrate_task.wait_for_completed()Note:To removeInsecureRequestWarning, you can include in your scripts (warning is suppressed whencatalystwan_develenvironment variable is set):importurllib3urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)Catching Exceptionstry:session.api.users.delete("bogus-user-name")exceptManagerHTTPErroraserror:# Process an error.print(error.response.status_code)print(error.info.code)print(error.info.message)print(error.info.details)Supported API endpointsContributing, bug reporting and feature requestsSeeking supportYou can contact us by submittingissues, or directly via mail onvmngclient@cisco.com.