+@bottle.route(url_base + '/openflow/mapping', method='POST')
+def http_of_port_mapping():
+ """
+ Insert a tenant into the database.
+ :return:
+ """
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+ http_content = format_in(of_port_map_new_schema)
+ r = remove_extra_items(http_content, of_port_map_new_schema)
+ if r is not None:
+ my.logger.error("http_of_port_mapping: Warning: remove extra items " + str(r), exc_info=True)
+
+ # insert in data base
+ port_mapping = my.ovim.set_of_port_mapping(http_content['of_port_mapings'])
+ change_keys_http2db(port_mapping, http2db_id, reverse=True)
+ delete_nulls(port_mapping)
+ data = {'of_port_mappings': port_mapping}
+ 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/mapping', method='GET')
+def get_of_port_mapping():
+ """
+ Insert a tenant into the database.
+ :return:
+ """
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+ select_, where_, limit_ = filter_query_string(bottle.request.query, http2db_id,
+ ('id', 'ofc_id', 'region', 'compute_node', 'pci',
+ 'switch_dpid', 'switch_port', 'switch_mac'))
+ # insert in data base
+ port_mapping = my.ovim.get_of_port_mappings(select_, where_)
+ change_keys_http2db(port_mapping, http2db_id, reverse=True)
+ delete_nulls(port_mapping)
+ data = {'of_port_mappings': port_mapping}
+ 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/mapping/<region>', method='DELETE')
+def delete_of_port_mapping(region):
+ """
+ Insert a tenant into the database.
+ :return:
+ """
+ my = config_dic['http_threads'][threading.current_thread().name]
+
+ try:
+ # insert in data base
+ db_filter = {'region': region}
+ result = my.ovim.clear_of_port_mapping(db_filter)
+ data = {'result': result}
+ 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))
+