Skip to main content

vManage SDK for Python

Project description

vManage-client logo

Python-Supported

vManage client is a package for creating simple and parallel automatic requests via official vManage 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 vManage.

Installation

pip install vmngclient

Session usage example

Our session is an extension to requests.Session designed to make it easier to communicate via API calls with vManage. We provide ready to use authenticetion, you have to simply provide the vmanage url, username and password as as if you were doing it through a GUI.

from vmngclient.session import create_vManageSession

url = "example.com"
username = "admin"
password = "password123"
session = create_vManageSession(url=url, username=username, password=password)

session.get("/dataservice/device")

API usage examples

Get 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 list
vsmarts = session.api.devices.get().filter(personality=Personality.VSMART)
image = "viptela-20.7.2-x86_64.tar.gz"

# Upload image
session.api.repository.upload_image(image)

# Install software

install_task = session.api.software.install(devices=vsmarts, image=image)

# Check action status
install_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 past n hours:

n = 24
alarms_from_n_hours = session.api.alarms.get(from_time=n)

To get all critical alarms from past n hours:

n = 48
critical_alarms = session.api.alarms.get(from_time=n).filter(severity=Severity.CRITICAL)
Users (click to expand)
# Get all users
session.api.users.get()

# Create user
new_user = User(userName="new_user", password="new_user", group=["netadmin"], description="new user")
session.api.users.create(new_user)

# Update user data
new_user_update = UserUpdateRequest(userName="new_user", group=["netadmin", "netops"], locale="en_US", description="updated-new_user-description", resGroupName="global")
session.api.users.update(new_user_update)

# Update user password
session.api.users.update_password("new_user", "n3W-P4s$w0rd")

# Reset user
session.api.users.reset("new_user")

# Delete user
session.api.users.delete("new_user")

# Get current user authentication type and role
session.api.users.get_auth_type()
session.api.users.get_role()
User Groups (click to expand)
# Get all user groups
session.api.user_groups.get()

# Create user group
group = 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 group
group.disable({"Alarms"})
session.api.user_groups.update(group)

# Delete user group
session.api.user_groups.delete(group.group_name)
Sessions (click to expand)
# Get all active sessions
active_sessions = session.api.sessions.get()

# Invalidate sessions for given user
new_user_sessions = active_sessions.filter(raw_username="new_user")
session.api.sessions.invalidate(new_user_sessions)
Resource Groups (click to expand)
# get resource groups
session.api.resource_groups.get()

# create resource group
new_resource_group = ResourceGroup(
    name="new_resource_group",
    desc="Custom Resource Group #1",
    siteIds=[]
)
session.api.resource_groups.create(new_resource_group)

# update resource group
resource_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 view
session.api.resource_groups.switch("new_resource_group")

# delete resource group
session.api.resource_groups.delete(resource_group.id)
Tenant management (click to expand)
api = session.api.tenant_management
# create tenants
tenants = [
    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 tenants
tenants_data = api.get_all()
# pick tenant from list by name
tenant = tenants_data.filter(name="tenant1").single_or_default()
# get selected tenant id
tenant_id = tenant.tenant_id
# get vsession id of selected tenant
vsessionid = api.vsession_id(tenant_id)
# delete tenant by ids
delete_task = api.delete([tenant_id])
delete_task.wait_for_completed()
# others
api.get_hosting_capacity_on_vsmarts()
api.get_statuses()
api.get_vsmart_mapping()
Tenant migration (click to expand)
from pathlib import Path
from vmngclient.session import create_vManageSession
from vmngclient.model.tenant import TenantExport
from vmngclient.workflows.tenant_migration import migration_workflow

tenant = 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.13
    is_destination_overlay_mt=True,            # only for SDWAN Manager >= 20.13
)

with create_vManageSession(url="10.0.1.15", username="st-admin", password="") as origin_session, \
     create_vManageSession(url="10.9.0.16", username="mt-provider-admin", password="") as target_session:
    migration_workflow(
        origin_session=origin_session,
        target_session=target_session,
        workdir=Path("workdir"),
        tenant=tenant,
        validator="10.9.12.26"
    )

migration_workflow performs multi-step migration procedure according to Migrate Single-Tenant Cisco SD-WAN Overlay to Multitenant Cisco SD-WAN Deployment

Since 20.13 also MT to ST is supported (just provide suitable origin/target sessions, and is_destination_overlay_mt parameter)

Each step of the migration_workflow procedure can be executed independently using api methods: export_tenant, download, import_tenant, store_token, migrate_network

origin_api = origin_session.api.tenant_migration_api
target_api = target_session.api.tenant_migration_api
tenant_file = Path("~/tenant.tar.gz")
token_file = Path("~/tenant-token.txt")
# export
export_task = origin_api.export_tenant(tenant=tenant)
remote_filename = export_task.wait_for_file()
# download
origin_api.download(export_path, remote_filename)
# import
import_task = target_api.import_tenant(export_path, tenant.migration_key)
import_task.wait_for_completed()
# get token
migration_id = import_task.import_info.migration_token_query_params.migration_id
target_api.store_token(migration_id, token_path)
# migrate network
migrate_task = origin_api.migrate_network(token_path)
migrate_task.wait_for_completed()

Note:

To remove InsecureRequestWarning, you can include in your scripts (warning is suppressed when VMNGCLIENT_DEVEL environment variable is set):

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

Catching Exceptions

try:
	session.api.users.delete_user("XYZ")
except vManageBadRequestError as error:
	# Process an error.
	logger.error(error.info.details)

# message = 'Delete users request failed' 
# details = 'No user with name XYZ was found' 
# code = 'USER0006'

Exceptions

Supported API endpoints

Contributing, bug reporting and feature requests

Seeking support

You can contact us by submitting issues, or directly via mail on vmngclient@cisco.com.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vmngclient-0.18.1.dev2.tar.gz (218.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vmngclient-0.18.1.dev2-py3-none-any.whl (322.3 kB view details)

Uploaded Python 3

File details

Details for the file vmngclient-0.18.1.dev2.tar.gz.

File metadata

  • Download URL: vmngclient-0.18.1.dev2.tar.gz
  • Upload date:
  • Size: 218.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.8.18 Linux/6.2.0-1016-azure

File hashes

Hashes for vmngclient-0.18.1.dev2.tar.gz
Algorithm Hash digest
SHA256 bf2976364d8ffa1ca2e18a8f42bf74ee106b0c1c07e0cfb747b6bc2a41318f8f
MD5 4996af2b8af444e4580986166c9a9482
BLAKE2b-256 6979c1923ababe8f49d4a29c376ff6204378fb87bfb235c554717841a177927b

See more details on using hashes here.

File details

Details for the file vmngclient-0.18.1.dev2-py3-none-any.whl.

File metadata

  • Download URL: vmngclient-0.18.1.dev2-py3-none-any.whl
  • Upload date:
  • Size: 322.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.8.18 Linux/6.2.0-1016-azure

File hashes

Hashes for vmngclient-0.18.1.dev2-py3-none-any.whl
Algorithm Hash digest
SHA256 ebfa3d747324c80e53b909df124df755a8b10616d609d08117c46260150788e0
MD5 cdcb61fb829199f13cbe391abc9c12ec
BLAKE2b-256 7801c909b3513cfeb232fab0c3606ae0f0f06ec1904af4386549ea776b6d440a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page