REST – Automation

By | 01/01/2021

Web browsers use REST to get and post information to web servers or other systems that use HTTP. The same HTTP request methods and response codes are used.

Figure 12-4 shows a create, retrieve, update, and delete (CRUD) example with a client using HTTP POST, GET, PUT, and DELETE calls along with the response codes coming back from the server.

Figure 12-4 Create, Retrieve, Update, and Delete (CRUD)

Table 12-2 lists some common HTTP response codes.

Table 12-2 Common HTTP Response Codes

Response CodeDescription
Success Messages (2xxx)
200Request succeeded
201The request has been fulfilled; new resource created
204The server fulfilled the request but does not return a body
Client Errors (4xx)
400Bad request; malformed syntax
401Unauthorized
403Server understood request but refuses to fulfill it
Server Errors (5xx)
500Internal server error
501Not implemented

YANG, NETCONF, and RESTCONF Explored

YANG is intertwined with NETCONF and RESTCONF, as they are all protocols used to manage configuration and state data.

Table 12-3 lists the Cisco-supported products for YANG, NETCONF, and RESTCONF.

Table 12-3 Cisco-Supported Products for YANG, NETCONF, and RESTCONF

Cisco-Supported ProductsYANG, NETCONF, and/or RESTCONF
Tail-f Network Control SystemNETCONF/YANG
Tail-f Confd AgentNETCONF/YANG
Open SDN Controller/OpenDaylightNETCONF/YANG/RESTCONF
IOS XRNETCONF/YANG
NX-OSNETCONF
IOS XENETCONF

YANG Concepts

Yet Another Next Generation (YANG) is an IETF standard (RFC 6020) data modeling language used to describe the data for network configuration protocols such as NETCONF and RESTCONF. YANG is extensible, enabling the addition of new content to existing data models and new statements to the YANG language. YANG also has a limited scope: It is intended to describe network concepts in a tree structure along with data and types. YANG is intended to be very readable compared to other schema languages.

YANG data models can be displayed and represented in a variety of formats, including the following:

  • YANG language
  • Clear text
  • XML
  • JSON
  • HTML/JavaScript

Figure 12-5 illustrates the NETCONF/YANG stack.

Figure 12-5 NETCONF/YANG Stack

A YANG module is a self-contained top-level hierarchy of nodes. A YANG module can also use submodules. It uses linkage statements such as import and include. Within a module, containers are used to group related nodes. Within a container, lists are used to identify nodes that are stored in a sequence. Inside lists, each individual attribute is referred to as a leaf, and attributes are used for things like names or descriptions. Each leaf also needs to have an associated type, such as Boolean or string.

Table 12-4 lists the common attributes for leaf values.

Table 12-4 Leaf Attributes

AttributeDescription
configSpecifies whether this leaf is a configurable value (“true”) or an operational value (“false”) and is inherited from the parent container if not specified
defaultSpecifies the default value for this leaf and implies that the leaf is optional
mandatorySpecifies whether the leaf is mandatory (“true”) or optional (“false”)
mustSpecifies the XPath constraint that will be enforced for this leaf
typeSpecifies the data type (and range) of this leaf
whenIndicates a conditional leaf, which is present only if the XPath expression is true
descriptionProvides a human-readable definition and help text for the leaf
referenceProvides a human-readable reference to some other element or spec
unitsProvides a human-readable unit specification (for example, Hz, Mbps, °F)
statusIndicates whether this leaf is current, deprecated, or obsolete

When versioning YANG modules, consider the following:

  • Add a revision statement at the top.
  • Update the organization, contact, and other information.
  • Do not rename a module or namespaces.
  • Do not remove obsolete definitions.
  • Do not reorder data definitions.

Leave a Reply

Your email address will not be published. Required fields are marked *