<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import json <EOL> import requests <EOL> from requests . auth import HTTPBasicAuth <EOL> class OpenDaylight ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . setup = { '<STR_LIT>' : '<STR_LIT:localhost>' , <EOL> '<STR_LIT:port>' : '<STR_LIT>' , <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT:path>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:default>' , <EOL> '<STR_LIT:http>' : '<STR_LIT>' } <EOL> self . _base_url = None <EOL> self . url = None <EOL> self . auth = None <EOL> def prepare ( self , app , path ) : <EOL> """<STR_LIT>""" <EOL> self . prepare_url ( app , path ) <EOL> self . prepare_auth ( ) <EOL> def prepare_url ( self , app , path ) : <EOL> """<STR_LIT>""" <EOL> self . _base_url = self . setup [ '<STR_LIT:http>' ] + self . setup [ '<STR_LIT>' ] + '<STR_LIT::>' + self . setup [ '<STR_LIT:port>' ] + self . setup [ '<STR_LIT:path>' ] <EOL> self . url = self . _base_url + app + '<STR_LIT:/>' + self . setup [ '<STR_LIT>' ] + path <EOL> def prepare_auth ( self ) : <EOL> """<STR_LIT>""" <EOL> self . auth = HTTPBasicAuth ( self . setup [ '<STR_LIT:username>' ] , <EOL> self . setup [ '<STR_LIT:password>' ] ) <EOL> class OpenDaylightFlow ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , odl ) : <EOL> """<STR_LIT>""" <EOL> self . odl = odl <EOL> self . __app = '<STR_LIT>' <EOL> self . request = None <EOL> self . flows = None <EOL> def get ( self , node_id = None , flow_name = None ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . request <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . flows <EOL> if node_id is None : <EOL> self . odl . prepare ( self . __app , '<STR_LIT:/>' ) <EOL> elif flow_name is None : <EOL> self . odl . prepare ( self . __app , '<STR_LIT:/>' + '<STR_LIT>' + node_id + '<STR_LIT:/>' ) <EOL> else : <EOL> self . odl . prepare ( self . __app , '<STR_LIT:/>' + '<STR_LIT>' + node_id + '<STR_LIT:/>' <EOL> + flow_name + '<STR_LIT:/>' ) <EOL> self . request = requests . get ( url = self . odl . url , auth = self . odl . auth ) <EOL> if self . request . status_code == <NUM_LIT:200> : <EOL> self . flows = self . request . json ( ) <EOL> if '<STR_LIT>' in self . flows : <EOL> self . flows = self . flows . get ( '<STR_LIT>' ) <EOL> else : <EOL> raise OpenDaylightError ( { '<STR_LIT:url>' : self . odl . url , <EOL> '<STR_LIT>' : self . request . status_code , <EOL> '<STR_LIT>' : self . request . text } ) <EOL> def add ( self , flow ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . request <EOL> self . odl . prepare ( self . __app , '<STR_LIT:/>' + flow [ '<STR_LIT>' ] [ '<STR_LIT>' ] + '<STR_LIT:/>' + <EOL> flow [ '<STR_LIT>' ] [ '<STR_LIT>' ] + '<STR_LIT:/>' + flow [ '<STR_LIT:name>' ] + '<STR_LIT:/>' ) <EOL> headers = { '<STR_LIT>' : '<STR_LIT:application/json>' } <EOL> body = json . dumps ( flow ) <EOL> self . request = requests . post ( url = self . odl . url , auth = self . odl . auth , <EOL> data = body , headers = headers ) <EOL> if self . request . status_code != <NUM_LIT> : <EOL> raise OpenDaylightError ( { '<STR_LIT:url>' : self . odl . url , <EOL> '<STR_LIT>' : self . request . status_code , <EOL> '<STR_LIT>' : self . request . text } ) <EOL> def delete ( self , node_id , flow_name ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . request <EOL> self . odl . prepare ( self . __app , '<STR_LIT:/>' + '<STR_LIT>' + node_id + '<STR_LIT:/>' + <EOL> flow_name + '<STR_LIT:/>' ) <EOL> self . request = requests . delete ( url = self . odl . url , auth = self . odl . auth ) <EOL> if self . request . status_code != <NUM_LIT:200> : <EOL> raise OpenDaylightError ( { '<STR_LIT:url>' : self . odl . url , <EOL> '<STR_LIT>' : self . request . status_code , <EOL> '<STR_LIT>' : self . request . text } ) <EOL> class OpenDaylightNode ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , odl ) : <EOL> """<STR_LIT>""" <EOL> self . odl = odl <EOL> self . __app = '<STR_LIT>' <EOL> self . nodes = None <EOL> self . node_connectors = None <EOL> self . request = None <EOL> def get_nodes ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . request <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . nodes <EOL> self . odl . prepare ( self . __app , '<STR_LIT>' ) <EOL> self . request = requests . get ( url = self . odl . url , auth = self . odl . auth ) <EOL> if self . request . status_code == <NUM_LIT:200> : <EOL> self . nodes = self . request . json ( ) <EOL> if '<STR_LIT>' in self . nodes : <EOL> self . nodes = self . nodes . get ( '<STR_LIT>' ) <EOL> else : <EOL> raise OpenDaylightError ( { '<STR_LIT:url>' : self . odl . url , <EOL> '<STR_LIT>' : self . request . status_code , <EOL> '<STR_LIT>' : self . request . text } ) <EOL> def get_node_connectors ( self , node_id ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . request <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . node_connectors <EOL> self . odl . prepare ( self . __app , '<STR_LIT>' + '<STR_LIT>' + node_id + '<STR_LIT:/>' ) <EOL> self . request = requests . get ( url = self . odl . url , auth = self . odl . auth ) <EOL> if self . request . status_code == <NUM_LIT:200> : <EOL> self . node_connectors = self . request . json ( ) <EOL> if '<STR_LIT>' in self . node_connectors : <EOL> self . node_connectors = self . node_connectors . get ( <EOL> '<STR_LIT>' ) <EOL> else : <EOL> raise OpenDaylightError ( { '<STR_LIT:url>' : self . odl . url , <EOL> '<STR_LIT>' : self . request . status_code , <EOL> '<STR_LIT>' : self . request . text } ) <EOL> def save ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> del self . request <EOL> self . odl . prepare ( self . __app , '<STR_LIT>' ) <EOL> self . request = requests . post ( url = self . odl . url , auth = self . odl . auth ) <EOL> if self . request . status_code != <NUM_LIT:200> : <EOL> raise OpenDaylightError ( { '<STR_LIT:url>' : self . odl . url , <EOL> '<STR_LIT>' : self . request . status_code , <EOL> '<STR_LIT>' : self . request . text } ) <EOL> def delete_node_property ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def add_node_property ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def delete_node_connector_property ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def add_node_connector_property ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> class OpenDaylightError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass </s>
