Skip to main content

Universal vManage API

Project description

vManage-client

Python3.8

vManage client is a package for creating simple and parallel automatic requests via official vManageAPI. 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)
User operations (click to expand)
from vmngclient.api.administration import User, UsersAPI

# Get all users
all_users = UsersAPI(session).get_all_users()

# Create a user
new_user = User(username="new_user", password="new_user", group=["netadmin"], description="new user")
status = UsersAPI(session).create_user(new_user)

# Delete a user
status = UsersAPI(session).delete_user(username="new_user")
Tenant migration (click to expand) Preparation:
from vmngclient.api.tenant_migration_api import TenantMigrationAPI, st_to_mt
from vmngclient.model.tenant import Tenant
from vmngclient.session import create_vManageSession
# create sessions to both systems
st_session = create_vManageSession(**single_tenant_login)
mt_session = create_vManageSession(**multi_tenant_provider_login)
# create api and tenant objects
st_api = TenantMigrationAPI(st_session)
mt_api = TenantMigrationAPI(mt_session)
tenant = Tenant.parse_obj({
    "name": "single-tenant",
    "desc": "Migrated from Single Tenant",
    "orgName": "vIPtela Inc Regression",
    "subDomain": "single-tenant.fruits.com",
    "wanEdgeForecast": 99
})

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

from pathlib import Path
st_to_mt(st_api, mt_api, workdir=Path.cwd(), tenant=tenant)

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

tenant_file = Path("~/tenant.tar.gz")
token_file = Path("~/tenant-token.txt")
# export
export_task = st_api.export_tenant(tenant=tenant)
export_result = export_task.wait_for_completed()
# download
st_api.download(tenant_file)
# import
import_task = mt_api.import_tenant(tenant_file)
import_task.wait_for_completed()
# get token
migration_id = import_task.import_info.migration_token_query_params.migration_id
mt_api.store_token(migration_id, token_file)
# migrate network
migrate_task = st_api.migrate_network(token_file)
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'

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.10.2.post0.tar.gz (104.3 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.10.2.post0-py3-none-any.whl (145.4 kB view details)

Uploaded Python 3

File details

Details for the file vmngclient-0.10.2.post0.tar.gz.

File metadata

  • Download URL: vmngclient-0.10.2.post0.tar.gz
  • Upload date:
  • Size: 104.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.8.17 Linux/5.15.0-1040-azure

File hashes

Hashes for vmngclient-0.10.2.post0.tar.gz
Algorithm Hash digest
SHA256 972a81e7768ea76adf326a47258a69a16d8a41c2f2402e7874b30f7879e135d4
MD5 d3fb4d6ee717d3539b54f9b19334e82f
BLAKE2b-256 e5a6fdfa6d33e62f4fb39b99a38fc52db878871f413388296731385675a47eed

See more details on using hashes here.

File details

Details for the file vmngclient-0.10.2.post0-py3-none-any.whl.

File metadata

  • Download URL: vmngclient-0.10.2.post0-py3-none-any.whl
  • Upload date:
  • Size: 145.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.8.17 Linux/5.15.0-1040-azure

File hashes

Hashes for vmngclient-0.10.2.post0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f892b82c56bbd801d402319cb7aebbff455691c90ea379eed42e00869897aa3
MD5 875d2139e6e36697397ff713aad9252e
BLAKE2b-256 27c341f95add49214e1d9401173268d01a34952902190113a6ca214a6b0dc820

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