Networking NVIDIA NVOS User Manual for InfiniBand Switches

NVUE OpenAPI

This section provides information about using the NVUE API.

In addition to the CLI, NVUE supports a REST API. Instead of accessing NVOS through SSH, you can interact with the switch through an HTTP client, such as cURL or a web browser.

The nvued service provides access to the NVUE REST API. NVOS exposes the HTTP endpoint internally, which makes the NVUE REST API accessible locally within the NVOS switch. The NVUE CLI also communicates with the nvued service using internal APIs. To provide external access to the NVUE REST API, NVOS uses an HTTP reverse proxy server and supports HTTPS and TLS connections from external REST API clients.

The following illustration shows the NVUE REST API architecture and how NVOS forwards requests internally.

image-2024-8-4_15-48-19.png

Supported HTTP Methods

The NVUE REST API supports the following methods:

  • GET (show): For examples of how to construct a REST API request and interpret the response, refer to View a Configuration.
    Displays configuration and operational data. This method is equivalent to the nv show commands.

  • PATCH (set): For examples of how to derive the cURL request, endpoint, and JSON payload from the OpenAPI path and schema, refer to Make a Configuration Change.
    Modifies the configuration. Use this method for the nv set and nv config apply commands.

    NVUE supports two types of PATCH operations:

    • Targeted patch: Changes a specific resource by sending the PATCH request to a particular OpenAPI endpoint. For example, to change an interface MTU, send the request to /nvue_v1/interface/<interface-id>/link/mtu with a payload that conforms to the schema for that endpoint. A targeted patch provides fine-grained control over individual resources.

    • Root patch: Changes one, several, or all configuration objects in a single PATCH request sent to the root /nvue_v1 endpoint. Because the changes are specified relative to the root node, the payload must conform to the NVUE object model schema. Root patches are useful for bulk configuration updates, such as when an SDN controller or network management system pushes a complete switch configuration. They can also reduce the number of round trips required to make multiple configuration changes.

    A PATCH request can contain either a set or an unset JSON object for the same resource, but not both. The execution order of set and unset objects is not deterministic and is not supported.

  • POST (action): For examples of how to construct requests for action operations, refer to Action Operations.
    Creates and submits operations. You typically use this method for nv action commands and for nv config commands that create configuration revisions.

  • DELETE (unset): For examples of how to construct a REST API request to remove configuration, refer to Unset a Configuration Change.
    Removes configuration. This method is equivalent to the nv unset commands.

Secure the API

The NVUE REST API supports HTTP basic authentication and the same underlying username and password authentication methods that the NVUE CLI supports. User accounts work the same way in the API and the CLI.

Certificates

NVOS includes a self-signed certificate and private key to use on the server so that it works out of the box. The switch generates the self-signed certificate and private key when it boots for the first time. The X.509 certificate with the public key is in /etc/ssl/certs/nvue.pem, and the corresponding private key is in /etc/ssl/private/nvue.key.

NVIDIA recommends that you use your own certificates and keys. For the steps to generate self-signed certificates and keys, refer to the Ubuntu Certificates and Security documentation.

NVOS lets you manage CA certificates (such as DigiCert or Verisign) and entity (endpoint) certificates. Both a CA certificate and an entity certificate can contain a chain of certificates.

You can import certificates onto the switch (fetch certificates from an external source), set which certificate you want to use for the NVUE REST API, and show information about a certificate, such as the serial number and the date and time during which the certificate is valid.

Import a Certificate

  • You can import a maximum of 25 entity certificates and a maximum of 25 CA certificates.

  • The certificate you import contains sensitive private key information. NVIDIA recommends that you use a secure transport, such as SFTP, SCP, or HTTPS.

  • To import an entity certificate, run the nv action import system security certificate <cert-id> command.

  • To import a CA certificate, run the nv action import system security ca-certificate <cert-id> command.

If the certificate is passphrase protected, you must include the passphrase.

You must provide a certificate ID (<cert-id>) to uniquely identify the certificate you import.

The following example imports a CA certificate with a public key and names the certificate tls-cert-1. The certificate is protected with the passphrase mypassphrase. The public key is a Base64 ASCII-encoded PEM string.

nvos@switch:~$ nv action import system security ca-certificate tls-cert-1 passphrase mypassphrase data "<public-key>"

The following example imports an entity certificate bundle and names the certificate tls-cert-1. The certificate bundle is protected with the passphrase mypassphrase.

A certificate bundle must be in .PFX or .P12 format.

nvos@switch:~$ nv action import system security certificate tls-cert-1 passphrase mypassphrase uri-bundle scp://user:pass@1.2.3.4:/opt/certs/cert.p12

The following example imports an entity certificate with the public key URI scp://user:pass@1.2.3.4:/opt/certs/public and the private key URI scp://user:pass@1.2.3.4:/opt/certs/private, and names the certificate tls-cert-1. The certificate is not passphrase protected.

A CA certificate must be in .pem, .p7a, or .p7c format.

nvos@switch:~$ nv action import system security certificate tls-cert-1 uri-public-key scp://user:pass@1.2.3.4:/opt/certs/public uri-private-key scp://user:pass@1.2.3.4:/opt/certs/private

Set the Certificate to Use

You can configure the NVUE REST API to use a specific certificate.

The following example configures the API to use the certificate tls-cert-1:

nvos@switch:~$ nv set system api certificate tls-cert-1
nvos@switch:~$ nv config apply

The following example configures the API to use the self-signed certificate:

nvos@switch:~$ nv set system api certificate self-signed
nvos@switch:~$ nv config apply

To unset the certificate that the NVUE REST API uses:

nvos@switch:~$ nv unset system api certificate tls-cert-1

Delete Certificates

  • To delete an entity certificate and the key data stored on the switch, run the nv action delete system security certificate <cert-id> command.

  • To delete a CA certificate and the key data stored on the switch, run the nv action delete system security ca-certificate <cert-id> command.

The following command deletes the certificate tls-cert-1:

nvos@switch:~$ nv action delete system security certificate tls-cert-1

Show Certificate Information

  • To show all the entity certificates on the switch, run the nv show system security certificate command.

  • To show all the CA certificates on the switch, run the nv show system security ca-certificate command.

The following example shows all the entity certificates on the switch:

nvos@switch:~$ nv show system security certificate
  • To show the applications that are using a specific entity certificate, run the nv show system security certificate <cert-id> installed command.

  • To show the applications that are using a specific CA certificate, run the nv show system security ca-certificate <cert-id> installed command.

The following example shows the applications that are using a specific entity certificate:

nvos@switch:~$ nv show system security certificate tls-cert-1 installed
  • To show detailed information about a specific entity certificate, run the nv show system security certificate <cert-id> dump command.

  • To show detailed information about a specific CA certificate, run the nv show system security ca-certificate <cert-id> dump command.

The following example shows detailed information about the CA certificate tls-cert-1:

nvos@switch:~$ nv show system security ca-certificate tls-cert-1 dump

Control Plane ACLs

You can secure the API by configuring:

The following example creates ACLs that allow users from the management subnet and the local switch to communicate with the switch through the REST API, and that restrict all other access.

nvos@switch:~$ nv set acl API-PROTECT type ipv4
nvos@switch:~$ nv set acl API-PROTECT rule 10 action permit
nvos@switch:~$ nv set acl API-PROTECT rule 10 match ip protocol tcp
nvos@switch:~$ nv set acl API-PROTECT rule 10 match ip tcp dest-port 443
nvos@switch:~$ nv set acl API-PROTECT rule 10 match ip source-ip 192.168.200.0/24
nvos@switch:~$ nv set acl API-PROTECT rule 10 remark "Allow the Management Subnet to talk to API"
nvos@switch:~$ nv set acl API-PROTECT rule 20 action permit
nvos@switch:~$ nv set acl API-PROTECT rule 20 match ip protocol tcp
nvos@switch:~$ nv set acl API-PROTECT rule 20 match ip tcp dest-port 443
nvos@switch:~$ nv set acl API-PROTECT rule 20 match ip source-ip 127.0.0.1
nvos@switch:~$ nv set acl API-PROTECT rule 20 remark "Allow the local switch to talk to the API"
nvos@switch:~$ nv set acl API-PROTECT rule 30 action deny
nvos@switch:~$ nv set acl API-PROTECT rule 30 match ip protocol tcp
nvos@switch:~$ nv set acl API-PROTECT rule 30 match ip tcp dest-port 443
nvos@switch:~$ nv set acl API-PROTECT rule 30 remark "Block everyone else from talking to the API"
nvos@switch:~$ nv set system control-plane acl API-PROTECT inbound

Supported Objects

The NVUE object model supports most features on the NVOS switch. The following table shows the high-level objects. The NVUE API supports more objects within each of these objects. For a full list of the supported API endpoints, refer to the API reference.

High-level Objects

Description

acl

Access control lists.

interface

Interface configuration.

platform

Platform configuration, such as hardware and software components.

system

Global system settings, such as system login messages, switch reboot history, syslog, and NTP.

vrf

Get VRF.

ib

IB devices.

Use the API

The NVUE CLI and the REST API are equivalent in functionality; you can run all management operations from the REST API or from the CLI. The NVUE object model drives both the REST API and the CLI management operations. All operations are consistent; for example, the CLI nv show commands reflect any PATCH operation (create and update) you run through the REST API.

NVUE follows a declarative model, removing context-specific commands and settings. The structure of NVUE is like a big tree that represents the entire state of an NVOS instance. At the base of the tree are high-level branches representing objects, such as system and interface. Under each of these branches are more branches. As you navigate through the tree, you gain a more specific context. At the leaves of the tree are actual attributes, represented as key-value pairs. The path through the tree is similar to a filesystem path.

NVOS enables the NVUE REST API by default. To disable the NVUE REST API, run the nv set system api state disabled command.

To use the NVUE REST API in NVOS, you must change the password for the admin user; otherwise, you see 401 responses when you run commands.

API Port and Listening Address

This section shows how to:

  • Set the NVUE REST API port. If you do not set a port, NVOS uses the default port 443.

  • Specify the NVUE REST API listening address. You can specify an IPv4 address, an IPv6 address, or localhost. If you do not specify a listening address, NGINX listens on all addresses for the target port.

NVUE Commands

The following example sets the port to 8888:

nvos@switch:~$ nv set system api port 8888
nvos@switch:~$ nv config apply

You can listen on multiple interfaces by specifying different listening addresses:

nvos@switch:~$ nv set system api listening-address 10.10.10.1
nvos@switch:~$ nv set system api listening-address 10.10.20.1
nvos@switch:~$ nv config apply

The following example configures the listening address on eth0, which has the IP address 172.0.24.0 and uses the management VRF by default:

nvos@switch:~$ nv set system api listening-address 172.0.24.0
nvos@switch:~$ nv config apply

cURL Command

The following example sets the port to 8888:

nvos@switch:~$ curl -u 'admin:****' -k --request PATCH https://localhost:443/nvue_v1/system/api?rev=2 -H 'Content-Type:application/json' -d '{"port": 8888 }'

You can listen on multiple interfaces by specifying different listening addresses. The following example sets localhost, interface address 10.10.10.1, and 10.10.20.1 as listening addresses.

nvos@switch:~$ curl -u 'admin:****' -k --request PATCH https://localhost:443/nvue_v1/system/api/listening-address?rev=2 -H 'Content-Type:application/json' -d '{ "localhost": {}, "10.10.10.1": {}, "10.10.20.1": {}}'

The following example configures the listening address on eth0, which has the IP address 172.0.24.0 and uses the management VRF by default:

nvos@switch:~$ curl -u 'admin:****' -k --request PATCH https://localhost:443/nvue_v1/system/api/listening-address?rev=2 -H 'Content-Type:application/json' -d '{"172.0.24.0": {}}'

Show NVUE REST API Information

To show the REST API port configuration, state (enabled or disabled), certificate, listening address, and connection information:

NVUE Commands

Run the nv show system api command:

nvos@switch:~$ nv show system api
                     operational  applied
-------------------  -----------  -----------
state                enabled      enabled
port                 443          443
certificate          self-signed  self-signed
[listening-address]  any
connections
  active             1
  accepted           2
  handled            2
  requests           2
  reading            0
  writing            1
  waiting            0

To show connection information only, run the nv show system api connections command:

 nvos@switch:~$ nv show system api connections
          operational
--------  -----------
active    2
accepted  8
handled   8
requests  8
reading   0
writing   2
waiting   0

To show the configured listening address, run the nv show system api listening-address command:

nvos@switch:~$ nv show system api listening-address
---------
localhost

To show all the certificates installed on the switch, run the nv show system security certificate command. To show information about a specific certificate, such as the serial number and how long the certificate is valid, run the nv show system security certificate <certificate> command:

 nvos@switch:~$ nv show system security certificate tls-cert-1
               operational                applied
-------------  -------------------------  -------
installed
 app           TLS
serial-number  67:03:3B:B4:6E:35:D3
valid-from     2023-02-14T00:35:18+00:00
valid-to       2033-02-11T00:35:18+00:00

cURL Command

nvos@switch:~$ curl -u 'admin:****' -k --request GET https://localhost:443/nvue_v1/system/api?rev=2 -H "accept: application/json"
{
  "certificate": "self-signed",
  "listening-address": {
    "10.10.10.1": {},
    "10.10.20.1": {},
    "172.0.24.0": {},
    "localhost": {}
  },
  "port": 8888,
  "state": "enabled"
}

To show the configured listening address:

nvos@switch:~$ curl -u 'admin:****' -k --request GET https://localhost:443/nvue_v1/system/api/listening-address?rev=2 -H "accept: application/json"
{
  "10.10.10.1": {},
  "10.10.20.1": {}
}

To show the certificates on the switch:

nvos@switch:~$ curl -u 'admin:****' -k --request GET https://localhost:443/nvue_v1/system/api/certificate?rev=2 -H "accept: application/json"
{
  "tls-cert-1": {},
  "tls-cert-2": {}
}

To show information about a specific certificate, such as the serial number and how long the certificate is valid:

nvos@switch:~$ curl -u 'admin:****' -k --request GET https://localhost:443/nvue_v1/system/api/certificate/tls-cert-1?rev=2 -H "accept: application/json"
{
  "serial-number": "67:03:3B:B4:6E:35:D3",
  "valid-from": "2023-02-14T00:35:18+00:00",
  "valid-to": "2033-02-11T00:35:18+00:00"
}

Run cURL Commands

You can run the cURL commands from the command line. Use the username and password for the switch. For example:

nvos@switch:~$ curl  -u 'admin:****' --insecure https://127.0.0.1:443/nvue_v1/interface
{
  "eth0": {
    "ip": {
      "address": {
        "192.168.200.12/24": {}
      }
    },
    "link": {
      "mtu": 1500,
      "state": {
        "up": {}
      },
      "stats": {
        "carrier-transitions": 2,
        "in-bytes": 184151,
        "in-drops": 0,
        "in-errors": 0,
        "in-pkts": 2371,
        "out-bytes": 117506,
        "out-drops": 0,
        "out-errors": 0,
        "out-pkts": 762
      }
...

API Use Cases

The following examples show the primary API use cases.

View a Configuration

Use the following example to view the currently applied configuration on the switch. To view a different revision, change the rev argument. Options for the rev argument include startup, pending, operational, and applied.

cURL Command

nvos@switch:~$ curl -k -u 'admin:****' -X GET "https://127.0.0.1:443/nvue_v1/?rev=applied&filled=false"
  "interface": {
    "eth0": {
      "type": "eth"
    },
 ...

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

if __name__ == "__main__":
    r = requests.get(url=nvue_end_point + "/?rev=applied&filled=false",
                     auth=auth,
                     verify=False)
    print("=======Current Applied Revision=======")
    print(json.dumps(r.json(), indent=2))

NVUE CLI

nvos@switch:~$ nv config show
- set:
    fae:
      system:
        events:
          table-size: 600
    interface:
      eth0-1:
        type: eth
...

Replace an Entire Configuration

To replace an entire configuration:

  1. Create a new revision ID with a POST:

    nvos@switch:~$ curl -u 'admin:****' --insecure -X POST https://127.0.0.1:443/nvue_v1/revision
    {
     "1": {
       "state": "pending",
       "transition": {
         "issue": {},
         "progress": ""
       }
     }
    }
    
  2. Record the revision ID. In the previous example, the revision ID is "1".

  3. Use a root patch to delete the entire configuration:

    nvos@switch:~$ curl -u 'admin:****' -d '{}' -H 'Content-Type: application/json' -k -X DELETE https://127.0.0.1:443/nvue_v1/?rev=1
    {}
    
  4. Use a root patch to update the switch with the new configuration:

    nvos@switch:~$ curl -u 'admin:****' -d '{
       "system": {
         "hostname": "switch01"
       },
       "interface": {
         "eth0": {
           "ipv4": {
             "address": {
               "192.168.200.6/24": {}
             },
           },
           "type": "eth"
         },
       }
     }' -H 'Content-Type: application/json' -k -X PATCH https://127.0.0.1:443/nvue_v1/?rev=1
    {}
    
  5. Apply the changes with a PATCH to the revision changeset.
    cURL Command

    nvos@switch:~$ curl -u 'admin:****' -H 'Content-Type:application/json' -d '{"state": "apply", "auto-prompt": {"ays": "ays_yes"}}' -k -X PATCH https://127.0.0.1:443/nvue_v1/revision/1
    {
      "state": "apply",
      "transition": {
        "issue": {},
        "progress": ""
      }
    }
    

    NVUE CLI

    nvos@switch:~$ nv config apply
    
  6. Review the status of the apply and the configuration:

    cURL Command

    nvos@switch:~$ curl -u 'admin:****' -k -X GET https://127.0.0.1:443/nvue_v1/revision/1
    {
      "state": "applied",
      "transition": {
        "issue": {},
        "progress": ""
      }
    }
    
    nvos@switch:~$ curl -u 'admin:****' --insecure https://127.0.0.1:443/nvue_v1/system 
    {
      "contact": null,
      "date-time": {
        "local-time": "2026-05-19 08:35:26",
        "timezone": "Etc/UTC"
      },
      "health": {
        "status": "OK"
      },
      "hostname": "rosalind-eb2-164-mgmt2",
      "location": null,
      "product-name": "nvos",
      "product-release": "25.03.0514-001",
      "status": "System is ready",
      "uptime": 43910,
      "version": {
        "product-release": "25.03.0514-001"
      }
    }
    

    Python Code

    #!/usr/bin/env python3
    
    import requests
    from requests.auth import HTTPBasicAuth
    import json
    import time
    
    auth = HTTPBasicAuth(username="admin", password="password")
    nvue_end_point = "https://127.0.0.1:443/nvue_v1"
    mime_header = {"Content-Type": "application/json"}
    
    DUMMY_SLEEP = 5  # In seconds
    POLL_APPLIED = 1  # in seconds
    RETRIES = 10
    
    def print_request(r: requests.Request):
        print("=======Request=======")
        print("URL:", r.url)
        print("Headers:", r.headers)
        print("Body:", r.body)
    
    def print_response(r: requests.Response):
        print("=======Response=======")
        print("Headers:", r.headers)
        print("Body:", json.dumps(r.json(), indent=2))
    
    def create_nvue_changest():
        r = requests.post(url=nvue_end_point + "/revision",
                          auth=auth,
                          verify=False)
        print_request(r.request)
        print_response(r)
        response = r.json()
        changeset = response.popitem()[0]
        return changeset
    
    def apply_nvue_changeset(changeset):
        apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
        url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                                   safe="")
        r = requests.patch(url=url,
                           auth=auth,
                           verify=False,
                           data=json.dumps(apply_payload),
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
    def is_config_applied(changeset) -> bool:
        # Check if the configuration was indeed applied
        global RETRIES
        global POLL_APPLIED
        retries = RETRIES
        while retries > 0:
            r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                             auth=auth,
                             verify=False)
            response = r.json()
            print(response)
            if response["state"] == "applied":
                return True
            retries -= 1
            time.sleep(POLL_APPLIED)
    
        return False
    
    def apply_new_config(path,payload):
        # Create a new revision ID
        changeset = create_nvue_changest()
        print("Using NVUE Changeset: '{}'".format(changeset))
    
        # Delete existing configuration
        query_string = {"rev": changeset}
        r = requests.delete(url=nvue_end_point + path,
                           auth=auth,
                           verify=False,
                           params=query_string,
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
        # Patch the new configuration
        
        query_string = {"rev": changeset}
        r = requests.patch(url=nvue_end_point + path,
                           auth=auth,
                           verify=False,
                           data=json.dumps(payload),
                           params=query_string,
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
        # Apply the changes to the new revision changeset
        apply_nvue_changeset(changeset)
    
        # Check if the changeset was applied
        is_config_applied(changeset)
    
    def nvue_get(path):
        r = requests.get(url=nvue_end_point + path,
                         auth=auth,
                         verify=False)
        print_request(r.request)
        print_response(r)
    
    if __name__ == "__main__":
        payload = {
          "system": {
            "hostname": "switch01"
          },
          "interface": {
            "eth0": {
              "ipv4": {
                "address": {
                  "192.168.200.6/24": {}
                },
              },
              "type": "eth"
    		}
          },
        }
        apply_new_config("/",payload)
        time.sleep(DUMMY_SLEEP)
        print("=====Verifying some of the configurations=====")
        nvue_get("/system")
        nvue_get("/interface")
    

    NVUE CLI

    nvos@switch:~$ nv show system
                       operational             applied
    -----------------  ----------------------  -------
    uptime             12:12:54
    hostname           rosalind-eb2-164-mgmt2
    product-name       nvos
    product-release    25.03.0514-001
    status             System is ready
    date-time
      local-time       2026-05-19 08:36:30
      timezone         Etc/UTC                 Etc/UTC
    health
      status           OK
    version
      product-release  25.03.0514-001                        
    

Verify a Configuration (Dry Run)

To verify a configuration without applying it (dry run), use the dry-run option in the state-controls field when you call the apply endpoint.

The dry-run field accepts the following values:

brief: Provides basic verification output (the default behavior of nv config verify).
verbose: Provides detailed output, including staged files and scheduled services.

  1. Create a new revision ID with a POST:

    nvos@switch:~$ curl -u 'admin:****' --insecure -X POST https://127.0.0.1:443/nvue_v1/revision
    {
     "1": {
       "state": "pending",
       "transition": {
         "issue": {},
         "progress": ""
       }
     }
    }
    
  2. Record the revision ID. In the previous example, the revision ID is "1".

  3. Patch the configuration to verify:

    curl -u admin:admin --insecure -X PATCH -H "Content-Type: text/plain" "https://10.7.145.61:443/nvue_v1/?rev=5" --data-binary @bad-config.txt
    
  4. Run the verification (dry run) in brief mode:

    admin@croc-61:~$ curl -u 'admin:admin' -H 'Content-Type: application/json' -k -X PATCH -d '{"state": "apply", "state-controls": {"dry-run": "brief"}}' --request GET https://10.7.145.61:443/nvue_v1/revision/1
    
  5. Run the verification (dry run) in verbose mode:

    admin@croc-61:~$ curl -u 'admin:admin' -H 'Content-Type: application/json' -k -X PATCH -d '{"state": "apply", "state-controls": {"dry-run": "verbose"}}' --request GET https://10.7.145.61:443/nvue_v1/revision/1
    

    Verify an existing revision by ID:

    curl -u admin:admin --insecure -X PATCH -H "Content-Type: application/json" "https://10.7.145.61:443/nvue_v1/revision/5" -d '{"state": "apply", "state-controls": {"dry-run": "brief"}}'
    

    NVUE CLI

    nvos@switch:~$ nv config verify filename config.txt
    nvos@switch:~$ nv config verify revision 5
    

Make a Configuration Change

To make a configuration change:

  1. Create a new revision ID with a POST:

    nvos@switch:~$ curl -u 'admin:****' --insecure -X POST https://127.0.0.1:443/nvue_v1/revision
    {
       "2": {
       "state": "pending",
       "transition": {
         "issue": {},
         "progress": ""
       }
     }
    }
    
  2. Record the revision ID. In the previous example, the revision ID is "2".

  3. Make the change with a PATCH and link it to the revision ID:

    cURL Command

    nvos@switch:~$ curl -u 'admin:****' -d '{"99.99.99.99/32": {}}' -H 'Content-Type: application/json' -k -X PATCH https://127.0.0.1:443/nvue_v1/interface/eth0/ipv4/address?rev=2
    {
      "99.99.99.99/32": {}
    }
    

    NVUE CLI

    nvos@switch:~$ nv set interface eth0 ipv4 address 99.99.99.99/32
    
  4. Apply the changes with a PATCH to the revision changeset:

    cURL Command

    nvos@switch:~$ curl -u 'admin:****' -H 'Content-Type:application/json' -k -X PATCH https://127.0.0.1:443/nvue_v1/revision/2
    {
      "state": "apply",
      "transition": {
        "issue": {},
        "progress": ""
      }
    }
    

    NVUE CLI

    nvos@switch:~$ nv config apply
    
  5. Review the status of the apply and the configuration:

    cURL Command

    nvos@switch:~$ curl -u 'admin:****' -k -X GET https://127.0.0.1:443/nvue_v1/revision/2
    {
      "state": "applied",
      "transition": {
        "issue": {},
        "progress": ""
      }
    }
    
    nvos@switch:~$ curl -u 'admin:****' -k -X GET https://127.0.0.1:443/nvue_v1/revision/2
    {
      "state": "applied",
      "transition": {
        "issue": {},
        "progress": ""
      }
    }
    

    Python Code

    #!/usr/bin/env python3
    
    import requests
    from requests.auth import HTTPBasicAuth
    import json
    import time
    
    auth = HTTPBasicAuth(username="admin", password="password")
    nvue_end_point = "https://127.0.0.1:443/nvue_v1"
    mime_header = {"Content-Type": "application/json"}
    
    DUMMY_SLEEP = 5  # In seconds
    POLL_APPLIED = 1  # in seconds
    RETRIES = 10
    
    def print_request(r: requests.Request):
        print("=======Request=======")
        print("URL:", r.url)
        print("Headers:", r.headers)
        print("Body:", r.body)
    
    def print_response(r: requests.Response):
        print("=======Response=======")
        print("Headers:", r.headers)
        print("Body:", json.dumps(r.json(), indent=2))
    
    def create_nvue_changest():
        r = requests.post(url=nvue_end_point + "/revision",
                          auth=auth,
                          verify=False)
        print_request(r.request)
        print_response(r)
        response = r.json()
        changeset = response.popitem()[0]
        return changeset
    
    def apply_nvue_changeset(changeset):
        apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
        url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                                   safe="")
        r = requests.patch(url=url,
                           auth=auth,
                           verify=False,
                           data=json.dumps(apply_payload),
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
    def is_config_applied(changeset) -> bool:
        # Check if the configuration was indeed applied
        global RETRIES
        global POLL_APPLIED
        retries = RETRIES
        while retries > 0:
            r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                             auth=auth,
                             verify=False)
            response = r.json()
            print(response)
            if response["state"] == "applied":
                return True
            retries -= 1
            time.sleep(POLL_APPLIED)
    
        return False
    
    def apply_new_config(path,payload):
        # Create a new revision ID
        changeset = create_nvue_changest()
        print("Using NVUE Changeset: '{}'".format(changeset))
    
        # Delete existing configuration
        query_string = {"rev": changeset}
        r = requests.delete(url=nvue_end_point + path,
                           auth=auth,
                           verify=False,
                           params=query_string,
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
        # Patch the new configuration
        
        query_string = {"rev": changeset}
        r = requests.patch(url=nvue_end_point + path,
                           auth=auth,
                           verify=False,
                           data=json.dumps(payload),
                           params=query_string,
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
        # Apply the changes to the new revision changeset
        apply_nvue_changeset(changeset)
    
        # Check if the changeset was applied
        is_config_applied(changeset)
    
    def nvue_get(path):
        r = requests.get(url=nvue_end_point + path,
                         auth=auth,
                         verify=False)
        print_request(r.request)
        print_response(r)
    
    if __name__ == "__main__":
        payload = {
            "99.99.99.99/32": {}
        }
        apply_new_config("/interface/eth0/ipv4/address",payload)
        time.sleep(DUMMY_SLEEP)
        nvue_get("/interface/eth0/ipv4/address")
    

    NVUE CLI

    nvos@switch:~$ nv show interface eth0 ip address
       
    -------------
    99.99.99.99/32
    127.0.0.1/8
    ::1/128
    

View Differences Between Configurations

To view the differences between configurations, use the GET /nvue_v1/<resource>?rev=<rev-A>&diff=<rev-B> method with the configurations you want to diff. This method is equivalent to the NVUE nv config diff <rev-A> <rev-B> command.

To see the difference between the startup revision and the applied revision:

$ curl -u 'admin:****' --insecure -X GET /nvue_v1/interface?rev=startup&diff=applied

To see the difference between revision 1 and revision 2:

$ curl -u 'admin:****' --insecure -X GET /nvue_v1/<resource>?rev=1&diff=2

You can change the order of the revisions; for example, GET /nvue_v1/<resource>?rev=2&diff=1.

Troubleshoot Configuration Changes

When a configuration change fails, you see an error in the change request.

Configuration Apply Fails with Warnings

In some cases, such as the first push with NVUE or when you change a file manually instead of with NVUE, you see a warning prompt and the apply fails.

nvos@switch:~$ curl -u 'admin:****' --insecure -X GET https://127.0.0.1:443/nvue_v1/revision/6
{
  "6": {
    "state": "ays_fail",
    "transition": {
      "issue": {
        "0": {
          "code": "client_timeout",
          "data": {},
          "message": "Timeout while waiting for client response",
          "severity": "error"
        }
      },
      "progress": "Aborted apply after warnings"
    }
  }

To resolve this issue, review the failures or errors, and then inspect the configuration that you are trying to apply. After you resolve the errors, retry the API request. To ignore the errors and force an apply, add "auto-prompt":{"ays": "ays_yes"} to the configuration apply request.

nvos@switch:~$ curl -u 'admin:****' -d '{"state":"apply","auto-prompt":{"ays": "ays_yes"}}' -H 'Content-Type:application/json' --insecure -X PATCH https://127.0.0.1:443/nvue_v1/revision/6

Save a Configuration

To save an applied configuration change to the startup configuration file (/etc/nvue.d/startup.yaml) so that the changes persist after a reboot, use a PATCH to the applied revision with the save state.

cURL Command

nvos@switch:~$ curl -u 'admin:****' -k -X PATCH -d '{"state": "save", "auto-prompt": {"ays": "ays_yes"}}' -H 'Content-Type: application/json'  https://127.0.0.1:443/nvue_v1/revision/applied
{
  "state": "save",
  "transition": {
    "issue": {},
    "progress": ""
  }
}

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

DUMMY_SLEEP = 5  # In seconds
POLL_APPLIED = 1  # in seconds
RETRIES = 10

def print_request(r: requests.Request):
    print("=======Request=======")
    print("URL:", r.url)
    print("Headers:", r.headers)
    print("Body:", r.body)

def print_response(r: requests.Response):
    print("=======Response=======")
    print("Headers:", r.headers)
    print("Body:", json.dumps(r.json(), indent=2))

def save_nvue_changeset():
    apply_payload = {"state": "save", "auto-prompt": {"ays": "ays_yes"}}
    url = nvue_end_point + "/revision/applied"
    r = requests.patch(url=url,
                       auth=auth,
                       verify=False,
                       data=json.dumps(apply_payload),
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

if __name__ == "__main__":
    save_nvue_changeset()

NVUE CLI

nvos@switch:~$ nv config save
saved

Unset a Configuration Change

To unset a change, use the null value for the key. For example, to delete start configuration from the eth1 port, use the following syntax:

nvos@switch:~$ curl -u 'admin:****' -d '{"eth1":null}' -H 'Content-Type: application/json' --insecure -X PATCH https://127.0.0.1:443/nvue_v1/interface/rev=4

When you unset a change, you must still use the PATCH method. The null value indicates removal of the entry. The data is {"eth1":null} with the PATCH method.

Use the API for Active Monitoring

The following example retrieves the counters for interface sw1p1.

cURL Command

nvos@switch:~$ curl -u 'admin:****' -k -X GET https://127.0.0.1:443/nvue_v1/interface/sw1p1/counters/link
{
  "buffer-overrun-errors": 0,
  "in-bytes": 16128,
  "in-drops": 0,
  "in-errors": 0,
  "in-pkts": 56,
  "in-symbol-errors": 0,
  "link-downed": 0,
  "link-error-recovery": 0,
  "local-link-integrity-errors": 0,
  "out-bytes": 16128,
  "out-drops": 0,
  "out-errors": 0,
  "out-pkts": 56,
  "out-wait": 0,
  "port-rcv-constraint-errors": 0,
  "port-rcv-remote-physical-errors": 0,
  "port-rcv-switch-relay-errors": 0,
  "qp1-drops": 0,
  "rcv-icrc-errors": 0,
  "tx-parity-errors": 0
}

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

if __name__ == "__main__":
    r = requests.get(url=nvue_end_point + "/interface/sw1p1/counters/link",
                     auth=auth,
                     verify=False)
    print("=======Interface sw1p1 Counters=======")
    print(json.dumps(r.json(), indent=2))

NVUE CLI

nvos@switch:~$ nv show interface sw1p1 counters link --view detail
                                 operational  description
-------------------------------  -----------  ----------------------------------------------------------------------
in-bytes                         15.75 KB     Total number of bytes received on the interface
in-pkts                          56           Total number of packets received on the interface
in-drops                         0            Number of received packets dropped
in-errors                        0            Number of received packets with errors
out-bytes                        15.75 KB     Total number of bytes transmitted out of the interface
out-pkts                         56           Total number of packets transmitted out of the interface
out-drops                        0            The number of outbound packets that were chosen to be discarded even
                                              though no errors had been detected to prevent their being transmitted.
out-errors                       0            The number of outbound packets that could not be transmitted because
                                              of errors.
in-symbol-errors                 0            Total number of minor errors detected on one or more physical lanes
out-wait                         0            The number of ticks during which the port selected by PortSelect had
                                              data to transmit but no data was sent during the entire tick because
                                              of insufficient credits or of lack of arbitration.
link-error-recovery              0            Total number of times the Port Training state machine has successfully
                                              completed the link error recovery process
link-downed                      0            Total number of times the Port Training state machine has failed the
                                              link error recovery process and downed the link
port-rcv-remote-physical-errors  0            Total number of packets marked with the EBP delimiter received on the
                                              port
port-rcv-switch-relay-errors     0            Total number of packets received on the port that were discarded
                                              because they could not be forwarded by the switch relay
port-rcv-constraint-errors       0            Total number of packets received on the switch physical port that are
                                              discarded due to constraints
local-link-integrity-errors      0            Total number of times that the count of local physical errors exceeded
                                              the threshold specified by Local Phy Errors
qp1-drops                        0            Total number of QP1 MADs (packets) dropped due to resource limitations
buffer-overrun-errors            0            The number of times that Overrun-Errors consecutive flow control
                                              update periods occur
rcv-icrc-errors                  0            Total number of icrc payload corruption rx errors
tx-parity-errors                 0            Total number of icrc payload corruption tx parity errors

Retrieve View Types

NVUE provides views for certain show commands. A view is a subset of information.

To see the views available for a show command, run the command with --view and press Tab:

nvos@switch:~$ nv show interface --view <<TAB>>
brief             detail            link-diagnostics  lldp              mac               small

To retrieve view types through the REST API, use the curl -u 'admin:****' -k -X GET http://<path>?view=<brief> syntax. For example, the equivalent REST API method for the NVUE nv show interface --view=brief command is:

nvos@switch:~$ curl -u 'admin:****' -k -X GET https://127.0.0.1:443/nvue_v1/interface?view=brief

Convert CLI Changes to Use the API

You can take a configuration change from the CLI and use the API to configure the same set of changes.

  1. Make your configuration changes on the system with the NVUE CLI.

    nvos@switch:~$ nv set system hostname switch01
    nvos@switch:~$ nv set interface eth0 ipv4 address 192.168.200.6/24 
    
  2. View the changes as a JSON blob.

    nvos@switch:~$ nv config diff -o json 
    [
      {
        "set": {
          "interface": {
            "eth0": {
              "ip": {
                "address": {
                  "192.168.200.6/24": {}
                }
              }
            }
          },
          "system": {
            "hostname": "switch01"
          }
        }
      }
    ]
    
  3. Use the JSON blob as the payload of a root patch request.

    nvos@switch:~$ curl -u 'admin:****' -d '{
          "interface": {
            "eth0": {
              "ipv4": {
                "address": {
                  "192.168.200.6/24": {}
                }
              }
            }
          },
          "system": {
            "hostname": "switch01"
          }
        }' -k -X PATCH https://127.0.0.1:443/nvue_v1/?rev=3
    
    
  4. Apply the changes with a PATCH to the revision changeset.

    nvos@switch:~$ curl -u 'admin:****' -H 'Content-Type:application/json' -k -d '{"state": "apply", "auto-prompt": {"ays": "ays_yes"}}' -X PATCH https://127.0.0.1:443/nvue_v1/revision/3
    {
      "state": "apply",
      "transition": {
        "issue": {},
        "progress": ""
      }
    }
    
  5. Review the status of the apply and the configuration:
    cURL Command

    nvos@switch:~$ curl -u 'admin:****' -k -X GET https://127.0.0.1:443/nvue_v1/revision/3
    {
      "state": "applied",
      "transition": {
        "issue": {},
        "progress": ""
      }
    }
    

    Python Code

    #!/usr/bin/env python3
    
    import requests
    from requests.auth import HTTPBasicAuth
    import json
    import time
    
    auth = HTTPBasicAuth(username="admin", password="password")
    nvue_end_point = "https://127.0.0.1:443/nvue_v1"
    mime_header = {"Content-Type": "application/json"}
    
    DUMMY_SLEEP = 5  # In seconds
    POLL_APPLIED = 1  # in seconds
    RETRIES = 10
    
    def print_request(r: requests.Request):
        print("=======Request=======")
        print("URL:", r.url)
        print("Headers:", r.headers)
        print("Body:", r.body)
    
    def print_response(r: requests.Response):
        print("=======Response=======")
        print("Headers:", r.headers)
        print("Body:", json.dumps(r.json(), indent=2))
    
    def create_nvue_changest():
        r = requests.post(url=nvue_end_point + "/revision",
                          auth=auth,
                          verify=False)
        print_request(r.request)
        print_response(r)
        response = r.json()
        changeset = response.popitem()[0]
        return changeset
    
    def apply_nvue_changeset(changeset):
        # apply_payload = {"state": "apply"}
        apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
        url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                                   safe="")
        r = requests.patch(url=url,
                           auth=auth,
                           verify=False,
                           data=json.dumps(apply_payload),
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
    def is_config_applied(changeset) -> bool:
        # Check if the configuration was indeed applied
        global RETRIES
        global POLL_APPLIED
        retries = RETRIES
        while retries > 0:
            r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                             auth=auth,
                             verify=False)
            response = r.json()
            print(response)
    
            if response["state"] == "applied":
                return True
            retries -= 1
            time.sleep(POLL_APPLIED)
    
        return False
    
    def apply_new_config(path,payload):
        # Create a new revision ID
        changeset = create_nvue_changest()
        print("Using NVUE Changeset: '{}'".format(changeset))
    
        # Delete existing configuration
        query_string = {"rev": changeset}
        r = requests.delete(url=nvue_end_point + path,
                           auth=auth,
                           verify=False,
                           params=query_string,
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
        # Patch the new configuration
        
        query_string = {"rev": changeset}
        r = requests.patch(url=nvue_end_point + path,
                           auth=auth,
                           verify=False,
                           data=json.dumps(payload),
                           params=query_string,
                           headers=mime_header)
        print_request(r.request)
        print_response(r)
    
        # Apply the changes to the new revision changeset
        apply_nvue_changeset(changeset)
    
        # Check if the changeset was applied
        is_config_applied(changeset)
    
    def nvue_get(path):
        r = requests.get(url=nvue_end_point + path,
                         auth=auth,
                         verify=False)
        print_request(r.request)
        print_response(r)
    
    if __name__ == "__main__":
        payload = {
          "interface": {
            "eth0": {
              "ipv4": {
                "address": {
                  "192.168.200.6/24": {}
                }
              }
            }
          },
          "system": {
            "hostname": "switch01"
          }
        }
        apply_new_config("/",payload)
        time.sleep(DUMMY_SLEEP)
        nvue_get("/interface/eth0")
        nvue_get("/system")
    

API Examples

The following sections provide practical API examples.

Configure the System

To set the system hostname, pre-login or post-login message, and time zone on the switch, send a targeted API request to /nvue_v1/system.

cURL Command

nvos@switch:~$ curl -u 'admin:****' -d '{"system": {"hostname":"switch01","date-time": {"timezone":"America/
Los_Angeles"},"message":{"pre-login":"Welcome to NVOS","post-login":"You have successfully logged in to
switch01"}}}' -k -X PATCH https://127.0.0.1:443/nvue_v1/?rev=4

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

DUMMY_SLEEP = 5  # In seconds
POLL_APPLIED = 1  # in seconds
RETRIES = 10

def print_request(r: requests.Request):
    print("=======Request=======")
    print("URL:", r.url)
    print("Headers:", r.headers)
    print("Body:", r.body)

def print_response(r: requests.Response):
    print("=======Response=======")
    print("Headers:", r.headers)
    print("Body:", json.dumps(r.json(), indent=2))

def create_nvue_changest():
    r = requests.post(url=nvue_end_point + "/revision",
                      auth=auth,
                      verify=False)
    print_request(r.request)
    print_response(r)
    response = r.json()
    changeset = response.popitem()[0]
    return changeset

def apply_nvue_changeset(changeset):
    # apply_payload = {"state": "apply"}
    apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
    url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                               safe="")
    r = requests.patch(url=url,
                       auth=auth,
                       verify=False,
                       data=json.dumps(apply_payload),
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

def is_config_applied(changeset) -> bool:
    # Check if the configuration was indeed applied
    global RETRIES
    global POLL_APPLIED
    retries = RETRIES
    while retries > 0:
        r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                         auth=auth,
                         verify=False)
        response = r.json()
        print(response)

        if response["state"] == "applied":
            return True
        retries -= 1
        time.sleep(POLL_APPLIED)

    return False

def apply_new_config(path,payload):
    # Create a new revision ID
    changeset = create_nvue_changest()
    print("Using NVUE Changeset: '{}'".format(changeset))

    # Delete existing configuration
    query_string = {"rev": changeset}
    r = requests.delete(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Patch the new configuration

    query_string = {"rev": changeset}
    r = requests.patch(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       data=json.dumps(payload),
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Apply the changes to the new revision changeset
    apply_nvue_changeset(changeset)

    # Check if the changeset was applied
    is_config_applied(changeset)

def nvue_get(path):
    r = requests.get(url=nvue_end_point + path,
                     auth=auth,
                     verify=False)
    print_request(r.request)
    print_response(r)

if __name__ == "__main__":
    payload = {
        "system":
        {
            "hostname":"switch01",
            "date-time":{
                "timezone":"America/Los_Angeles"
            },
            "message":
            {
                "pre-login":"Welcome to NVOS",
                "post-login":"You have successfully logged in to switch01"
            }
        }
    }
    apply_new_config("/",payload) # Root patch
    time.sleep(DUMMY_SLEEP)
    nvue_get("/system")

NVUE CLI

nvos@switch:~$ nv set system hostname switch01
nvos@switch:~$ nv set system date-time timezone America/Los_Angeles
nvos@switch:~$ nv set system message pre-login "Welcome to NVOS"
nvos@switch:~$ nv set system message post-login "You have successfully logged into switch01"

Configure Services

To set up NTP, SYSLOG, and SNMP on the switch, send a targeted API request to /nvue_v1/system.

cURL Command

nvos@switch:~$ curl -u 'admin:****' -d '{"system": { "ntp": {"server":{"4.nvos.pool.ntp.org":{}}}}}' -k -X PATCH https://127.0.0.1:443/nvue_v1/?rev=5

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

DUMMY_SLEEP = 5  # In seconds
POLL_APPLIED = 1  # in seconds
RETRIES = 10

def print_request(r: requests.Request):
    print("=======Request=======")
    print("URL:", r.url)
    print("Headers:", r.headers)
    print("Body:", r.body)

def print_response(r: requests.Response):
    print("=======Response=======")
    print("Headers:", r.headers)
    print("Body:", json.dumps(r.json(), indent=2))

def create_nvue_changest():
    r = requests.post(url=nvue_end_point + "/revision",
                      auth=auth,
                      verify=False)
    print_request(r.request)
    print_response(r)
    response = r.json()
    changeset = response.popitem()[0]
    return changeset

def apply_nvue_changeset(changeset):
    # apply_payload = {"state": "apply"}
    apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
    url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                               safe="")
    r = requests.patch(url=url,
                       auth=auth,
                       verify=False,
                       data=json.dumps(apply_payload),
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

def is_config_applied(changeset) -> bool:
    # Check if the configuration was indeed applied
    global RETRIES
    global POLL_APPLIED
    retries = RETRIES
    while retries > 0:
        r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                         auth=auth,
                         verify=False)
        response = r.json()
        print(response)

        if response["state"] == "applied":
            return True
        retries -= 1
        time.sleep(POLL_APPLIED)

    return False

def apply_new_config(path,payload):
    # Create a new revision ID
    changeset = create_nvue_changest()
    print("Using NVUE Changeset: '{}'".format(changeset))

    # Delete existing configuration
    query_string = {"rev": changeset}
    r = requests.delete(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Patch the new configuration

    query_string = {"rev": changeset}
    r = requests.patch(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       data=json.dumps(payload),
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Apply the changes to the new revision changeset
    apply_nvue_changeset(changeset)

    # Check if the changeset was applied
    is_config_applied(changeset)

def nvue_get(path):
    r = requests.get(url=nvue_end_point + path,
                     auth=auth,
                     verify=False)
    print_request(r.request)
    print_response(r)

if __name__ == "__main__":
    payload = {
      "system":
      {
        "ntp":
        {
          "server":
            {
              "4.nvos.pool.ntp.org": {}
            }
        },
      }
    }
    apply_new_config("/",payload) # Root patch
    time.sleep(DUMMY_SLEEP)
    nvue_get("/system/ntp")

NVUE CLI

nvos@switch:~$ nv set system ntp server 4.nvos.pool.ntp.org

Configure Users

The following example creates a new user and then deletes the user.

cURL Command

This example creates a new user named test1.

nvos@switch:~$ curl -u 'admin:****' -d '{"system": {"aaa": {"user": {"test1": {"hashed-password":"72b28582708d749c6c82f3b3f226041f1bd37090281641eaeba8d44bd915d0042d609a92759d9f6fb96475cb0601cf428cd22613df8a53a09461e0b426cf0a35","role": "monitor","state": "enabled","full-name": "Test User"}}}}}' -k -X PATCH https://127.0.0.1:443/nvue_v1/?rev=5

This example deletes the test1 user.

nvos@switch:~$ curl -u 'admin:****' -k -X DELETE https://127.0.0.1:443/nvue_v1/system/aaa/user/test1?rev=6

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

DUMMY_SLEEP = 5  # In seconds
POLL_APPLIED = 1  # in seconds
RETRIES = 10

def print_request(r: requests.Request):
    print("=======Request=======")
    print("URL:", r.url)
    print("Headers:", r.headers)
    print("Body:", r.body)

def print_response(r: requests.Response):
    print("=======Response=======")
    print("Headers:", r.headers)
    print("Body:", json.dumps(r.json(), indent=2))

def create_nvue_changest():
    r = requests.post(url=nvue_end_point + "/revision",
                      auth=auth,
                      verify=False)
    print_request(r.request)
    print_response(r)
    response = r.json()
    changeset = response.popitem()[0]
    return changeset

def apply_nvue_changeset(changeset):
    # apply_payload = {"state": "apply"}
    apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
    url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                               safe="")
    r = requests.patch(url=url,
                       auth=auth,
                       verify=False,
                       data=json.dumps(apply_payload),
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

def is_config_applied(changeset) -> bool:
    # Check if the configuration was indeed applied
    global RETRIES
    global POLL_APPLIED
    retries = RETRIES
    while retries > 0:
        r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                         auth=auth,
                         verify=False)
        response = r.json()
        print(response)

        if response["state"] == "applied":
            return True
        retries -= 1
        time.sleep(POLL_APPLIED)

    return False

def apply_new_config(path,payload):
    # Create a new revision ID
    changeset = create_nvue_changest()
    print("Using NVUE Changeset: '{}'".format(changeset))

    # Delete existing configuration
    query_string = {"rev": changeset}
    r = requests.delete(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Patch the new configuration

    query_string = {"rev": changeset}
    r = requests.patch(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       data=json.dumps(payload),
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Apply the changes to the new revision changeset
    apply_nvue_changeset(changeset)

    # Check if the changeset was applied
    is_config_applied(changeset)

def delete_config(path):
    # Create an NVUE changeset
    changeset = create_nvue_changest()
    print("Using NVUE Changeset: '{}'".format(changeset))

    # Equivalent to JSON `null`
    payload = None

    # Stage the change
    query_string = {"rev": changeset}
    r = requests.delete(url=nvue_end_point + path,
                        auth=auth,
                        verify=False,
                        data=json.dumps(payload),
                        params=query_string,
                        headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Apply the staged changeset
    apply_nvue_changeset(changeset)

    # Check if the changeset was applied
    is_config_applied(changeset)

def nvue_get(path):
    r = requests.get(url=nvue_end_point + path,
                     auth=auth,
                     verify=False)
    print_request(r.request)
    print_response(r)

if __name__ == "__main__":

    # Need to create a hashed password - The supported password
    # Here in this example, we use SHA-512
    import crypt
    hashed_password = crypt.crypt("hello$world#2023", salt=crypt.METHOD_SHA512)
    payload = {
        "system": {
            "aaa": {
                "user": {
                    "test1": {
                        "hashed-password": hashed_password,
                        "role": "monitor",
                        "state": "enabled",
                        "full-name": "Test User",
                    }
                }
            }
        }
    }
    apply_new_config("/",payload) # Root patch
    time.sleep(DUMMY_SLEEP)
    nvue_get("/system/user/aaa")

    """Delete an existing user account using the AAA API."""
    delete_config("/system/aaa/user/test1")
    time.sleep(DUMMY_SLEEP)
    nvue_get("/system/user/aaa")

NVUE CLI

This example creates a new user named test1.

nvos@switch:~$ nv set system aaa user test1
nvos@switch:~$ nv set system aaa user test1 full-name "Test User"
nvos@switch:~$ nv set system aaa user test1 password "abcd@test"
nvos@switch:~$ nv set system aaa user test1 role monitor
nvos@switch:~$ nv set system aaa user test1 state enabled

This example deletes the user test1.

nvos@switch:~$ nv unset system aaa user test1

Configure an Interface

The following example configures an interface.

cURL Command

nvos@switch:~$ curl -u 'admin:****' -k -d '{"eth1": {"link":{"state":{"up": {}}}}}' -H 'Content-Type: application/json' -k -X PATCH https://127.0.0.1:443/nvue_v1/interface?rev=21

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

DUMMY_SLEEP = 5  # In seconds
POLL_APPLIED = 1  # in seconds
RETRIES = 10

def print_request(r: requests.Request):
    print("=======Request=======")
    print("URL:", r.url)
    print("Headers:", r.headers)
    print("Body:", r.body)

def print_response(r: requests.Response):
    print("=======Response=======")
    print("Headers:", r.headers)
    print("Body:", json.dumps(r.json(), indent=2))

def create_nvue_changest():
    r = requests.post(url=nvue_end_point + "/revision",
                      auth=auth,
                      verify=False)
    print_request(r.request)
    print_response(r)
    response = r.json()
    changeset = response.popitem()[0]
    return changeset

def apply_nvue_changeset(changeset):
    # apply_payload = {"state": "apply"}
    apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
    url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                               safe="")
    r = requests.patch(url=url,
                       auth=auth,
                       verify=False,
                       data=json.dumps(apply_payload),
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

def is_config_applied(changeset) -> bool:
    # Check if the configuration was indeed applied
    global RETRIES
    global POLL_APPLIED
    retries = RETRIES
    while retries > 0:
        r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                         auth=auth,
                         verify=False)
        response = r.json()
        print(response)

        if response["state"] == "applied":
            return True
        retries -= 1
        time.sleep(POLL_APPLIED)

    return False

def apply_new_config(path,payload):
    # Create a new revision ID
    changeset = create_nvue_changest()
    print("Using NVUE Changeset: '{}'".format(changeset))

    # Delete existing configuration
    query_string = {"rev": changeset}
    r = requests.delete(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Patch the new configuration

    query_string = {"rev": changeset}
    r = requests.patch(url=nvue_end_point + path,
                       auth=auth,
                       verify=False,
                       data=json.dumps(payload),
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Apply the changes to the new revision changeset
    apply_nvue_changeset(changeset)

    # Check if the changeset was applied
    is_config_applied(changeset)

def nvue_get(path):
    r = requests.get(url=nvue_end_point + path,
                     auth=auth,
                     verify=False)
    print_request(r.request)
    print_response(r)

if __name__ == "__main__":
    payload = {
      "eth1":
      {
        "type": "eth",
        "link":
        {
          "state":"up"
          }
        }
      }
    apply_new_config("/interface",payload)
    time.sleep(DUMMY_SLEEP)
    nvue_get("/interface/eth1")

NVUE CLI

nvos@switch:~$ nv set interface eth1

Action Operations

The NVUE action operations are ephemeral operations that do not modify the state of the configuration; for example, they reset interface counters and reboot the system.

cURL Command

To clear counters on sw1p1:

nvos@switch:~$ curl -u 'admin:****' -H 'Content-Type:application/json' -d '{"@clear": {"state": "start", "parameters": {}}}' -k -X POST https://127.0.0.1:443/nvue_v1/interface/sw1p1/link/counters
1
nvos@switch:~$ curl -u 'admin:****' -X GET https://127.0.0.1:443/nvue_v1/action/1 -k
{"detail":"sw1p1 counters cleared.","http_status":200,"issue":[],"state":"action_success","status":"sw1p1 counters cleared.","timeout":60,"type":""}

Python Code

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

DUMMY_SLEEP = 5  # In seconds
POLL_APPLIED = 1  # in seconds
RETRIES = 10

def print_request(r: requests.Request):
    print("=======Request=======")
    print("URL:", r.url)
    print("Headers:", r.headers)
    print("Body:", r.body)

def print_response(r: requests.Response):
    print("=======Response=======")
    print("Headers:", r.headers)
    print("Body:", json.dumps(r.json(), indent=2))

def nvue_action():
    r = requests.post(url=nvue_end_point + path,
                      auth=auth,
                      verify=False,
                      data=json.dumps(apply_payload),
                      headers=mime_header)
    print_request(r.request)
    print_response(r)
    return response

def nvue_get(path):
    r = requests.get(url=nvue_end_point + path,
                     auth=auth,
                     verify=False)
    print_request(r.request)
    print_response(r)

if __name__ == "__main__":
    payload = {
      "@clear":
      {
        "state": "start",
        "parameters": {}
      }
    }
    action_id=nvue_action("/interface/sw1p1/link/counters",payload)
    time.sleep(DUMMY_SLEEP)
    nvue_get(f"/action/{action_id}")

NVUE CLI

nvos@switch:~$ nv action clear interface sw1p1 counters

Example Python Script

In the following Python example, the full_config_example() method sets the system pre-login message and changes a few other configuration settings in a single bulk operation. The API endpoint is the root node, /nvue_v1.

#!/usr/bin/env python3

import requests
from requests.auth import HTTPBasicAuth
import json
import time

auth = HTTPBasicAuth(username="admin", password="password")
nvue_end_point = "https://127.0.0.1:443/nvue_v1"
mime_header = {"Content-Type": "application/json"}

DUMMY_SLEEP = 5  # In seconds
POLL_APPLIED = 1  # in seconds
RETRIES = 10

def print_request(r: requests.Request):
    print("=======Request=======")
    print("URL:", r.url)
    print("Headers:", r.headers)
    print("Body:", r.body)

def print_response(r: requests.Response):
    print("=======Response=======")
    print("Headers:", r.headers)
    print("Body:", json.dumps(r.json(), indent=2))

def sanity():
    # Basic retrieval to check connectivity
    r = requests.get(url=nvue_end_point + "/system",
                     auth=auth,
                     verify=False)
    print_request(r.request)
    print_response(r)

def create_nvue_changest():
    r = requests.post(url=nvue_end_point + "/revision",
                      auth=auth,
                      verify=False)
    print_request(r.request)
    print_response(r)
    response = r.json()
    changeset = response.popitem()[0]
    return changeset

def apply_nvue_changeset(changeset):
    # apply_payload = {"state": "apply"}
    apply_payload = {"state": "apply", "auto-prompt": {"ays": "ays_yes"}}
    url = nvue_end_point + "/revision/" + requests.utils.quote(changeset,
                                                               safe="")
    r = requests.patch(url=url,
                       auth=auth,
                       verify=False,
                       data=json.dumps(apply_payload),
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

def full_config_example():
    # Create an NVUE changeset
    changeset = create_nvue_changest()
    print("Using NVUE Changeset: '{}'".format(changeset))

    # https://www.asciiart.eu/comics/batman
    pre_login_message = u"""
                   ,.ood888888888888boo.,
              .od888P^""            ""^Y888bo.
          .od8P''   ..oood88888888booo.    ``Y8bo.
       .odP'"  .ood8888888888888888888888boo.  "`Ybo.
     .d8'   od8'd888888888f`8888't888888888b`8bo   `Yb.
    d8'  od8^   8888888888[  `'  ]8888888888   ^8bo  `8b
  .8P  d88'     8888888888P      Y8888888888     `88b  Y8.
 d8' .d8'       `Y88888888'      `88888888P'       `8b. `8b
.8P .88P            """"            """"            Y88. Y8.
88  888                                              888  88
88  888                                              888  88
88  888.        ..                        ..        .888  88
`8b `88b,     d8888b.od8bo.      .od8bo.d8888b     ,d88' d8'
 Y8. `Y88.    8888888888888b    d8888888888888    .88P' .8P
  `8b  Y88b.  `88888888888888  88888888888888'  .d88P  d8'
    Y8.  ^Y88bod8888888888888..8888888888888bod88P^  .8P
     `Y8.   ^Y888888888888888LS888888888888888P^   .8P'
       `^Yb.,  `^^Y8888888888888888888888P^^'  ,.dP^'
          `^Y8b..   ``^^^Y88888888P^^^'    ..d8P^'
              `^Y888bo.,            ,.od888P^'
                   "`^^Y888888888888P^^'"
"""

    # https://www.asciiart.eu/comics/superman
    post_login_message = u'''
        _____________________________________________
      //:::::::::::::::::::::::::::::::::::::::::::::\\
    //:::_______:::::::::________::::::::::_____:::::::\\
  //:::_/   _-"":::_--"""        """--_::::\_  ):::::::::\\
 //:::/    /:::::_"                    "-_:::\/:::::|^\:::\\
//:::/   /~::::::I__                      \:::::::::|  \:::\\
\\:::\   (::::::::::""""---___________     "--------"  /::://
 \\:::\  |::::::::::::::::::::::::::::""""==____      /::://
  \\:::"\/::::::::::::::::::::::::::::::::::::::\   /~::://
    \\:::::::::::::::::::::::::::::::::::::::::::)/~::://
      \\::::\""""""------_____::::::::::::::::::::::://
        \\:::"\               """""-----_____:::::://
          \\:::"\    __----__                )::://
            \\:::"\/~::::::::~\_         __/~:://
              \\::::::::::::::::""----""":::://
                \\::::::::::::::::::::::::://
                  \\:::\^""--._.--""^/::://
                    \\::"\         /":://
                      \\::"\     /":://
                        \\::"\_/":://
                          \\::::://
                            \\_//
                              "
'''

    # Prepare payload which configures a few
    # different switch configurations
    payload = {
        "interface":{
            "eth0":{
                "description": "management port"
            }
        },
        "system":{
            "message":{
                "pre-login": pre_login_message,
                "post-login": post_login_message
            },
            "date-time":{
                "timezone": "Europe/Paris"
            }
        },
    }
    # Stage the change
    query_string = {"rev": changeset}
    r = requests.patch(url=nvue_end_point + "/",  # Root patch
                       auth=auth,
                       verify=False,
                       data=json.dumps(payload),
                       params=query_string,
                       headers=mime_header)
    print_request(r.request)
    print_response(r)

    # Apply the staged changeset
    apply_nvue_changeset(changeset)

    # Check if the changeset was applied
    is_config_applied(changeset)


def message_get():
    # Get the system pre-login/post-login
    # message that was configured.
    r = requests.get(url=nvue_end_point + "/system/message",
                     auth=auth,
                     verify=False)
    print_request(r.request)
    print_response(r)

def is_config_applied(changeset) -> bool:
    # Check if the configuration was indeed applied
    global RETRIES
    global POLL_APPLIED
    retries = RETRIES
    while retries > 0:
        r = requests.get(url=nvue_end_point + "/revision/" + requests.utils.quote(changeset, safe=""),
                         auth=auth,
                         verify=False)
        response = r.json()
        print(response)

        if response["state"] == "applied":
            return True
        retries -= 1
        time.sleep(POLL_APPLIED)

    return False

if __name__ == "__main__":
    sanity()
    time.sleep(DUMMY_SLEEP)
    full_config_example()
    time.sleep(DUMMY_SLEEP)
    message_get()

Try the API

To try out the NVUE REST API, use the NVUE API Lab available on NVIDIA Air. The lab provides a basic example to help you get started. You can also try out the other examples in this document.

Resources

For information about using the NVUE REST API, refer to the NVUE API Swagger documentation. To download the OpenAPI specification, use the Download Spec option in the NVUE API browser tool.

Considerations

  • Unlike the NVUE CLI, the NVUE API does not support configuring a plain text password for a user account; you must configure a hashed password for a user account with the NVUE API.

  • If you need to make multiple updates on the switch, NVIDIA recommends that you use a root patch, which can make configuration changes with fewer round trips to the switch. Running many targeted NVUE PATCH requests to set or unset objects requires many round trips to the switch to set up the HTTP connection, transfer payloads and responses, manage network utilization, and so on.

Send an Action

1. Run the nv action disconnect

$ curl -u '<username:password>'  --insecure https://<IP>/nvue_v1/system/aaa/user -H 'Content-Type: application/json' -d '
{"@disconnect": {"state": "start", "parameters": {"user": "monitor"}
}
}'

3

2. Get the action ID from the response (in this example, "3").

3. Check the status:

$ curl -u '<username:password>' --request GET 'https://<IP>/nvue_v1/action/3'
{"detail":"all sessions have been terminated","http_status":200,"issue":[],"state":"action_success","status":"all sessions have been terminated","timeout":60,"type":""}

Last updated: