Skip to content

Commit 736aaad

Browse files
committed
formatting fixes
1 parent 759c75c commit 736aaad

File tree

12 files changed

+64
-77
lines changed

12 files changed

+64
-77
lines changed

labs/coding-101-rest-basics-ga/5.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
There are many HTTP clients that can help you quickly test web services. These types of tools provide an easy way to construct and send requests to REST APIs, and to view the responses.
44

5-
* Postman - <http://www.getpostman.com/>
6-
* Firefox RestClient - <https://addons.mozilla.org/en-US/firefox/addon/restclient/>
7-
* Command Line using curl - <http://curl.haxx.se/docs/httpscripting.html#POST>
5+
* Postman - [http://www.getpostman.com/](http://www.getpostman.com/)
6+
* Firefox RestClient - [https://addons.mozilla.org/en-US/firefox/addon/restclient/](https://addons.mozilla.org/en-US/firefox/addon/restclient/)
7+
* Command Line using curl - [http://curl.haxx.se/docs/httpscripting.html#POST](http://curl.haxx.se/docs/httpscripting.html#POST)
88
* SOAPUI
99
* Many IDEs have consoles for testing REST Services built in
1010

@@ -46,7 +46,7 @@ You may need to accept the SSL certificate before calling the APIs in Postman.
4646
3. Click **Send**.
4747
4. Postman will send the request to the server, and the display the response.
4848
* You can see the **Response Code** that is returned displayed here as '200' and is shown in the **Status** field.
49-
* You can see the **JSON** response data that contains a 'serviceTicket' attribute. We've highlighted the value of the service ticket. The actual value returned will most likely be different. **Copy and paste this value into a text file to use for the next steps!**<br/><br/>
49+
* You can see the **JSON** response data that contains a **serviceTicket** attribute. We've highlighted the value of the service ticket. The actual value returned will most likely be different. **Copy and paste this value into a text file to use for the next steps!**<br/><br/>
5050
![](/posts/files/coding-101-rest-basics-ga/assets/images/postman3.png "Response")
5151

5252
#### Congrats! You just made your first REST API call! ####

labs/coding-102-rest-python-ga/1.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ Completion Time: 35 minutes
3939
* **If you are working on a DevNet Learning Lab PC at a DevNet event**,
4040
* Open the Git Command window by clicking on the *Git CMD* icon on the Task Bar or click on the Start button, then in the Run bar type: **git cmd** and press the **Enter** key.
4141
* **If you are working from your own workstation**, on your desktop open a command terminal.
42-
* Go to the root directory by typing: `cd \`
43-
* Create a directory called 'C:\DevNetCode\yourname' by typing: `mkdir DevNetCode\<your-name>`
44-
* For example: `mkdir DevNetCode\brTiller`
45-
* Go to the new directory by typing: `cd \DevNetCode\<your-name>`
46-
* For example: `cd \DevNetCode\brTiller`
42+
![](/posts/files/coding-102-rest-python-ga/assets/images/create_directory.png)<br/><br/>
4743
* Clone the coding skills sample code from GitHub. Enter the command below.
4844
```
4945
git clone https://github.com/CiscoDevNet/coding-skills-sample-code

labs/coding-102-rest-python-ga/3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ We are going to build on the previous simple example, and learn how to parse and
55
These files are located on your workstation in the directory: /DevNetCode/&lt;your-name&gt;/coding-skills-sample-code/coding102-REST-python-ga/
66
* **create-ticket.py** - Example to create a service ticket. Used in Step 2.
77
* **get-network-hosts.py** – First application to parse the service ticket response and show list of hosts by doing a pretty print of the JSON data
8-
* **get-network-devices.py** – Retrieves network device list and parses JSON to display networkDeviceId values
8+
* **get-network-devices.py** – Retrieves network device list and parses JSON to display **networkDeviceId** values
99
* **build-topology.py** – Shows how to retrieve devices and interfaces, and to build and display spreadsheet-like text topology
1010
* **build-topology-web-server.py** – Shows how to retrieve devices and interfaces, and to build a graphical topology
1111

labs/coding-102-rest-python-ga/4.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ getNetworkDevices(theTicket)
6767

6868
Let's look at what the code is doing. We'll focus on the key code changes.
6969

70-
* *def getTicket():*
71-
* We define the function named getTicket. This function creates and returns the service ticket.
72-
* *def getNetworkDevices(ticket):*
73-
* We define the function named getNetworkDevices which uses the parameter ticket. The ticket parameter should contain the service ticket data. This function returns the network devices.
74-
* *url = "https://" + controller + "/api/v1/network-device"*
70+
* **def getTicket():**
71+
* We define the function named `getTicket()`. This function creates and returns the service ticket.
72+
* **def getNetworkDevices(ticket):**
73+
* We define the function named `getNetworkDevices` which uses the parameter ticket. The ticket parameter should contain the service ticket data. This function returns the network devices.
74+
* **url = "https://" + controller + "/api/v1/network-device"**
7575
* Creates the URL to get the network devices by concatenating the strings.
76-
* *header = {"content-type": "application/json", "X-Auth-Token":ticket}*
76+
* **header = {"content-type": "application/json", "X-Auth-Token":ticket}**
7777
* HTTP header with the ticket data designated as "X-Auth-Token" for API authentication.
78-
* *for i in r_json["response"]: print(i["id"] + " " + i["series"])*
78+
* **for i in r_json["response"]: print(i["id"] + " " + i["series"])**
7979
* Parse the network data JSON data and print out the device ID and the device series name.
80-
* *theTicket=getTicket()*
81-
* Call the getTicket() function and assign the service ticket data to the variable 'theTicket'.
82-
* *getNetworkDevices(theTicket)*
83-
* Call the getNetworkDevices(theTicket) function and pass in the service ticket data in the 'theTicket' variable.
80+
* **theTicket=getTicket()**
81+
* Call the `getTicket()` function and assign the service ticket data to the variable `theTicket`.
82+
* **getNetworkDevices(theTicket)**
83+
* Call the `getNetworkDevices(theTicket)` function and pass in the service ticket data in the `theTicket` variable.
8484

8585
To run this code sample:
8686
1. Go to directory **coding102-REST-python-ga**. In the terminal type:
@@ -100,8 +100,8 @@ To run this code sample:
100100
![](/posts/files/coding-102-rest-python-ga/assets/images/get-devices.png)
101101

102102
## Things to Try
103-
* Edit the function getNetworkDevices to display the management IP address and name of the location for each network device.
104-
* Write a new function called getHosts(theTicket) to get and display the network hosts. See step 3 for the URL to use for retrieving host data.
103+
* Edit the function `getNetworkDevices` to display the management IP address and name of the location for each network device.
104+
* Write a new function called `getHosts(theTicket)` to get and display the network hosts. See step 3 for the URL to use for retrieving host data.
105105

106106

107107
In the next section, we will learn how to build a network topology.

labs/coding-102-rest-python-ga/5.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ getTopology(theTicket)
113113
```
114114

115115
Let's look at what the code is doing. We'll focus on the key code changes.
116-
* *def getTopology(theTicket):*
117-
* We define the function named getTopology. This function reads in the topology data. It parses the nodes which are devices on the network and displays some information about them. It also parses the link data which are interfaces that connect the nodes and displays information about how they connect the devices and their status. The passed in parameter 'theTicket' is used for authorization purposes.
118-
* *for n in r_json["response"]["nodes"]:*
116+
* **def getTopology(theTicket):**
117+
* We define the function named `getTopology`. This function reads in the topology data. It parses the nodes which are devices on the network and displays some information about them. It also parses the link data which are interfaces that connect the nodes and displays information about how they connect the devices and their status. The passed in parameter `theTicket` is used for authorization purposes.
118+
* **for n in r_json["response"]["nodes"]:**
119119
* We read the dictionary data for each node into n from which we will parse the data.
120-
* *if "platformId" in n:*
121-
* Checking that the node data in n contains a 'platformId' key. Some records don't have this key so different field data would need to be accessed.
122-
* *if "startPortName" in i:*
123-
* Checking that the interface data in i contains a 'startPortName' key. Some records don't have this key so different field data would need to be accessed.
120+
* **if "platformId" in n:**
121+
* Checking that the node data in n contains a `platformId` key. Some records don't have this key so different field data would need to be accessed.
122+
* **if "startPortName" in i:**
123+
* Checking that the interface data in i contains a `startPortName` key. Some records don't have this key so different field data would need to be accessed.
124124

125125

126126
To run this code sample:
@@ -142,9 +142,9 @@ To run this code sample:
142142

143143

144144
## Things to Try
145-
* After running the script review the node data printed. Modify the source code by replacing the label key with another key such as role or nodeType. Run the script again and determine the change of the data displayed.
145+
* After running the script review the node data printed. Modify the source code by replacing the label key with another key such as `role` or `nodeType`. Run the script again and determine the change of the data displayed.
146146
* Review the printed topology data and determine how many host devices exist and to which devices they connect.
147-
* Starting from the cloud node, use the topology data provided to draw a picture of the first three layers of the topology. Hint: look for matching devices specified by the Label attribute. For example, the cloud node connects to four devices with one device being Branch-Router1. Determine which devices Branch-Router1 connects to by finding it in the Label field of the topology data. Then do the same steps for the other three devices.
147+
* Starting from the cloud node, use the topology data provided to draw a picture of the first three layers of the topology. Hint: look for matching devices specified by the Label attribute. For example, the cloud node connects to four devices with one device being `Branch-Router1`. Determine which devices `Branch-Router1` connects to by finding it in the Label field of the topology data. Then do the same steps for the other three devices.
148148

149149

150150
In the next section, we will learn how to use the NeXt UI toolkit and Flask to build a network topology and display it graphically

labs/coding-102-rest-python-ga/6.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,23 @@ if __name__ == "__main__":
100100
```
101101

102102
Let's look at what the code is doing. We'll focus on the key code changes.
103-
* *from flask import Flask*
103+
* **from flask import Flask**
104104
* From the flask python module imports the Flask object
105-
* *from flask import render_template, jsonify*
106-
* From the flask python module imports a couple of functions which are render_template and jsonify.
107-
* *app = Flask(__name__)*
105+
* **from flask import render_template, jsonify**
106+
* From the flask python module imports a couple of functions which are `render_template` and `jsonify`.
107+
* **app = Flask(__name__)**
108108
* Instanitates the Flask web application.
109-
* *@app.route("/")*
110-
* Tags the function below it "def index()" and specifies that it is called as the default web page for the Flask web application variable 'app'.
111-
* *def index():*
112-
* The index function that calls the Flask function render_template that loads the topology.html web page.
113-
* *@app.route("/api/topology")*
109+
* **@app.route("/")**
110+
* Tags the function below it "def index()" and specifies that it is called as the default web page for the Flask web application variable `app`.
111+
* **def index():**
112+
* The index function that calls the Flask function `render_template` that loads the `topology.html` web page.
113+
* **@app.route("/api/topology")**
114114
* Tags the function below it "def topology()" and is called by NeXt UI. Identifies as web page for the Flask web application variable 'app'
115-
* *def topology():*
115+
* **def topology():**
116116
* Returns the network topology data in JSON format.
117-
* *if __name__ == "__main__":*
118-
* Optional code that specifies that if this module is run, rather than just importing it and calling it's functions, that below this point is where the script should begin running. Python typically knows already has this information, but this prevents any ambiguity.
119-
* *app.run()*
117+
* **if __name__ == "__main__":**
118+
* Optional code that specifies that if this module is run, rather than just importing it and calling its functions, that below this point is where the script should begin running. Python typically knows already has this information, but this prevents any ambiguity.
119+
* **app.run()**
120120
* Starts the Flask web application.
121121

122122

Loading

labs/coding-201-parsing-xml/1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ cd ~/Desktop
6262
```
6363
python get-ap-xml.py
6464
```
65-
Note: You may need to run the python command as <b>python3.4 get-ap-xml.py</b> on OS X to force using the 3.4 version of Python. If you get any errors, verify the version of python being executed and double-check the code.
65+
Note: You may need to run the python command as **python3.4 get-ap-xml.py** on OS X to force using the 3.4 version of Python. If you get any errors, verify the version of python being executed and double-check the code.
6666
<br/>
6767
<br/>
6868
7. When you run the Python script, you should get an screen full of XML data returned to the terminal.
@@ -74,4 +74,4 @@ Note: You may need to run the python command as <b>python3.4 get-ap-xml.py</b> o
7474

7575
----------
7676

77-
By default, CMX will return the data in XML. For this first step, this is what we want. Let's clean up this data parse out something more specific in the next step.
77+
By default, CMX will return the data in XML. For this first step, this is what we want. Let's clean up this data parse out something more specific in the next step.

labs/coding-201-parsing-xml/2.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ It is still a formidable amount of text, but we can now see some of the structur
4141

4242
----------
4343

44-
A key thing to notice is that there is a hierarchical structure to the returned data. Notably, the XML element with the Tag name 'Floor' has sub-objects and those sub-object can have objects themselves. For this exercise, we are interested in the collection of Access Points for this floor and, in particular, the name, Ethernet MAC Address, and IP Address of each Access Point. There is other information returned, but the *name*, *ethMacAddress*, and *ipAddress* attributes of an element with a Tag of *AccessPoint* are what we are interested in.
44+
A key thing to notice is that there is a hierarchical structure to the returned data. Notably, the XML element with the Tag name 'Floor' has sub-objects and those sub-object can have objects themselves. For this exercise, we are interested in the collection of Access Points for this floor and, in particular, the name, Ethernet MAC Address, and IP Address of each Access Point. There is other information returned, but the **name**, **ethMacAddress**, and **ipAddress** attributes of an element with a Tag of **sAccessPoint** are what we are interested in.
4545

46-
Structurally, the XML elements are represented in the following order:
46+
Structurally, the XML elements are represented in the following order:
4747

4848
&lt;Floor&gt;<br/>
4949
&nbsp;&nbsp;&nbsp;&nbsp;&lt;Dimension /&gt;<br/>
@@ -53,7 +53,7 @@ Structurally, the XML elements are represented in the following order:
5353
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ApInterface /&gt;<br/>
5454
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;ApInterface /&gt;<br/>
5555
&nbsp;&nbsp;&nbsp;&nbsp;&lt;/AccessPoint&gt;<br/>
56-
56+
5757

5858
In the above description, the elements tagged as AccessPoint have sub-elements of MapCoordinate and ApInterface. The AccessPoint element itself has XML attributes that can tell us the name of the Access Point and its MAC and IP addresses. A full AccessPoint element from the data can look like this:
5959
```
@@ -64,8 +64,3 @@ Where the Tag is "AccessPoint" and there are 6 Attributes: "apMode", "ethMacAddr
6464
If you are interested in looking over the complete reference of available map information from CMX, review the online documentation at [https://developer.cisco.com/site/cmx-mobility-services/documents/api-reference-manual/index.gsp#maps-api](https://developer.cisco.com/site/cmx-mobility-services/documents/api-reference-manual/index.gsp#maps-api "Online Documentation for CMX Maps API")
6565

6666
Now that we have a better understanding of what the structure looks like, let's parse the data.
67-
68-
69-
70-
71-

labs/coding-201-parsing-xml/4.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## Step 4. Getting XML Elements in Python
1+
## Step 4. Getting XML Elements in Python
22

33
### Retrieving Elements by Tag Name
44

5-
Rather than manually evaluate each child in a series of nodes, Minidom offers functionality to extract a collection of elements by their tag name. We can use the getElementsByTagName() method to return an array of elements.
5+
Rather than manually evaluate each child in a series of nodes, Minidom offers functionality to extract a collection of elements by their tag name. We can use the `getElementsByTagName()` method to return an array of elements.
66

77
1. In **get-ap-xml.py**, strip out what was inserted in Step 3 (everything between the print(xml) and response.close() lines) and insert the following in its place. Again, be careful in maintaining the indentation.
88
```
@@ -38,9 +38,3 @@ When you run the Python script, you should get a very similar output to before w
3838
Using Python and Minidom, we have extracted specific information from CMX using the Element Tag name and were able to output only the data we were looking for from this CMX data.
3939

4040
Let's move to the last step and learn about resources available to further your knowledge of parsing XML with Python.
41-
42-
43-
44-
45-
46-

0 commit comments

Comments
 (0)