+
+
+@bottle.route(url_base + '/openflow/controller', method='GET')
+def http_get_openflow_controller():
+ """
+ Retrieve a openflow controllers list from DB.
+ :return:
+ """
+ # TODO check if show a proper list
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+ select_, where_, limit_ = filter_query_string(bottle.request.query, http2db_ofc,
+ ('id', 'name', 'dpid', 'ip', 'port', 'type',
+ 'version', 'user', 'password'))
+
+ content = my.ovim.get_of_controllers(select_, where_)
+ delete_nulls(content)
+ change_keys_http2db(content, http2db_ofc, reverse=True)
+ data = {'ofcs': content}
+ return format_out(data)
+ except ovim.ovimException as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(HTTP_Bad_Request, str(e))
+
+
+@bottle.route(url_base + '/openflow/controller/<uuid>', method='GET')
+def http_get_openflow_controller_id(uuid):
+ """
+ Get an openflow controller by dpid from DB.get_of_controllers
+ """
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+
+ content = my.ovim.show_of_controller(uuid)
+ delete_nulls(content)
+ change_keys_http2db(content, http2db_ofc, reverse=True)
+ data = {'ofc': content}
+ return format_out(data)
+ except ovim.ovimException as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(HTTP_Bad_Request, str(e))
+
+
+@bottle.route(url_base + '/openflow/controller/', method='POST')
+def http_post_openflow_controller():
+ """
+ Create a new openflow controller into DB
+ :return:
+ """
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+ http_content = format_in(openflow_controller_schema)
+ of_c = http_content['ofc']
+ uuid = my.ovim.new_of_controller(of_c)
+ content = my.ovim.show_of_controller(uuid)
+ delete_nulls(content)
+ change_keys_http2db(content, http2db_ofc, reverse=True)
+ data = {'ofc': content}
+ return format_out(data)
+ except ovim.ovimException as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(HTTP_Bad_Request, str(e))
+
+
+@bottle.route(url_base + '/openflow/controller/<of_controller_id>', method='PUT')
+def http_put_openflow_controller_by_id(of_controller_id):
+ """
+ Create an openflow controller into DB
+ :param of_controller_id: openflow controller dpid
+ :return:
+ """
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+ http_content = format_in(openflow_controller_schema)
+ of_c = http_content['ofc']
+
+ content = my.ovim.edit_of_controller(of_controller_id, of_c)
+ delete_nulls(content)
+ change_keys_http2db(content, http2db_ofc, reverse=True)
+ data = {'ofc': content}
+ return format_out(data)
+ except ovim.ovimException as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(HTTP_Bad_Request, str(e))
+
+
+@bottle.route(url_base + '/openflow/controller/<of_controller_id>', method='DELETE')
+def http_delete_openflow_controller(of_controller_id):
+ """
+ Delete an openflow controller from DB.
+ :param of_controller_id: openflow controller dpid
+ :return:
+ """
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+ content = my.ovim.delete_of_controller(of_controller_id)
+ data = {'result': content}
+ return format_out(data)
+ except ovim.ovimException as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ my.logger.error(str(e), exc_info=True)
+ bottle.abort(HTTP_Bad_Request, str(e))
+
+