Devnet Module 1 4
Devnet Module 1 4
Devnet Module 1 4
Python Programming
• Python is an easy to learn programming language.
• Few factors that make Python a great tool for learning basic coding are:
• It is easy to learn - the time needed to learn Python is shorter than for many other languages.
• It is easy to use for writing new software – it is possible to write code faster when using Python.
• It is easy to obtain, install and deploy - Python is free, open and multiplatform.
• Python provides a solid foundation and allows to learn other programming languages (for example, C++, Java, or C)
much easier and faster.
Module 2
What is DevNet?
DevNet is a fully-integrated developer program comprising a website, an interactive developer community, coordinated
developer tools, integrated discussion forums, and sandboxes. It consists of the following features:
• Learning Labs - Self-paced tutorials that covers topics from basic coding to using REST APIs with various technologies
• Sandboxes - Production-like development and testing environments for a host of technologies
• Code Exchange - A repository of sample code written by other developers
• Developer support - Support for developer related issues through tickets, live chats, and forums
• Developer documentation - A central location for all of the product developer API documentation
DevNet provides developers a starting point for all Cisco APIs, including API documentation, education, and developer
support.
To get an overview of DevNet, visit the DevNet Home page at developer.cisco.com
The site offers the following:
• Start Now
• Learning Tracks
• Video Course
• Sandbox
• Code Exchange
• Ecosystem Exchange
Introduction
• The software development process is also known as the software development life cycle (SDLC).
• SDLC is more than just coding and also includes gathering requirements, creating a proof of concept, testing, and fixing
bugs.
Implementation
• The implementation phase is also called the coding or development phase.
• As all the components and modules are built during this phase, it is the longest phase of the life cycle.
• At the end of the phase, the functional code that implements all customer's requirements is ready to be tested.
Testing
• In this phase, code is installed in the test environment
• Functional testing, integration testing, performance testing and security testing is performed.
• Testing continues until all the codes are bug free and pass all the tests. At the end of this
phase, a high quality, bugfree, working piece of software is ready for production.
Deployment
• During this phase, the software is installed into the production environment.
• At the end of the phase, the product manager releases the final piece of software to end users.
Maintenance
• During the maintenance phase, the team:
• Provides support to customers
• Fixes bugs found in production
• Works on software improvements
• Gathers new requests from the customer
• At the end, the team works on the next iteration and version of the software
Agile Manifesto, in 2001. According to the Agile Manifesto, the values of Agile are:
• Individuals and interactions over processes and tools
• Working software over comprehensive documentation
• Customer collaboration over contract negotiation
• Responding to change over following a plan
Agile Methods
The popular Agile methods are:
• Agile Scrum: The Scrum focuses on small, self-organizing teams that meet daily for short periods and work in iterative
sprints.
• Lean: The Lean method emphasizes on elimination of wasted effort in planning and execution, and reduction of
programmer cognitive load.
• Extreme Programming (XP): XP deliberately addresses the specific kinds of quality-oflife issues faced by the software
development teams.
• Feature-Driven Development (FDD): FDD prescribes that software development should proceed in terms of an overall
model, broken out, planned, designed, and built featureby-feature.
Backlog
• The backlog consists of all the features of the software, in a prioritized list.
• User stories
• A user story is a simple statement of what a user (or a role) needs, and why. Each user story should be small enough
that a single team can finish it within a single sprint.
Scrum Teams
• Scrum teams are cross-functional, collaborative, self-managed and self-empowered.
• The scrum teams should not be larger than 10 individuals.
• The scrum master should have a daily stand-up meeting with the team at a fixed time everyday for not more than 15
minutes.
• The goal is to go over important tasks that have been finished, are in progress, or are about to be started.
Lean Software Development
• Lean software development is based on Lean Manufacturing principles, which are focused on minimizing waste and
maximizing value to the customer.
• The seven principles of lean, given in the book “Lean Software Development: An Agile Toolkit,” are as follows:
• Eliminate waste
• Amplify learning
• Decide as late as possible
• Deliver as fast as possible
• Empower the team
• Build integrity in
• Optimize the whole
Build Integrity In
• Integrity for the software is when the software addresses the customer’s needs as well as maintains the usefulness for
the customer.
MODULE 3
Software Design Patterns
Introduction
• Software design patterns are best practice solutions for solving common problems in software development.
• Design patterns are language-independent.
• In 1994, Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (known as the Gang of Four (GoF)) published a
book called Design Patterns - Elements of Reusable Object-Oriented Software.
Patterns identified are:
• Program to an interface, not an implementation.
• Favor object composition over class inheritance.
• Software design patterns have already been proven to be successful, so using them can speed up development.
Model-View-Controller (MVC)
• The Model-View-Controller (MVC) design pattern aims to simplify development of applications that depend on graphic
user interfaces.
• MVC abstracts code and responsibility into three different components:
• Model: The model is the application's data structureand is responsible for managing the data, logic and rules
of the application. It gets input from the controller.
• View: The view is the visual representation of the data.
• Controller: The controller is the middleman between the model and view. It takes in user input and
manipulates it to fit the format for the model or view.
• The benefit of MVC is that each component can be built in parallel.
Git
• Git is an open source implementation of a distributed version control system that is currently the latest trend in
software development.
• A Git client must be installed on a client machine. It is available for MacOS, Windows, and Linux/Unix.
• One key difference between Git and other version control systems is that Git stores data as snapshots instead of
differences (the delta between the current file and the previous version).
• If the file does not change, Git uses a reference link to the last snapshot in the system instead of taking a new and
identical snapshot.
What is Branching?
• Branching enables users to work on code independently without affecting the main code in the repository. When a
repository is created, the code is automatically put on a branch called Master.
• Branches can be local or remote, and they can be deleted and have their own history, staging area, and working
directory.
• Git's branch creation is lightweight, and switching between branches is almost instantaneous.
• When a user goes from one branch to another, the code in their working directory and the files in the staging area
change accordingly, but the repository (.git) directories remain unchange
Git Commands
Setting up Git
• To configure Git, use the --global option to set the initial global settings.
Command: git config --global key value
Create a New Git Repository
• Git provides a git init command to create an empty Git repository, or make an existing folder a Git repository.
• When a new or existing project becomes a Git repository, a hidden .git directory is created inthat project folder.
• The .git directory is the repository that holds the metadata such as the compressed files, the commithistory, and the
staging area. In addition, Git also creates the master branch.
Clean Code
• Clean codes are the result of developers trying to make their code easy to read and understand for other developers.
• They follow some common principles related to formatting, organization, intuitiveness of components, purpose and
reusability.
• Clean codes emphasize on standardization, proper organization, modularity, providing inline comments and other
characteristics that help make code self-documenting.
Reasons why developers want to write clean code
• Clean code is easier to understand, more compact, and better-organized.
• Clean code, being modular, tends to be easier to test using automated methods such as unit testing frameworks.
• Clean code, being standardized, is easier to scan and check using automated tools.
• It simply looks nicer.
Return Statements
• The return statement refers to the return value that is specified using the keyword return followed by a variable or
expression. A return statement ends the execution of a function, and returns control to the calling function.
• When a return statement is executed, the value of the return statement is returned and any code below it gets
skipped.
Methods are code blocks associated with an object, typically for object-oriented programming.
Functions are standalone code blocks.
Modules
• Developers typically use modules to divide a large project into smaller parts so that the code can be read and
understood easily.
• They consists of a set of functions and typically contains an interface for other modules to integrate with.
• A module is packaged as a single file and is expected to work independently.
• Below is a module with a set of functions saved in a script called circleClass.py.
Classes
• In most Object-Orient Programming (OOP) languages, and in Python, classes are a means of bundling data and
functionality. Each class declaration defines a new object type.
• Classes may have class variables and object variables.
• New classes may be defined, based on existing, previously defined classes, so that they inherit the properties, data
members, and functionality (methods).
• A class may be instantiated (created) multiple times, and each with its own object-specific data attribute values.
Note: Unlike other OOP languages, in Python, there is no means of creating 'private' class variables or
internal methods. However, by convention, methods and variables with a single preceding underscore
( _ ) are considered private and not to be used or referenced outside the class.
Testing
• Software testing is classically subdivided into two general categories:
• Functional testing seeks to determine whether the software works correctly. Does it behave as intended in a
logical sense, from the lowest levels of detail examined with Unit Testing, to higher levels of complexity explored
in Integration Testing?
• Non-functional testing examines usability, performance, security, resiliency, compliance, localization, and
many other issues. This type of testing finds out if the software is fit for its purpose, provides the intended value,
and minimizes risk.
• Developers capture design requirements as tests and then write software to pass those tests. This is called Test-Driven
Development (TDD).
Unit Testing
• Detailed functional testing of small pieces of code (lines, blocks, functions, classes, and other components in isolation)
is called Unit Testing.
• These test frameworks are software that allows you to make assertions about testable conditions and determine if
these assertions are valid at a point in execution.
Integration Testing
• Integration testing ensures that all the individual units fit together properly to make a complete application.
Test-Driven Development (TDD)
• If you want to test to validate the application design in light of requirements, implies that you should write the testing
code before you write the application code .
• Having expressed the requirements in your testing code, you can then write the application code until it passes the
tests that you have created in the testing code.
• The basic pattern of TDD is a five-step, repeating process:
• Create a new test.
• Run tests to see if any fail for unexpected reasons.
• Write application code to pass the new test.
• Run tests to see if any fail.
• Refactor and improve application code.
Data Formats
• Rest APIs let you exchange information with remote services and equipment.
• The three most popular standard formats for exchanging information with remote APIs are XML, JSON, and YAML.
• Parsing XML, JSON, or YAML is a frequent requirement of interacting with APIs. An oftencountered pattern in REST API
implementations is as follows:
• Authenticate, usually by POSTing a user/password combination and retrieving an expiring token for use in
authenticating subsequent requests.
• Execute a GET request to a given endpoint (authenticating as required) to retrieve the state of a resource,
requesting XML, JSON, or YAML as the output format.
• Modify the returned XML, JSON, or YAML.
• Execute a POST (or PUT) to the same endpoint (again, authenticating as required) to change the state of the
resource, again requesting XML, JSON, or YAML as the output format and interpreting it as needed to determine
if the operation was successful.
XML
• Extensible Markup Language (XML) is a generic methodology for wrapping textual data in symmetrical tags to indicate
semantics.
• It is a derivative of Structured, Generalized Markup Language (SGML), and also the parent of HyperText Markup
Language (HTML). XML filenames typically end in ".xml".
•XML Document Body: Except the first two lines of a XML document, the remainder of the
document is considered as the body.
• User-Defined Tag Names: XML tag names are user-defined. If you are composing XML for
your own application, pick tag names that clearly express the meaning of data elements, their
relationships, and hierarchy.
• Special Character Encoding: Data is conveyed in XML as readable text.
• XML Prologue: The XML prologue is the first line in an XML file.
• Comments in XML: XML files can include comments, using the same commenting convention
used in HTML documents.
• XML Attributes: XML lets you embed attributes within tags to convey additional information.
XML Namespaces:
• Namespaces are defined by the IETF and other internet authorities, organizations, and other entities, and their
schemas are typically hosted as public documents on the web.
• Namespaces are identified by Uniform Resource Names (URIs) to make persistent documents reachable
without the seeker needing to be concerned about their location.
• The code example below shows the use of a namespace, defined as the value of an xmlns attribute, to assert
that the content of an XML remote procedure call should be interpreted according to the legacy NETCONF 1.0
standard.
Interpreting XML
• In the XML Namespaces example, the structure is represented as a list or onedimensional array (called 'instances') of
objects (each identified as an 'instance' by
bracketing tags). Each instance object contains two key-value pairs denoting a unique instance ID and VM server type.
JSON
• JSON, or JavaScript Object Notation, is a data format derived from the way complex object literals are written in
JavaScript.
• JSON filenames typically end in “.json.”
•JSON Basic Data Types: JSON basic data types include numbers, strings, Booleans, or nulls.
• JSON Objects: As in JavaScript, individual objects in JSON comprise of key/value pairs, which may be surrounded by
braces, individually.
• JSON Maps and Lists: In this case, each individual key/value pair does not need its own set of brackets, but the entire
object does. JSON compound objects can be deeply-nested, with complex structure. It can also express JavaScript
ordered arrays (or 'lists') of data or objects.
• No Comments in JSON: Unlike XML and YAML, JSON does not support any kind of standard method for including
unparsed comments in code.
• Whitespace Insignificant: Whitespace in JSON is not significant, and files can be indented using tabs or spaces as
preferred, or not at all.
YAML
• YAML Ain't Markup Language (YAML) is a superset of JSON designed for even easier human readability.
• As a superset of JSON, YAML parsers can generally parse JSON documents (but not viceversa).
• Hence, YAML is better than JSON at certain tasks, including the ability to embed JSON directly (including quotes) in
YAML files.
YAML File Structure: YAML files conventionally open with three dashes ( --- alone on a
line) and end with three dots ( ... likewise).
• YAML Data Types: YAML basic data types include numbers, strings, Booleans, or nulls.
• Basic Objects: In YAML, basic data types are equated to keys.
• YAML Indentation and File Structure: YAML indicates its hierarchy using indentation.
• Maps and Lists: YAML easily represents more complex data types, such as maps
containing multiple key/value pairs and ordered lists.
• Maps are generally expressed over multiple lines, beginning with a label key and a
colon, followed by members, indented on subsequent lines:
•Lists (arrays) are represented with optionally-indented members preceded by a single dash and space:
•Maps and lists can also be represented in a so-called "flow syntax," which looks very much like JavaScript or
Python:
Long Strings: They are represented using a 'folding' syntax, where linebreaks are presumed to be replaced by spaces
when the file is parsed/consumed, or in a non-folding syntax.
Comments: Comments in YAML can be inserted anywhere except in a long string literal, and are preceded by the hash
sign and a space.
More YAML Features: YAML has many more features, most often encountered when using it in the context of specific
languages, like Python, or when converting to JSON or other formats. For example, YAML 1.2 supports schemas and tags,
which can be used to disambiguate interpretation of values.
For example, to force a number to be interpreted as a string, you could use the !!str string,
which is part of the YAML "Failsafe" schema:
Synchronous APIs
• Synchronous APIs respond to a request directly by providing data immediately.
When are APIs synchronous?
• APIs are synchronous when the data for the request is readily available.
Benefits of a synchronous API design
• Synchronous APIs enable the application to receive data immediately. If the API is designed correctly, the application
performance will be better.
Client side processing
• The application that is making the API request must wait for the response before performing any additional code
execution tasks.
Asynchronous APIs
• Asynchronous APIs provide a response (with no data) to signify that the request has been received.
When are APIs asynchronous?
• APIs are asynchronous when the request takes some time for the server to process or if data isn’t readily available.
Benefit of asynchronous API design
• Asynchronous APIs allow the application to continue execution without being blocked till the server processes the
request, thus resulting in better performance.
Client-side processing
• With asynchronous processing, the design of the API on the server side defines the requirement on the client side.
Stateless
• Requests from the client to the server must contain REST client-server model and all the information which the server
needs to make the request.
• The server cannot contain session states.
Cache model:
• Responses from the server must state whether the response is cacheable or non-cacheable.
• If it is cacheable, the client can use the data from the response for later requests.
Uniform interface:
The interface between the client and the server adhere to the four principles:
• Identification of resources
• Manipulation of resources through representations
• Self-descriptive messages
• Hypermedia as the engine of application state.
Layered system:
• The Layered system consists of different hierarchical layers in which each layer provides services only to the layer
above it.
• As a result, it consumes services from the layer below.
Code-on-demand:
• The information returned by a REST service can include executable code (for example, javascript) or links intended to
usefully extend client functionality.
• The constraint is optional because execution of third-party codes introduces potential security risks.
The Uniform Resource Identifier (URI), also referred to as Uniform Resource Locator (URL), identifies which resource the
client wants to manipulate. The components of a URI are:
• Scheme: specifies which HTTP protocol should be used, http or https.
• Authority: consists of two parts, namely, host and port.
• Path: represents the location of the resource, the data or object, to be manipulated on the server.
• Query: provides additional details for scope, filtering, or to clarify a request
HTTP method:
• REST APIs use the standard HTTP methods to communicate to the web services for which action is being requested for
the given resource.
• The suggested mapping of the HTTP Method to the action is as follows:
Header:
• HTTP headers are formatted as name-value pairs that are separated by a colon ( : ), [name]:[value].
Two types of headers:
Request headers - Include additional information that does not relate to the content of the message.
Entity headers - Additional information that describes the content of the body of the message
Body:
• The body of the REST API request contains the data pertaining to the resource that the client wants to manipulate.
• REST API requests that use the HTTP method POST, PUT, and PATCH typically include a body.
• The body is optional depending on the HTTP method.
• If the data is provided in the body, then the data type must be specified in the header using the Content-Type key
HTTP Status
• The HTTP status code help the client determine the reason for the error and can sometimes provide suggestions for
fixing the problem.
• HTTP status codes consists of three digits, where the first digit is the response category and the other two digits are
assigned in numerical order.
• There are five different categories of HTTP status codes:
• 1xx – Informational – for informational purposes, responses do not contain a body
• 2xx – Success – the server received and accepted the request
• 3xx – Redirection – the client has an additional action to take to get the request completed
• 4xx -- Client Error – the request contains an error such as bad syntax or invalid input
• 5xx -- Server Error – unable to fulfill the valid requests.
Header – The header in the response is to provide additional information between the server and the client in the name-
value pair format that is separated by a colon header[name]:[value].There are two types of headers: response headers
and entity headers.
• Response headers – It contains additional information that doesn't relate to the content of the message. The
typical response headers for a REST API request include: Set-Cookie and Cache-Control
• Entity headers – They are additional information that describes the content of the body of
the message. One common entity header specifies the type of data being returned: Content-Type
Response Pagination
• Response Pagination enables data to be broken into chunks.
• Most APIs that implement pagination use the query parameter to specify which page to return in the response.
Compressed response data
• Compressed data reduces large amount of data that cannot be paginated
• To request a data compression, the request must add the Accept-Encoding field to the request header. The accepted
values are:
• gzip
• compress
• deflate
• br
• identity
Authentication mechanisms
The common types of authentication mechanisms include:
• Basic authentication: It transmits credentials as username/password pairs separated with a colon (:) and encoded
using Base64.
• Bearer authentication: It uses a bearer token, which is a string generated by an authentication server such as an
Identity Service (IdS).
• API Key: It is a unique alphanumeric string generated by the server and assigned to a user. The two types of API keys
are public and private.
Authorization Mechanisms
• Open Authorization (Oauth) combines authentication with authorization.
• Oauth was developed as a solution to insecure authentication mechanisms.
• Oauth has increased security as compared to other options.
• There are two versions of Oauth - OAuth 1.0 and OAuth 2.0, where OAuth 2.0 is not backwards compatible.
• OAuth 2.0 authorization framework enables a third-party application to obtain limited access to an HTTP service.
• OAuth allows the user to provide credentials directly to the authorization server [Identity Provider (IdP) or an Identity
Service (IdS)], to obtain an access token to share with the application.
• The process of obtaining the token is called a flow.
What is a Webhook?
• A Webhook is an HTTP callback, or an HTTP POST, to a specified URL that notifies the application when a particular
activity or event is occurred in the resources.
• With webhooks, applications are more efficient as polling mechanisms are not required.
• Webhooks are also known as reverse APIs, because applications subscribe to a webhook server by registering with the
webhook provider.
• Multiple applications can subscribe to a single webhook server.
Examples:
• The Cisco DNA Center platform provides webhooks that enable third-party applications to receive network data when
specified events occur.
• You can create a webhook to have Cisco Webex Teams notify you of new messages posted in a particular room
Consuming a Webhook
• In order to receive a notification from a webhook provider, the application must meet certain requirements:
• The application must be running at all times to receive HTTP POST requests.
• The application must register a URI on the webhook provider.
• Also, the application must handle the incoming notifications from the webhook server.
• Use free online tools to ensure the application is receiving notifications from a webhook.
401 – Unauthorized:
• This error message means the server could not authenticate the request.
• Check your credentials, including username, password, API key, token, request URI
403 – Forbidden
• The server recognizes the authentication credentials, but the client is not authorized to
perform the request.
409 - The request could not be completed due to a conflict with the current state of the
target resource.
• For example, an edit conflict where a resource is being edited by multiple users would cause a 409 error.
• Retrying the request later might succeed, as long as the conflict is resolved by the server