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
In this step we're going to continue to use functions to get, create and delete users.
3
+
In this step we're going to get the topology then parse the data to determine how devices link to one another and their status.
4
4
5
5
6
6
#### manage-users.py
7
-
This sample code uses the application REST function call to retrieve a list of the APIC-EM users and their roles. Our goal is to find the users and display information about them. In addition, we'll create a new user and delete it.
7
+
This sample code uses the application REST function call to retrieve a list of devices called nodes and links which are the interfaces that connect them. Our goal is to find the devices and display information about them and how they connect to other devices.
8
8
9
9
10
10
```python
@@ -14,16 +14,12 @@ import requests
14
14
#import json library
15
15
import json
16
16
17
-
18
17
# Disable warnings
19
18
requests.packages.urllib3.disable_warnings()
20
19
21
-
22
20
controller='sandboxapic.cisco.com'
23
21
24
-
#creates and returns a service ticket.
25
22
defgetTicket():
26
-
print("\nCreating ticket")
27
23
# put the ip address or dns of your apic-em controller in this url
28
24
url ="https://"+ controller +"/api/v1/ticket"
29
25
@@ -36,6 +32,8 @@ def getTicket():
36
32
#Performs a POST on the specified url to get the service ticket
Let's look at what the code is doing. We'll focus on the key code changes.
126
-
**def addUser(theTicket):*
127
-
* We define the function named addUser. This function creates a payload with user information and adds it. The passed in parameter 'theTicket' is used for authorization purposes.
128
-
**def deleteUser(username,theTicket):*
129
-
* We define the function named deleteUser which removes a user with the name of the passed in parameter 'username'. The passed in parameter 'theTicket' is used for authorization purposes.
109
+
**def getTopology(theTicket):*
110
+
* 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.
130
111
131
112
To run this code sample:
132
113
1. Go to directory **coding102-REST-python-ga**. In the terminal type:
2. Assign the APIC-EM Controller IP address or DNS to the **controller** variable.
135
-
* Open the file **manage-users.py**. For example, in Windows type: **notepad manage-users.py**
116
+
* Open the file **build-topology.py**. For example, in Windows type: **notepad build-topology.py**
136
117
**If you are not using your own APIC-EM Controller*, use the [DevNet Sandbox](https://developer.cisco.com/site/devnet/sandbox/) Always-On APIC-EM Lab: [sandboxapic.cisco.com](https://sandboxapic.cisco.com)
137
118
* controller='sandboxapic.cisco.com'
138
119
3. Save the file. If encoding type is an option select **UTF-8**.
139
120
4. Type the python command and then the filename at the command prompt, and press the return key.
140
-
**On Windows type*: **py -3 manage-users.py**. Or type: **python manage-users.py**
141
-
**On Mac OS or Linux type*: **python3 manage-users.py**
121
+
**On Windows type*: **py -3 build-topology.py**. Or type: **python build-topology.py**
122
+
**On Mac OS or Linux type*: **python3 build-topology.py**
142
123
5. The program should execute or display an error message.
*Comment out the call to deleteUser(name,theTicket) which would then show as *#deleteUser(name,theTicket)*, and run the program twice. What error occurs when you try to add an already existing user?
162
-
*Remove the pound sign # from the deleteUser function so reads as *deleteUser(name,theTicket)* then run the program twice. Is the problem corrected?
163
-
*In the showUser(name,theTicket) function call change the name parameter to string 'joe' so the function call reads as *showUser('joe',theTicket)* . What happens when the user to be shown is not found?
131
+
*After running the script, review the node data printed. Replace the label attribute that is printed with another attribute such as role or nodeType.
132
+
*You may have noticed that no host devices are printed. Review the data and the source code, and determine why this is so along with how you would print this data.
133
+
*Modify the source code so that host devices are printed as well.
0 commit comments