cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
732
Views
2
Helpful
2
Replies

How to get a 'show inventory' of a vedge

emory.clayton
Level 1
Level 1

I'm trying to use the Python Viptela SDK in order to pull the inventory from all vedges. I'm needing to get the PID of the LTE module that is installed for some 300+ routers. If I can just pull a "show inventory" from all the vedges, I can work with the data to get what I need out of it. Even if I can only get it to work for one, I can take the function call and run it through a for loop if I have to. 

Looking through the documentation (see link below), I believe this might be what I'm looking for. However, as the doc states, one of the arguments is 'path' with the description 'The path of the data'. I don't know what this means. I was thinking this is where you would put your command that you wanted run on the vedge, but this does not seem to be the case, as the various show commands I have tried to run, have not worked. I get a 404 (not found) error.

vmanage_device.get_device_data(self, path, device_ip)

https://python-viptela.readthedocs.io/en/latest/autoapi/api/device/index.html

2 Replies 2

Hey @emory.clayton i will try and help. Ages back i wrote this code would _should_ do the same thing https://github.com/bigevilbeard/sd_wan_demo

To use the get_device_data() function, you would first need to import the viptela module. You can do this by running the following command:

import viptela

Once you have imported the viptela module, you can create a Device object. The Device object represents a vEdge device.

device = viptela.Device('vedge_ip_address', 'username', 'password')

The Device object has a get_device_data() method that you can use to retrieve data from the device. This code shows how to use the get_device_data() method to retrieve the inventory data from a vEdge device:

inventory = device.get_device_data('/api/v1/inventory')

This code will first connect to the vEdge device and then get the inventory data for the device you want. The inventory data will be returned as a dictionary object.

Its been a while for me with this SDK. From the looks it has not been updated in a while, so would say also look at https://github.com/CiscoDevNet/sastre which has a lot more support for newer features and models. I would also move this thread to https://community.cisco.com/t5/sd-wan-and-cloud-networking/bd-p/discussions-sd-wan which is more focused on SD-WAN and the API for customer cases and support.

Hope this helps you.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Marcel Zehnder
Spotlight
Spotlight

You may also use this code, it collects all vedges + hw-inventory using the REST-API.

import requests
requests.packages.urllib3.disable_warnings()
import json


def login(vmanage, username, password):
    try:
        url = f"https://{vmanage}/j_security_check"
        payload = {
            "j_username" : username,
            "j_password" : password
        }

        r = requests.post(url=url, data=payload, verify=False)
        r.raise_for_status()
        jsessionid = r.headers["Set-Cookie"].split(";")[0]
    
        headers = {"Cookie": jsessionid}
        url = f"https://{vmanage}/dataservice/client/token"   
        r = requests.get(url=url, headers=headers, verify=False)
        r.raise_for_status()
        xsrf_token = r.text

        return {"Cookie": jsessionid, "X-XSRF-TOKEN": xsrf_token}

    except:
        print("Could not get session/token")
        exit()


def api_call(vmanage, uri, header):
    url = f"https://{vmanage}{uri}"
    r = requests.get(url=url, headers=header, verify=False)
    if r.ok:
        return (r.json().get("data"))
    return []


if __name__ == "__main__":
    vmanage = "sandbox-sdwan-2.cisco.com"
    username = "devnetuser"
    password = "RG!_Yw919_83"

    header = login(vmanage, username, password)
    
    vedges = {}
    for _ in api_call(vmanage, "/dataservice/system/device/vedges", header):
        if _.get("deviceIP"):
            vedges[_.get("deviceIP")] = {"name": _.get("host-name")}

    for k in vedges.keys():
        hw = api_call(vmanage, f"/dataservice/device/hardware/inventory?deviceId={k}", header)
        vedges[k]["hw"] = hw
    
    r = requests.get(f"https://{vmanage}/logout?nocache", headers=header, verify=False)
    print(f"API LOGOUT: {r.status_code}")

    print(json.dumps(vedges, indent=1))

Output (vedges dict):

{
 "10.10.1.15": {
  "name": "site2-cedge01",
  "hw": [
   {
    "hw-type": "hw-type-chassis",
    "vdevice-dataKey": "10.10.1.15-hw-type-chassis-0",
    "vdevice-name": "10.10.1.15",
    "hw-dev-index": "0",
    "serial-number": "9BHHW2IYRJM",
    "part-number": "C8000V",
    "lastupdated": 1693475920194,
    "version": "V00",
    "vdevice-host-name": "site2-cedge01",
    "hw-description": "Cisco Catalyst 8000V Edge Chassis"
   },
   {
    "hw-type": "hw-type-pim",
    "vdevice-dataKey": "10.10.1.15-hw-type-pim-1",
    "vdevice-name": "10.10.1.15",
    "hw-dev-index": "1",
    "serial-number": "JAB1303001C",
    "part-number": "C8000V",
    "lastupdated": 1693475920194,
    "version": "V00",
    "vdevice-host-name": "site2-cedge01",
    "hw-description": "Cisco Catalyst 8000V Edge Route Processor"
   },
   {
    "hw-type": "hw-type-pim",
    "vdevice-dataKey": "10.10.1.15-hw-type-pim-2",
    "vdevice-name": "10.10.1.15",
    "hw-dev-index": "2",
    "part-number": "C8000V",
    "lastupdated": 1693475920194,
    "vdevice-host-name": "site2-cedge01",
    "hw-description": "Cisco Catalyst 8000V Edge Embedded Services Processor"
   },
   {
    "hw-type": "hw-type-dram",
    "vdevice-dataKey": "10.10.1.15-hw-type-dram-3",
    "vdevice-name": "10.10.1.15",
    "hw-dev-index": "3",
    "lastupdated": 1693475920194,
    "vdevice-host-name": "site2-cedge01",
    "hw-description": "Physical Memory"
   },
   {
    "hw-type": "hw-type-cpu",
    "vdevice-dataKey": "10.10.1.15-hw-type-cpu-4",
    "vdevice-name": "10.10.1.15",
    "hw-dev-index": "4",
    "part-number": " GenuineIntel",
    "lastupdated": 1693475920194,
    "version": " 6",
    "vdevice-host-name": "site2-cedge01",
    "hw-description": " Intel(R) Xeon(R) Gold 6238 CPU @ 2.10G"
   }
  ]
 },
 "10.10.1.13": {
  "name": "site1-cedge01",
  "hw": [
   {
    "hw-type": "hw-type-chassis",
    "vdevice-dataKey": "10.10.1.13-hw-type-chassis-0",
    "vdevice-name": "10.10.1.13",
    "hw-dev-index": "0",
    "serial-number": "94ZG4KM8FPL",
    "part-number": "C8000V",
    "lastupdated": 1693475926399,
    "version": "V00",
    "vdevice-host-name": "site1-cedge01",
    "hw-description": "Cisco Catalyst 8000V Edge Chassis"
   },
   {
    "hw-type": "hw-type-pim",
    "vdevice-dataKey": "10.10.1.13-hw-type-pim-1",
    "vdevice-name": "10.10.1.13",
    "hw-dev-index": "1",
    "serial-number": "JAB1303001C",
    "part-number": "C8000V",
    "lastupdated": 1693475926399,
    "version": "V00",
    "vdevice-host-name": "site1-cedge01",
    "hw-description": "Cisco Catalyst 8000V Edge Route Processor"
   },
   {
    "hw-type": "hw-type-pim",
    "vdevice-dataKey": "10.10.1.13-hw-type-pim-2",
    "vdevice-name": "10.10.1.13",
    "hw-dev-index": "2",
    "part-number": "C8000V",
    "lastupdated": 1693475926399,
    "vdevice-host-name": "site1-cedge01",
    "hw-description": "Cisco Catalyst 8000V Edge Embedded Services Processor"
   },
   {
    "hw-type": "hw-type-dram",
    "vdevice-dataKey": "10.10.1.13-hw-type-dram-3",
    "vdevice-name": "10.10.1.13",
    "hw-dev-index": "3",
    "lastupdated": 1693475926399,
    "vdevice-host-name": "site1-cedge01",
    "hw-description": "Physical Memory"
   },
   {
    "hw-type": "hw-type-cpu",
    "vdevice-dataKey": "10.10.1.13-hw-type-cpu-4",
    "vdevice-name": "10.10.1.13",
    "hw-dev-index": "4",
    "part-number": " GenuineIntel",
    "lastupdated": 1693475926399,
    "version": " 6",
    "vdevice-host-name": "site1-cedge01",
    "hw-description": " Intel(R) Xeon(R) Gold 6238 CPU @ 2.10G"
   }
  ]
 },
 "10.10.1.11": {
  "name": "dc-cedge01",
  "hw": []
 },
 "10.10.1.17": {
  "name": "site3-vedge01",
  "hw": [
   {
    "hw-type": "Chassis",
    "vdevice-dataKey": "10.10.1.17-Chassis-0",
    "vdevice-name": "10.10.1.17",
    "hw-dev-index": 0,
    "serial-number": "sim",
    "part-number": "vEdge-Cloud",
    "lastupdated": 1693475961105,
    "version": "1.0",
    "vdevice-host-name": "site3-vedge01",
    "hw-description": "vEdge-Cloud"
   },
   {
    "hw-type": "PIM",
    "vdevice-dataKey": "10.10.1.17-PIM-0",
    "vdevice-name": "10.10.1.17",
    "hw-dev-index": 0,
    "serial-number": "None",
    "part-number": "ge-8",
    "lastupdated": 1693475961105,
    "version": "None",
    "vdevice-host-name": "site3-vedge01",
    "hw-description": "Max 8 x 1GE VM ports"
   }
  ]
 }
}