QuestionQ204

Understanding and Using APIs

Drag the code options from the bottom into the missing boxes to enable switch ports by using RESTCONF. Not every option is used.

Drag & Drop
yang-data+json
application/xml
ietf-interfaces:interface
iana-if-type:softwareLoopback
base_url
run_function
iana-if-type:ethernetCsmacd
def enable_function(if_name, if_status, if_type):
    headers = {'Accept': 'application/yang-data+json',
               'Content-Type': 'application/'}
    payload = {
        "": {
            "name": if_name,
            "enabled": if_status,
            "type": if_type,
        }
    }
     = 'https://192.168.1.1:8443'
    restconf_url = '/restconf/data/ietf-interfaces:interfaces/interface'

    res = requests.put(f'{base_url}{restconf}={if_name}',
                       headers=headers, json=payload,
                       auth=('cisco', 'secret'), verify=False)

enable_function('Loopback1', true, '')
Explanation

RESTCONF uses application/yang-data+json for YANG JSON data. The interface payload member is qualified as ietf-interfaces:interface, and base_url holds the server URL. An interface named Loopback1 is a software loopback, whose IANA interface type identity is iana-if-type:softwareLoopback; iana-if-type:ethernetCsmacd is for Ethernet interfaces.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!