Skip to content

Commit

Permalink
Updated the OpenDaylight library to work with the current version of …
Browse files Browse the repository at this point in the history
…the OpenDaylight controller: variable names changed.
  • Loading branch information
Nabil Maadarani committed Feb 27, 2014
1 parent 23c3d18 commit 401c2ea
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions OpenDaylight.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
Division of Information Technology
University of Wisconsin at Madison
Modified & updated by: Nabil Maadarani, [email protected]
Cisco Science Network
Cisco Systems
This material is based upon work supported by the National Science Foundation
under Grant No. 1247322.
"""
Expand Down Expand Up @@ -103,6 +107,7 @@ def prepare_url(self, app, path):

# the specific path we are building
self.url = self._base_url + app + '/' + self.setup['container'] + path
#self.url = self._base_url + app + '/' + path + self.setup['container']

def prepare_auth(self):
"""Set up the credentials for the REST connection by creating
Expand Down Expand Up @@ -150,7 +155,7 @@ def __init__(self, odl):
odl - an OpenDaylight object
"""
self.odl = odl
self.__app = 'flow'
self.__app = 'flowprogrammer'
self.request = None
self.flows = None

Expand All @@ -170,7 +175,7 @@ def get(self, node_id=None, flow_name=None):
del self.flows

if node_id is None:
self.odl.prepare(self.__app, '/')
self.odl.prepare(self.__app, '/flow')
elif flow_name is None:
self.odl.prepare(self.__app, '/' + 'OF/' + node_id + '/')
else:
Expand All @@ -183,6 +188,7 @@ def get(self, node_id=None, flow_name=None):
self.flows = self.request.json()
if 'flowConfig' in self.flows:
self.flows = self.flows.get('flowConfig')
print(self.flows)
else:
raise OpenDaylightError({'url':self.odl.url,
'http_code':self.request.status_code,
Expand All @@ -197,11 +203,11 @@ def add(self, flow):
if hasattr(self, 'request'):
del self.request
#print(flow)
self.odl.prepare(self.__app, '/' + flow['node']['@type'] + '/' +
flow['node']['@id'] + '/' + flow['name'] + '/')
self.odl.prepare(self.__app, '/node/' + flow['node']['type'] + '/' +
flow['node']['id'] + '/staticFlow/' + flow['name'] + '/')
headers = {'Content-type': 'application/json'}
body = json.dumps(flow)
self.request = requests.post(url=self.odl.url, auth=self.odl.auth,
self.request = requests.put(url=self.odl.url, auth=self.odl.auth,
data=body, headers=headers)

if self.request.status_code != 201:
Expand All @@ -224,7 +230,7 @@ def delete(self, node_id, flow_name):
if hasattr(self, 'request'):
del self.request

self.odl.prepare(self.__app, '/' + 'OF/' + node_id + '/' +
self.odl.prepare(self.__app, '/node/' + 'OF/' + node_id + '/staticFlow/' +
flow_name + '/')
self.request = requests.delete(url=self.odl.url, auth=self.odl.auth)

Expand All @@ -234,7 +240,7 @@ def delete(self, node_id, flow_name):
#self.prepare(self.__app, '/' + flow['node']['@type'] + '/' +
# flow['node']['@id'] + '/' + flow['name'] + '/')

if self.request.status_code != 200:
if self.request.status_code != 204:
raise OpenDaylightError({'url':self.odl.url,
'http_code':self.request.status_code,
'msg':self.request.text})
Expand Down

0 comments on commit 401c2ea

Please sign in to comment.