Chapter 29

Programmability

No, Cisco does not expect you to leave the CCNA experience a well-versed programmer. Cisco does expect you, however, to have a good understanding of key principles related to programmability. This chapter covers these key principles.

This chapter covers the following essential terms and components:

  • REST

  • API

  • CRUD

  • HTTP verbs

  • Data encoding

  • Puppet

  • Chef

  • Ansible

  • JSON

Topic: Describe characteristics of REST-based APIs (CRUD, HTTP verbs, and data encoding)

CramSaver

If you can correctly answer these CramSaver questions, save time by skimming the ExamAlerts in this section and then completing the CramQuiz at the end of this section and the Review Questions at the end of the chapter. If you are in doubt at all, read everything in this chapter!

1. What does each letter in CRUD stand for?

_________

2. What HTTP request method can perform the U in CRUD?

_________

Answers

1. Create, Read, Update, Delete

2. PUT

Application programming interfaces (APIs) permit software to communicate with other software components, as well as with users and engineers in charge of maintaining the software. Today, in our cloud-dominated world, APIs that follow a style called representational state transfer (REST) are most popular. As their name implies, RESTful APIs use REST conventions that follow a particular set of software rules.

RESTful APIs often use HTTP, and this makes them a great choice for the networking and cloud technologies that often leverage HTTP. Specifically, REST and HTTP share three very important aspects that enable them to work well together:

  • Both follow a client/server model

  • Both follow a stateless model

  • Both indicate whether an object is cacheable or not

Another important reason that REST and HTTP work so well together is that HTTP uses verbs in its operations (request methods) that nicely mirror the CRUD operations performed with APIs in software. CRUD stands for the following actions:

  • Create

  • Read

  • Update

  • Delete

Just look at how nicely the verbs used by HTTP for its actions mirror these CRUD requirements:

  • Create: POST

  • Read: GET

  • Update: PUT

  • Delete: DELETE

In addition to using HTTP verbs, you use URIs to indicate what resource to act on. For example, http://api.ciscospark.com/v1/rooms creates an HTTP GET request for the /v1/rooms resource at the server api.ciscospark.com.

Here is an example of a REST API request that uses HTTP and AWS S3 in the cloud:

http://s3-eu-west-1.amazonaws.com/ajs/me.jpg

This example performs the HTTP GET against an S3 storage bucket named ajs and asks for the resource (JPG) named me.jpg. Notice how incredibly simple HTTP and the REST API make this access.

Note that REST defines the standard set of operations that a RESTful API has to offer as access methods. The payload of the API calls is defined per service and/or (in the case of networking devices) per device. For example, the RESTful API of IOS XE uses JSON to encode its payload (as documented at https://www.cisco.com/c/en/us/td/docs/routers/csr1000/software/restapi/restapi/RESTAPIglobal.html).

CramQuiz

1. What does the URI indicate in a REST API call?

Image A. The latency acceptable for the response

Image B. The security protocol for authentication

Image C. The resource being acted upon

Image D. The protocol variant used

2. Which statement is not a valid similarity between REST APIs and HTTP?

Image A. Both indicate whether a resource can be cached

Image B. Both are stateless approaches

Image C. Both are client/server models

Image D. Both feature connectionless communications

CramQuiz Answers

1. C is correct. You use the URI information to indicate what resource the API call impacts.

2. D is correct. HTTP relies on TCP, which is a connection-oriented protocol.

Topic: Recognize the capabilities of the configuration management mechanisms Puppet, Chef, and Ansible

CramSaver

1. Name three popular configuration tools that help automate modern server infrastructures.

_________

_________

_________

2. Of the tools that you just listed, which tool does not ever feature the use of agent software on the managed node?

_________

Answers

1. Puppet, Chef, and Ansible

2. Ansible

The creation of more virtualization technologies and the cloud fostered the development of new technology in the area of configuration control and management. Three pioneering companies (and software packages) rose to the top in this area: Puppet, Chef, and Ansible.

Ansible, which is installed on a Linux system, can configure and manage devices without ever requiring that an “agent” software package be installed on the systems it is controlling. This is a great advantage because installing agent software on all the systems you want to control can be a huge undertaking in and of itself.

How does the Ansible system control a node if it does not install software on that system? It uses an SSH connection to pass the required instructions.

Ansible is run using simple components (such as text files) that control its behavior and abilities. These are the main components:

  • Inventory: A list of nodes that Ansible is set to manage

  • Modules: The units of code that Ansible executes

  • Tasks: The units of action in Ansible

  • Playbooks: Ordered lists of tasks that permit the future execution of the sequence

Although the similar tools Puppet and Chef were created primarily through the use of the Ruby programming language, Ansible relies heavily on Python. The increase in popularity in Python is another strong selling point for those considering the various automation tools.

Puppet takes a different approach to the configuration of the devices it manages. It has a more defined client/server relationship. The client is agent software installed on the node to be managed, and the Puppet server is installed on a UNIX or Windows system.

Puppet uses a custom declarative language to define the required configuration of the managed node. This configuration is either applied directly to the managed device or compiled into a catalog and distributed to the target system using a REST API.

Just like Ansible, Puppet is celebrated for its ease of use and the fact that it shields network administrators from the requirement of knowing how to program systems. The Ansible crowd, for what it is worth, love to point out that the Puppet approach requires agent software to be installed on the nodes that are to be managed. Some Nexus and IOS-XR platforms support the installation of a Puppet agent. IOS and IOS XE platforms do not support installation of the agent, so a workaround is used for managing IOS devices through Puppet: A proxy module acting as a Puppet agent is run on a Linux server that essentially translates the catalog into IOS CLI commands. The proxy module then uses SSH to get to the various IOS devices and execute the necessary commands. This proxy module makes Puppet for IOS “agentless.”

Chef is very similar to Puppet. This configuration management tool is written in Ruby and manages nodes using configuration manifests called recipes. Recipes can be grouped together in cookbooks for easier management and for automation of more complex tasks for the managed nodes.

Just like Puppet, Chef can run in client/server mode. Interestingly, the software can also run in a standalone configuration called Chef Solo. In client/server mode, the Chef client sends various attributes about the node to the Chef server. The server uses Elasticsearch to index these attributes and provides an API for clients to query this information. Chef recipes can query these attributes and use the resulting data to help configure the node.

Just like the other tools covered here, Chef was originally used to manage Linux system exclusively, but later versions support Microsoft Windows as well.

CramQuiz

1. What language is instrumental for both Puppet and Chef?

Image A. Ruby

Image B. C#

Image C. Java

Image D. Python

2. What is the term used with Ansible for the text file that lists the nodes that Ansible can manage?

Image A. Runbook

Image B. Playbook

Image C. Recipe

Image D. Inventory

CramQuiz Answers

1. A is correct. Both Puppet and Chef rely heavily on Ruby. Python is the key language used in the development of Ansible.

2. D is correct. Ansible uses an inventory file to list the nodes that are managed by the software.

Topic: Interpret JSON-encoded data

CramSaver

1. JSON is very similar to what other encoded data format?

_________

2. What symbol does JSON code begin and end with?

_________

Answers

1. XML

2. A curly brace

JavaScript Object Notation (JSON) is a very common data format today that has many potential uses. From feeding commands to Cisco devices to creating entire infrastructures in the cloud, JSON is versatile and very easy for humans to read and work with.

Note

JSON is often compared to XML. This is a very valid comparison. However, JSON script is much, much easier to read than XML.

JSON does have many potential uses. Here are just some examples:

  • It is used with many Web technologies like public cloud

  • It can be used to provide the details needed to construct a cloud infrastructure through code

  • It can provide the needed details to configure data for local projects

  • It can be used to power automation software

  • It can be used with Ansible for the configuration of devices

As you examine this list, remember that JSON is not the executable code that makes the magic happen. It is just a standardized data format for feeding the required data into an application.

Note

JSON is often the data format used when extracting data from an application.

Examine this JSON and make some observations about it:

{
  "response": [
    {
      "id": "d4b33d28-04dd-4733-a6de-8877ec26c196",
      "tag": "campus",
      "networkDeviceId": "e5f93514-3ae5-4109-8b52-b9fa876e1eae",
      "attributeInfo": {}
    },
    {
      "id": "d4b33d28-04dd-4733-a6de-8877ec26c196",
      "tag": "campus",
      "networkDeviceId": "da733ffb-e34b-4733-bd85-b615fb7e61f3",
      "attributeInfo": {}
    },
    {
      "id": "d4b33d28-04dd-4733-a6de-8877ec26c196",
      "tag": "campus",
      "networkDeviceId": "f8c3fc68-cd26-4576-bcec-51f9b578f71e",
      "attributeInfo": {}
    }
  ],
  "version": "0.0"
}

Notice that the JSON code begins and ends with the curly braces. This denotes a JSON object. Notice that the JSON also consists of simple key/value pairs (for example, the key version and the value 0.0). Notice that values can be objects, strings, numbers, Boolean values, and more.

Keep in mind that indentation in JSON is not required, but it is strongly encouraged since it makes the data much more human readable.

I think it is worth repeating one more time for emphasis: JSON does not contain executable code. It is a powerful format for data that we tend to move into and out of applications.

CramQuiz

1. What does a JSON object consist of?

Image A. Arrays

Image B. Subobjects

Image C. If, Then statements

Image D. Key/value pairs

2. Which statement about JSON is false?

Image A. JSON does not require the use of indenting.

Image B. JSON consists of groupings of executable code.

Image C. JSON is often used to provide the required data for cloud infrastructure construction.

Image D. JSON is considered more human readable than XML.

CramQuiz Answers

1. D is correct. A JSON object consists of key/value pairs.

2. B is correct. JSON does not consist of executable code.

Review Questions

1. What type of APIs are often used with networking and cloud technologies?

Image A. JSON-RPC

Image B. XML-RPC

Image C. REST

Image D. SOAP

2. Which is not a term in the developer CRUD actions?

Image A. Request

Image B. Create

Image C. Update

Image D. Delete

3. What technology is used to permit Ansible to connect to managed nodes for configuration purposes?

Image A. SSH

Image B. TFTP

Image C. IPSec

Image D. HTTP

4. What is the name for an ordered list of tasks in Ansible?

Image A. Cookbook

Image B. Playbook

Image C. Story

Image D. Task list

5. What character is used to separate a key from its value in JSON?

Image A. :

Image B. ,

Image C. [

Image D. {

Answers to Review Questions

1. C is correct. REST APIs work very well with HTTP and therefore are often used with networking and cloud technologies.

2. A is correct. The R in CRUD stands for Read.

3. A is correct. Ansible uses SSH to connect to and configure managed nodes in a secure fashion.

4. B is correct. Ansible uses playbooks in order to run many automation tasks together.

5. A is correct. A colon (:) separates the key from the value in a key/value pair in the JSON format.

Additional Resources

What Really Is an API?

https://www.ajsnetworking.com/what-really-is-an-api/

JavaScript Object Notation (JSON) Format

https://youtu.be/sJYvLp-0I1o

JSON Tutorial

https://www.w3resource.com/JSON/introduction.php

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.27.202