-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFirstRestconfApp.py
More file actions
executable file
·135 lines (111 loc) · 5.01 KB
/
FirstRestconfApp.py
File metadata and controls
executable file
·135 lines (111 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python
"""
DESCRIPTION:
This is an extremely simple Python application that demonstrates how to
use Elbrys SDN Developer Lab (dev.elbrys.com) to
control endpoint user sessions access to the network.
This application will use the RESTCONF api to obtain the networks
topology and print it out.
PRE-REQUISITES:
1. Python 2.x
2. Install python-requests:
a. sudo easy_install requests
3. Go to dev.elbrys.com and follow the directions there
Mail bug reports and suggestion to : support@elbrys.com
"""
import requests
import argparse
from requests.auth import HTTPBasicAuth
def RConfGetTopology(rConfBaseUrl, user, password):
# This calls the RESTConf api to retrieve the topology
# INPUT:
# rConfBaseUrl - base url at which RestConf calls may be
# made - example: http://192.168.56.101:8181/restconf
# user - the user name with which to authenticate - example: admin
# password - the password with which to authenticate - example - admin
# RETURNS: topology as JSON
url = rConfBaseUrl + '/operational/network-topology:network-topology/'
headers = {'content-type': 'application/json',
'accept': 'application/json'}
r = requests.get(url, headers=headers, auth=HTTPBasicAuth(user, password))
topo = r.json()
return topo
def PrintTopology(topology):
# Prints out provided topology. It is indented 12 spaces.
# INPUT:
# topology - the topology, in JSON, returned from RESTConf get topology
# RETURNS: nothing
print " ======================================================"
print " Topology"
print " ======================================================"
if ('network-topology' not in topology):
print " No toplogy."
else:
net = topology['network-topology']
net = net['topology']
for topo in net:
topo_id = topo['topology-id']
print " Network: " + topo_id
if 'node' in topo:
nodes = topo['node']
for node in nodes:
node_id = node['node-id']
print " Node: " + node_id
if 'termination-point' in node:
ports = node['termination-point']
for port in ports:
port_id = port['tp-id']
print " Port: " + port_id
print " ======================================================"
def GetCommandLineParser():
# This method will process the command line parameters
parser = argparse.ArgumentParser(
description='Simple SDN Application to block/unblock devices connected\
to switch.')
parser.add_argument('--id',
required=True,
help='your SDN Developer Lab Application id. Go to sdn-developer.\
elbrys.com, logon, select "My Account" in top right.')
parser.add_argument('--secret',
required=True,
help='your SDN Developer Lab Application secret. Go to\
sdn-developer.elbrys.com, logon, select "My\
Account", select "Edit Account", select the\
"eyeball" icon next to password.')
parser.add_argument('--server',
required=True,
help='The IP address of your SDN Developer Lab controller. Go to \
sdn-developer.elbrys.com, logon, look at \
"Controller" table.')
parser.add_argument('--port',
required=True,
help='The TCP REST API port number of your SDN Developer Lab \
controller. Go to sdn-developer.elbrys.com, \
logon, look at "Controller" table for \
REST API Port.')
return parser
def main():
global odlsBaseUrl
global odlsBaseRestConfUrl
# The version of the application
version = "1.1.3"
print "Elbrys Developer Portal FirstRestconfApp"
print "Version: " + version
print "A very simple that uses RESTCONF api of Elbrys' Developer Portal."
print __doc__
# --------------------------------
# Command Line Processing
parser = GetCommandLineParser()
args = parser.parse_args()
odlsBaseUrl = "http://" + args.server + ":" + args.port
odlsBaseRestConfUrl = odlsBaseUrl + "/restconf"
print "Elbrys Developer Portal API is at: " + odlsBaseUrl
print "Elbrys Developer Portal RESTCONF API is at: " + odlsBaseRestConfUrl
topology = RConfGetTopology(odlsBaseRestConfUrl, args.id, args.secret)
print " Initial Topology: "
PrintTopology(topology)
# The BASE url where the Elbrys' SDN Developer Portal api listens
odlsBaseUrl = None
odlsBaseRestConfUrl = None
if __name__ == "__main__":
main()