Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
2fff71b
fixed a few bugs and updated step3 script
amwhaley Apr 29, 2015
44f348a
Merge branch 'master' of https://github.com/CiscoDevNet/coding-skills…
amwhaley Apr 29, 2015
90f26bb
Initial commit of Coding 210 - Parsing JSON with C++
mikemaas May 4, 2015
784c5cd
Add gitignore
aroach May 5, 2015
49b0c91
Add blank travis file
aroach May 7, 2015
f25b430
Updating gitignore to not include JetBrains IDE workspace files.
mikemaas-cisco Jun 5, 2015
3dd5a82
Updates to include CMake support, C# comparison example, and README
mikemaas-cisco Jun 5, 2015
425489a
Last minute updates to use the properly named msesandbox.cisco.com URI
mikemaas-cisco Jun 8, 2015
abd16be
Adding parsing workshop skeleton file.
mikemaas-cisco Jun 9, 2015
8a7bf46
Cleaning up parsing code and updated to use the msedandbox.cisco.com URI
mikemaas-cisco Jun 10, 2015
afdf2b6
apic-em ga stuff
brtiller1 Jan 8, 2016
2372f9a
coding 207 for Apic-em ga
brtiller1 Jan 8, 2016
1d5b7af
update for apic-em GA release
brtiller1 Jan 12, 2016
8fce9f0
Delete file
brtiller1 Jan 19, 2016
088fbaa
readme file n other file changes
brtiller1 Jan 19, 2016
a3ed251
Merge branch 'master' of https://github.com/CiscoDevNet/coding-skills…
brtiller1 Jan 19, 2016
33e80ae
admin password changes
brtiller1 Jan 29, 2016
a3bf730
added links to learning labs in readme
amwhaley Feb 14, 2016
8afa97c
Updating to proper Python style (PEP 0008).
mikemaas-cisco Feb 15, 2016
2bc7f3e
Update to typo in commented-out code
mikemaas-cisco Feb 16, 2016
1a4e1da
Added env shebang to automatically choose parser
jandahl Feb 17, 2016
a825350
labs for coding 202 parsing json
brtiller1 May 6, 2016
8239803
changes
brtiller1 May 6, 2016
5fb79ce
fix
brtiller1 May 9, 2016
5e78c82
coding 202 script additions
brtiller1 May 11, 2016
2bc072a
apic-em coidng 102 user pwd changes
brtiller1 Jun 6, 2016
880cc78
apic-em user pwd change
brtiller1 Jun 6, 2016
0d8e2b4
apic-em coding user pwd changes
brtiller1 Jun 6, 2016
3fa69ea
new topology script
brtiller1 Jun 23, 2016
f233fbb
formatting changes
brtiller1 Jun 27, 2016
6652ee3
url tracking change
brtiller1 Jun 28, 2016
efd809c
url tracking change
brtiller1 Jun 28, 2016
2cf4b2a
changes
brtiller1 Jul 6, 2016
65ef270
changes
brtiller1 Jul 6, 2016
4a6d992
Delete report-topology.py
brtiller1 Jul 7, 2016
4581b9b
Delete spark.py
brtiller1 Jul 7, 2016
a3b16a8
updates
brtiller1 Jul 7, 2016
c9966b4
updates
brtiller1 Jul 7, 2016
056ff8e
Add one learning lab to use Flask build a web server and use NeXt UI …
abdvl Jul 8, 2016
653cc71
Fix for Spider Bot Defense
mikemaas-cisco Jul 11, 2016
51facf4
Merge pull request #6 from abdvl/master
brtiller1 Jul 21, 2016
eb8b415
build topology fixes
brtiller1 Jul 21, 2016
0a12c03
Delete build-topologySav7.21.2016.py
brtiller1 Jul 21, 2016
c08ad57
Delete readme.txt
brtiller1 Jul 28, 2016
4ad0176
coding 102 changes
brtiller1 Jul 29, 2016
ab5a713
Merge branch 'master' of http://github.com/CiscoDevNet/coding-skills-…
brtiller1 Jul 29, 2016
87d7ca2
coding 103 code
brtiller1 Aug 4, 2016
ea929dd
Delete call-functions.py
brtiller1 Aug 19, 2016
4887187
Delete data-type-values.py
brtiller1 Aug 19, 2016
36a0478
Delete hello.py
brtiller1 Aug 19, 2016
57dbdb8
Delete helloworld.py
brtiller1 Aug 19, 2016
ee42035
Delete json_parse-1.py
brtiller1 Aug 19, 2016
57dcb21
Delete json_parse-2.py
brtiller1 Aug 19, 2016
e44984c
Delete loops.py
brtiller1 Aug 19, 2016
92cb59e
Delete loops_ex.py
brtiller1 Aug 19, 2016
990fc9c
Fixes for MSE URL and API change
mikemaas-cisco Aug 23, 2016
dae2aa2
Delete apic-em-helloworld.py
brtiller1 Aug 29, 2016
a94988b
Delete apic-em1.py
brtiller1 Aug 29, 2016
c0fb18c
Delete learning-lab-basics-step2.py
brtiller1 Aug 29, 2016
726cdcf
Delete learning-lab-basics-step3.py
brtiller1 Aug 29, 2016
72c28be
Delete learning-lab-basics.py
brtiller1 Aug 29, 2016
815cf71
Delete learning-lab-create-policy.py
brtiller1 Aug 29, 2016
ae5b4f4
Delete learning-lab-delete-policy.py
brtiller1 Aug 29, 2016
efe0731
Delete readme.txt
brtiller1 Aug 29, 2016
b08c3ce
Delete list-of-devices.txt
brtiller1 Aug 29, 2016
b560c77
Delete my-new-file.txt
brtiller1 Aug 29, 2016
04a8341
Delete my-new-file2.txt
brtiller1 Aug 29, 2016
7ed59e1
Delete write-file-append.py
brtiller1 Aug 29, 2016
d1f10a0
Delete write-file-using-with.py
brtiller1 Aug 29, 2016
8392218
Delete write-file.py
brtiller1 Aug 29, 2016
dd44b38
Delete write-json-to-file.py
brtiller1 Aug 29, 2016
7bc4b61
updates
brtiller1 Aug 29, 2016
394d093
Fix for Authorization Header
mikemaas-cisco Jan 16, 2017
91b0471
Initial Addition of Content Server
mikemaas-cisco Feb 16, 2017
6c113ce
Update to index
mikemaas-cisco Feb 16, 2017
81d9265
Merged branch content-serve into master
mikemaas-cisco Feb 16, 2017
5907207
Adding Content-Serve Examples
mikemaas-cisco Mar 8, 2017
1c1173d
adding coding 103 sample code for devnet-2006
Jun 27, 2017
7356b4a
Fix misspelled Volkswagen
annegentle Nov 28, 2017
ec62d73
Merge pull request #8 from annegentle/ag-jsonspell
annegentle Dec 29, 2017
4a27d18
Adds contributing guidelines
agentlecisco Feb 20, 2018
9605eee
Merge pull request #9 from CiscoDevNet/add-contrib
annegentle Feb 20, 2018
4d51ead
Merge pull request #4 from jandahl/patch-1
annegentle Feb 22, 2018
57c36de
Consistent README for Learning Labs
agentlecisco Mar 9, 2018
338b64d
Consistent README for Learning Labs
agentlecisco Mar 9, 2018
ce9feae
Update README with more info
agentlecisco Mar 13, 2018
78dbf9e
Merge pull request #10 from CiscoDevNet/readme
annegentle Mar 13, 2018
9e5f212
Simpler introductory text in the README
annegentle Apr 3, 2018
5cd1bee
Merge pull request #11 from CiscoDevNet/update-readme
annegentle Apr 3, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jetbrains IDE files
.idea
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>coding-skills-sample-code</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 3.0</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
</pydev_project>
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: python
python:
- "2.7"
branches:
only:
- clus-updates
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# coding-skills-sample-code
Sample code for the Cisco DevNet Coding Skills Learning Labs
## Cisco DevNet Learning Labs Sample Code for Coding Skills

You can find step-by-step tutorials that walk through this sample code on [Cisco DevNet](http://learninglabs.cisco.com).
These code examples provide Python scripts to perform coding tasks.

The step-by-step tutorials that work with this code are Learning Labs, displayed within the [Cisco DevNet Learning Labs system](https://learninglabs.cisco.com).

Contributions are welcome, and we are glad to review changes through pull requests. See [contributing.md](contributing.md) for details.

The goal of these learning labs is to ensure a 'hands-on' learning approach rather than just theory or instructions.

## Contributing

These samples are for public consumption, so you must ensure that you have the rights to any code that you contribute.

## Getting Involved

* If you'd like to contribute examples for an existing lab, refer to [contributing.md](contributing.md).
* If you're interested in creating a new Cisco DevNet Learning Lab or code example, please contact a DevNet administrator for guidance.

118 changes: 118 additions & 0 deletions coding102-REST-python-dcloud/build-topology.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# Example of building topology via REST API calls from Python

# * THIS SAMPLE APPLICATION AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
# * OF ANY KIND BY CISCO, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
# * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR
# * PURPOSE, NONINFRINGEMENT, SATISFACTORY QUALITY OR ARISING FROM A COURSE OF
# * DEALING, LAW, USAGE, OR TRADE PRACTICE. CISCO TAKES NO RESPONSIBILITY
# * REGARDING ITS USAGE IN AN APPLICATION, AND IT IS PRESENTED ONLY AS AN
# * EXAMPLE. THE SAMPLE CODE HAS NOT BEEN THOROUGHLY TESTED AND IS PROVIDED AS AN
# * EXAMPLE ONLY, THEREFORE CISCO DOES NOT GUARANTEE OR MAKE ANY REPRESENTATIONS
# * REGARDING ITS RELIABILITY, SERVICEABILITY, OR FUNCTION. IN NO EVENT DOES
# * CISCO WARRANT THAT THE SOFTWARE IS ERROR FREE OR THAT CUSTOMER WILL BE ABLE
# * TO OPERATE THE SOFTWARE WITHOUT PROBLEMS OR INTERRUPTIONS. NOR DOES CISCO
# * WARRANT THAT THE SOFTWARE OR ANY EQUIPMENT ON WHICH THE SOFTWARE IS USED WILL
# * BE FREE OF VULNERABILITY TO INTRUSION OR ATTACK. THIS SAMPLE APPLICATION IS
# * NOT SUPPORTED BY CISCO IN ANY MANNER. CISCO DOES NOT ASSUME ANY LIABILITY
# * ARISING FROM THE USE OF THE APPLICATION. FURTHERMORE, IN NO EVENT SHALL CISCO
# * OR ITS SUPPLIERS BE LIABLE FOR ANY INCIDENTAL OR CONSEQUENTIAL DAMAGES, LOST
# * PROFITS, OR LOST DATA, OR ANY OTHER INDIRECT DAMAGES EVEN IF CISCO OR ITS
# * SUPPLIERS HAVE BEEN INFORMED OF THE POSSIBILITY THEREOF.-->


# import requests library
import requests

#import json library
import json

# Disable warnings
requests.packages.urllib3.disable_warnings()

controller='198.18.129.100'


def getTicket():
# put the ip address or dns of your apic-em controller in this url
url = "https://" + controller + "/api/v1/ticket"

#the username and password to access the APIC-EM Controller
payload = {"username":"admin","password":"C1sco12345"}

#Content type must be included in the header
header = {"content-type": "application/json"}

#Performs a POST on the specified url to get the service ticket
response= requests.post(url,data=json.dumps(payload), headers=header, verify=False)

print (response)

#convert response to json format
r_json=response.json()

#parse the json to get the service ticket
ticket = r_json["response"]["serviceTicket"]

return ticket



def getTopology(ticket):
# URL for topology REST API call to get list of existing devices on the network, and build topology
url = "https://" + controller + "/api/v1/topology/physical-topology"

#Content type as well as the ticket must be included in the header
header = {"content-type": "application/json", "X-Auth-Token":ticket}

# this statement performs a GET on the specified network device url
response = requests.get(url, headers=header, verify=False)

# json.dumps serializes the json into a string and allows us to
# print the response in a 'pretty' format with indentation etc.
print ("Topology = ")
print (json.dumps(response.json(), indent=4, separators=(',', ': ')))

#convert data to json format.
r_json=response.json()

#Iterate through network device data and list the nodes, their interfaces, status and to what they connect
for n in r_json["response"]["nodes"]:
if "platformId" in n:
print()
print()
print('{:30}'.format("Node") + '{:25}'.format("Family") + '{:20}'.format("Label")+ "Management IP")
print('{:30}'.format(n["platformId"]) + '{:25}'.format(n["family"]) + '{:20}'.format(n["label"]) + n["ip"])
found=0 #print header flag
printed=0 #formatting flag
for i in r_json["response"]["links"]:
if "startPortName" in i:
#check that the source device id for the interface matches the node id. Means interface originated from this device.
if i["source"] == n["id"]:
if found==0:
print('{:>20}'.format("Source Interface") + '{:>15}'.format("Target") +'{:>28}'.format("Target Interface") + '{:>15}'.format("Status") )
found=1
printed=1
for n1 in r_json["response"]["nodes"]:
#find name of node to which this one connects
if i["target"] == n1["id"]:
print(" " + '{:<25}'.format(i["startPortName"]) + '{:<18}'.format(n1["platformId"]) + '{:<25}'.format(i["endPortName"]) + '{:<9}'.format(i["linkStatus"]) )
break;
found=0

for i in r_json["response"]["links"]:
if "startPortName" in i:
#Find interfaces that link to this one which means this node is the target.
if i["target"] == n["id"]:
if found==0:
if printed==1:
print()
print('{:>10}'.format("Source") + '{:>30}'.format("Source Interface") + '{:>25}'.format("Target Interface") + '{:>13}'.format("Status"))
found=1
for n1 in r_json["response"]["nodes"]:
#find name of node to that connects to this one
if i["source"] == n1["id"]:
print(" " + '{:<20}'.format(n1["platformId"]) + '{:<25}'.format(i["startPortName"]) + '{:<23}'.format(i["endPortName"]) + '{:<8}'.format(i["linkStatus"]))
break;

theTicket=getTicket()
getTopology(theTicket)
23 changes: 23 additions & 0 deletions coding102-REST-python-dcloud/create-ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# import requests library
import requests

#import json library
import json

# put the ip address or dns of your apic-em controller in this url
url = 'https://198.18.129.100/api/v1/ticket'



#the username and password to access the APIC-EM Controller
payload = {"username":"admin","password":"C1sco12345"}


#Content type must be included in the header
header = {"content-type": "application/json"}

#Performs a POST on the specified url.
response= requests.post(url,data=json.dumps(payload), headers=header, verify=False)

# print the json that is returned
print(response.text)
80 changes: 80 additions & 0 deletions coding102-REST-python-dcloud/get-network-devices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Example of getting network-devices via REST API calls from Python

# * THIS SAMPLE APPLICATION AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
# * OF ANY KIND BY CISCO, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
# * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR
# * PURPOSE, NONINFRINGEMENT, SATISFACTORY QUALITY OR ARISING FROM A COURSE OF
# * DEALING, LAW, USAGE, OR TRADE PRACTICE. CISCO TAKES NO RESPONSIBILITY
# * REGARDING ITS USAGE IN AN APPLICATION, AND IT IS PRESENTED ONLY AS AN
# * EXAMPLE. THE SAMPLE CODE HAS NOT BEEN THOROUGHLY TESTED AND IS PROVIDED AS AN
# * EXAMPLE ONLY, THEREFORE CISCO DOES NOT GUARANTEE OR MAKE ANY REPRESENTATIONS
# * REGARDING ITS RELIABILITY, SERVICEABILITY, OR FUNCTION. IN NO EVENT DOES
# * CISCO WARRANT THAT THE SOFTWARE IS ERROR FREE OR THAT CUSTOMER WILL BE ABLE
# * TO OPERATE THE SOFTWARE WITHOUT PROBLEMS OR INTERRUPTIONS. NOR DOES CISCO
# * WARRANT THAT THE SOFTWARE OR ANY EQUIPMENT ON WHICH THE SOFTWARE IS USED WILL
# * BE FREE OF VULNERABILITY TO INTRUSION OR ATTACK. THIS SAMPLE APPLICATION IS
# * NOT SUPPORTED BY CISCO IN ANY MANNER. CISCO DOES NOT ASSUME ANY LIABILITY
# * ARISING FROM THE USE OF THE APPLICATION. FURTHERMORE, IN NO EVENT SHALL CISCO
# * OR ITS SUPPLIERS BE LIABLE FOR ANY INCIDENTAL OR CONSEQUENTIAL DAMAGES, LOST
# * PROFITS, OR LOST DATA, OR ANY OTHER INDIRECT DAMAGES EVEN IF CISCO OR ITS
# * SUPPLIERS HAVE BEEN INFORMED OF THE POSSIBILITY THEREOF.-->


# import requests library
import requests

#import json library
import json

controller='198.18.129.100'

def getTicket():
# put the ip address or dns of your apic-em controller in this url
url = "https://" + controller + "/api/v1/ticket"

#the username and password to access the APIC-EM Controller
payload = {"username":"admin","password":"C1sco12345"}

#Content type must be included in the header
header = {"content-type": "application/json"}

#Performs a POST on the specified url to get the service ticket
response= requests.post(url,data=json.dumps(payload), headers=header, verify=False)

print (response)

#convert response to json format
r_json=response.json()

#parse the json to get the service ticket
ticket = r_json["response"]["serviceTicket"]

return ticket


def getNetworkDevices(ticket):
# URL for network-device REST API call to get list of exisiting devices on the network.
url = "https://" + controller + "/api/v1/network-device"

#Content type as well as the ticket must be included in the header
header = {"content-type": "application/json", "X-Auth-Token":ticket}

# this statement performs a GET on the specified network device url
response = requests.get(url, headers=header, verify=False)

# json.dumps serializes the json into a string and allows us to
# print the response in a 'pretty' format with indentation etc.
print ("Network Devices = ")
print (json.dumps(response.json(), indent=4, separators=(',', ': ')))

#convert data to json format.
r_json=response.json()

#Iterate through network device data and print the id and series name of each device
for i in r_json["response"]:
print(i["id"] + " " + '{:53}'.format(i["series"]) + " " + i["reachabilityStatus"])



theTicket=getTicket()
getNetworkDevices(theTicket)
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,44 @@
# * SUPPLIERS HAVE BEEN INFORMED OF THE POSSIBILITY THEREOF.-->


# import requests library
import requests

#import json library
import json

controller='198.18.129.100'


# put the ip address or dns of your apic-em controller in this url
url = 'https://sandboxapic.cisco.com/api/v0/host/1/3'
url = "https://" + controller + "/api/v1/ticket"

#the username and password to access the APIC-EM Controller
payload = {"username":"admin","password":"C1sco12345"}

#Content type must be included in the header
header = {"content-type": "application/json"}

#Performs a POST on the specified url to get the service ticket
response= requests.post(url,data=json.dumps(payload), headers=header, verify=False)

#convert response to json format
r_json=response.json()

print(r_json)
#parse the json to get the service ticket
ticket = r_json["response"]["serviceTicket"]

# URL for Host REST API call to get list of exisitng hosts on the network.
url = "https://" + controller + "/api/v1/host?limit=1&offset=1"

#Content type must be included in the header as well as the ticket
header = {"content-type": "application/json", "X-Auth-Token":ticket}

# this statement performs a GET on the specified url
response = requests.get(url, verify=False)
# this statement performs a GET on the specified host url
response = requests.get(url, headers=header, verify=False)

# print the json that is returned
print(response.text)
# json.dumps serializes the json into a string and allows us to
# print the response in a 'pretty' format with indentation etc.
print ("Hosts = ")
print (json.dumps(response.json(), indent=4, separators=(',', ': ')))
Loading