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

yang module for interfaces

sqambera
Level 1
Level 1

Hello,

I'm new to network programmability. I am wondering is there a module that can provide the information same as "show ip interface brief" meaning interface names and ip addresses. The module I have been referencing to provides unwanted detail:

Cisco-IOS-XE-interfaces-oper:interfaces

 

Thanks,

Qamber

2 Replies 2

balaji.bandi
Hall of Fame
Hall of Fame

you can use python if that work for you ?

BB

***** Rate All Helpful Responses *****

How to Ask The Cisco Community for Help

Try

# import requests, jason and sys
import requests
import json
import sys

#device details    
HOST = 'ios-xe-mgmt-latest.cisco.com'
PORT = 443
USER = 'developer'
PASS = 'C1sco12345'

# disable urlib3 warning
requests.packages.urllib3.disable_warnings()

#main function using restconf to show the status of device interface and print results in json
def main():
    # create a main function using restconf
    url = "https://{}:{}@{}:{}/restconf/data/ietf-interfaces:interfaces".format(USER, PASS, HOST, PORT)
    headers = {'Content-Type': 'application/yang-data+json'}
    response = requests.get(url, headers=headers, verify=False)
    print(response.status_code)
    # print the results in json format
    print(json.dumps(response.json(), indent=4))


# Call the function main() and exit giving the system the return code that is the result of main()
if __name__ == '__main__':
    sys.exit(main())

Will print the following

 

❯ {
∙     "ietf-interfaces:interfaces": {
∙         "interface": [
∙             {
∙                 "name": "GigabitEthernet1",
∙                 "description": "MANAGEMENT INTERFACE - DON'T TOUCH ME",
∙                 "type": "iana-if-type:ethernetCsmacd",
∙                 "enabled": true,
∙                 "ietf-ip:ipv4": {
∙                     "address": [
∙                         {
∙                             "ip": "10.10.20.48",
∙                             "netmask": "255.255.255.0"
∙                         }
∙                     ]
∙                 }
[snip]

  

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

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: