0% found this document useful (0 votes)
267 views2 pages

2.3.3.1 Lab - Create A Network Device Inventory in Python

This document provides instructions for modifying an existing Python script to obtain and display the inventory of network devices from the APIC-EM API instead of the previous host inventory. The key steps are to investigate the network device inventory API endpoint and response JSON, identify the needed changes to variables and keys, modify and save the print_hosts.py script as print_devices.py, run and test the new code, and refactor it into a print_devices function in the my_apic_em_functions.py file. Reusing code in this way reduces development time and effort while also presenting challenges in understanding the original code to modify it correctly.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
267 views2 pages

2.3.3.1 Lab - Create A Network Device Inventory in Python

This document provides instructions for modifying an existing Python script to obtain and display the inventory of network devices from the APIC-EM API instead of the previous host inventory. The key steps are to investigate the network device inventory API endpoint and response JSON, identify the needed changes to variables and keys, modify and save the print_hosts.py script as print_devices.py, run and test the new code, and refactor it into a print_devices function in the my_apic_em_functions.py file. Reusing code in this way reduces development time and effort while also presenting challenges in understanding the original code to modify it correctly.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 2

Lab – Create a Network Device Inventory in Python

Objectives
Part 1: Investigate the Network Device Inventory API
Part 2: Modify the Code

Background / Scenario
An important skill for software developers is the ability to obtain, modify, and reuse code that was previously
created. Coder communities like GitHub and Stack Overflow, among others, provide support for developers
and many people freely share code there. Obtaining and modifying code for a specific need is an import skill
for adding efficiency to the software development process.
In this lab, you will modify the code that was created to obtain the inventory of network hosts and repurpose it
to obtain an inventory of network devices.

Required Resources
 Access to the APIC-EM in the DevNet sandbox at https://{YOUR-APICEM}.cisco.com
 Postman
 Python 3 with IDLE
 Python requests module
 Python tabulate module
 The functions file that you have created
 The print_hosts.py file that you created or the print_hosts_sol.py file
 Access to the Internet

Part 1: Investigate the Network Device Inventory API


In this part of the lab, you will investigate the documentation for the APIC-EM’s network device inventory to
determine the necessary information you need to create your program.

Step 1: Determine the endpoint URL.


a. Login to the APIC-EM sandbox using the URL and credentials supplied by your instructor and click API to
access the Swagger API documentation:
b. Under Available APIs, click Inventory > network-device > GET /network-device.
c. Click Try it out! What is the URL that you will use in the request.get() method for this endpoint?
https://sandboxapicem.cisco.com/api/v1/network-device

Step 2: Investigate the response JSON.


a. Copy the JSON in the Response Body and paste it into https://codebeautify.org/jsonviewer.

 Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 1 of 2 www.netacad.com
Lab - Create a Network Device Inventory in Python

b. Compare GET /network-device JSON to the GET /host JSON you viewed in the previous lab. How
is the structure of the network device inventory JSON similar to the structure of the host inventory
JSON?
La respuestas Get/network-divace cuenta con muchas mas claves 34 en total, minetras que los Get /host
Son dispositivos conectados a una red y utilizan estos servicios por lo cual las claves van a disminuir
c. How many network devices are included in the inventory?
Existen dos objetos y 6 respuestas
d. You want to access and display information for the network devices similar to the information that
are displayed for the hosts. However, the keys do not use the names hostType and hostIP. What
are the names of similar keys for the network devices?

Cisco 4451 Series Integrated Services Router


Look for other cosmetic impacts to the code. For example, there are status and error messages that are
displayed to the user. They may require modification.

Part 2: Modify the Code.


a. Open your print_hosts.py file and save it as print_devices.py.
b. Locate the places that require changes and make the edits.
c. Save and run your code. Investigate errors. If necessary, compare your file to the print_devices_sol.py
file to discover the source of the errors.
d. Create a function from your code by copying the code into your my_apic_em_functions.py file and
transforming it into a function called print_devices().
e. Run your function file and test each function to make sure your code is error free.

Reflection
1. What are the advantages of modifying and reusing code in this way?
Menos lineas de codigo, es mucho mas comprensible y se aprovecha el trabajo anterior, se reduce el tiempo
de ejecución
2. What are the challenges?
Comprender el codigo que se va a reutilizar para reducer el tiempo y que no se convierta en un problema
3. What can developers do to make the process easier?
La reutilizacion de Código es una tecnica que se la emplea para reducer el tiempo en el Desarrollo del
Proyecto, permitiendonos reutilizar grandes componentes de software.

 Cisco and/or its affiliates. All rights reserved. Cisco Confidential Page 2 of 2 www.netacad.com

You might also like