You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: labs/coding-101-rest-basics-ga/5.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
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.
* Command Line using curl - [http://curl.haxx.se/docs/httpscripting.html#POST](http://curl.haxx.se/docs/httpscripting.html#POST)
8
8
* SOAPUI
9
9
* Many IDEs have consoles for testing REST Services built in
10
10
@@ -46,7 +46,7 @@ You may need to accept the SSL certificate before calling the APIs in Postman.
46
46
3. Click **Send**.
47
47
4. Postman will send the request to the server, and the display the response.
48
48
* 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/>
Copy file name to clipboardExpand all lines: labs/coding-102-rest-python-ga/1.md
+1-5Lines changed: 1 addition & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,11 +39,7 @@ Completion Time: 35 minutes
39
39
***If you are working on a DevNet Learning Lab PC at a DevNet event**,
40
40
* 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.
41
41
***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>`
Copy file name to clipboardExpand all lines: labs/coding-102-rest-python-ga/4.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,20 +67,20 @@ getNetworkDevices(theTicket)
67
67
68
68
Let's look at what the code is doing. We'll focus on the key code changes.
69
69
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.
* 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.
Copy file name to clipboardExpand all lines: labs/coding-102-rest-python-ga/5.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -113,14 +113,14 @@ getTopology(theTicket)
113
113
```
114
114
115
115
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"]:**
119
119
* 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.
124
124
125
125
126
126
To run this code sample:
@@ -142,9 +142,9 @@ To run this code sample:
142
142
143
143
144
144
## 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.
146
146
* 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.
148
148
149
149
150
150
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
Copy file name to clipboardExpand all lines: labs/coding-102-rest-python-ga/6.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,23 +100,23 @@ if __name__ == "__main__":
100
100
```
101
101
102
102
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**
104
104
* 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__)**
108
108
* 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")**
114
114
* 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():**
116
116
* 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.
Copy file name to clipboardExpand all lines: labs/coding-201-parsing-xml/1.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,7 @@ cd ~/Desktop
62
62
```
63
63
python get-ap-xml.py
64
64
```
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.
66
66
<br/>
67
67
<br/>
68
68
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
74
74
75
75
----------
76
76
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.
Copy file name to clipboardExpand all lines: labs/coding-201-parsing-xml/2.md
+3-8Lines changed: 3 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,9 +41,9 @@ It is still a formidable amount of text, but we can now see some of the structur
41
41
42
42
----------
43
43
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.
45
45
46
-
Structurally, the XML elements are represented in the following order:
46
+
Structurally, the XML elements are represented in the following order:
47
47
48
48
<Floor><br/>
49
49
<Dimension /><br/>
@@ -53,7 +53,7 @@ Structurally, the XML elements are represented in the following order:
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:
59
59
```
@@ -64,8 +64,3 @@ Where the Tag is "AccessPoint" and there are 6 Attributes: "apMode", "ethMacAddr
64
64
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")
65
65
66
66
Now that we have a better understanding of what the structure looks like, let's parse the data.
Copy file name to clipboardExpand all lines: labs/coding-201-parsing-xml/4.md
+2-8Lines changed: 2 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
## Step 4. Getting XML Elements in Python
1
+
## Step 4. Getting XML Elements in Python
2
2
3
3
### Retrieving Elements by Tag Name
4
4
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.
6
6
7
7
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.
8
8
```
@@ -38,9 +38,3 @@ When you run the Python script, you should get a very similar output to before w
38
38
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.
39
39
40
40
Let's move to the last step and learn about resources available to further your knowledge of parsing XML with Python.
0 commit comments