cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
665
Views
0
Helpful
1
Replies

How to create an user over https with Python - CBS220 ?

HalfMoonRising
Level 1
Level 1

Hello,

I am using a Cisco Switch CBS220-16P-2G
It does not come with telnet or ssh enabled by default. Only https.
( I do not think that this switch is running Cisco IOS XE. )

I just got the switch and discovered the RESTCONF.
Because of this, i am building a Python script to automate some stuff.

First, i would like to create an admin user, for which i want to provide my ssh key.

Then enable the ssh service on the switch.


So far, i have managed to modify the interfaces ( in this example, i am adding a description for gi 0/3):

 

import requests
import json
from pprint import pprint
from dotenv import load_dotenv, find_dotenv
import os

load_dotenv(find_dotenv())

CISCOU = os.environ.get("CISCOU")
CISCOP = os.environ.get("CISCOP")


device = {
   "ip": "10.1.1.103",
   "username": CISCOU,
   "password": CISCOP,
   "port": "443",
}

headers = {
      "Accept" : "application/yang-data+json", 
      "Content-Type" : "application/yang-data+json", 
   }

payload = {
    "ietf-interfaces:interface": [
        {
            "name": "gi3",
            "description": "HELLO"
        }
    ]
}



# retreive all details
url = f"https://{device['ip']}/restconf/data/ietf-interfaces:interfaces/interface"

print(url)

requests.packages.urllib3.disable_warnings()
response = requests.patch(url,
                        headers=headers,
                        data=json.dumps(payload),
                        auth=(device['username'], 
                              device['password']), 
                        verify=False)


print(response)

 

I have searched about RESTCONF, but the examples that i have found do not work on my device.


Any recommendations on how to automate the user creation and enabling the ssh service on the switch, over https , please?
Thank you

1 Reply 1

balaji.bandi
Hall of Fame
Hall of Fame

CBS220  - small business switch, i do not believe that you looking to run program works on these models

that feature you looking to do only possible on enterprise-grade switches, which run IOS or IOSXE (other side nexus)

 

BB

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

How to Ask The Cisco Community for Help