+@bottle.route(url_base + '/<tenant_id>/sdn_controllers', method='POST')
+def http_post_sdn_controller(tenant_id):
+ '''insert a sdn controller into the catalogue. '''
+ #parse input data
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+ http_content,_ = format_in( sdn_controller_schema )
+ try:
+ logger.debug("tenant_id: "+tenant_id)
+ #logger.debug("content: {}".format(http_content['sdn_controller']))
+
+ data = nfvo.sdn_controller_create(mydb, tenant_id, http_content['sdn_controller'])
+ return format_out({"sdn_controller": nfvo.sdn_controller_list(mydb, tenant_id, data)})
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_post_sdn_controller error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+@bottle.route(url_base + '/<tenant_id>/sdn_controllers/<controller_id>', method='PUT')
+def http_put_sdn_controller_update(tenant_id, controller_id):
+ '''Update sdn controller'''
+ #parse input data
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+ http_content,_ = format_in( sdn_controller_edit_schema )
+# r = utils.remove_extra_items(http_content, datacenter_schema)
+# if r:
+# logger.debug("Remove received extra items %s", str(r))
+ try:
+ #logger.debug("tenant_id: "+tenant_id)
+ logger.debug("content: {}".format(http_content['sdn_controller']))
+
+ data = nfvo.sdn_controller_update(mydb, tenant_id, controller_id, http_content['sdn_controller'])
+ return format_out({"sdn_controller": nfvo.sdn_controller_list(mydb, tenant_id, controller_id)})
+
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_post_sdn_controller error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+@bottle.route(url_base + '/<tenant_id>/sdn_controllers', method='GET')
+def http_get_sdn_controller(tenant_id):
+ '''get sdn controllers list, can use both uuid or name'''
+ try:
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+
+ data = {'sdn_controllers': nfvo.sdn_controller_list(mydb, tenant_id)}
+ return format_out(data)
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_get_sdn_controller error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+@bottle.route(url_base + '/<tenant_id>/sdn_controllers/<controller_id>', method='GET')
+def http_get_sdn_controller_id(tenant_id, controller_id):
+ '''get sdn controller details, can use both uuid or name'''
+ try:
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+ data = nfvo.sdn_controller_list(mydb, tenant_id, controller_id)
+ return format_out({"sdn_controllers": data})
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_get_sdn_controller_id error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+@bottle.route(url_base + '/<tenant_id>/sdn_controllers/<controller_id>', method='DELETE')
+def http_delete_sdn_controller_id(tenant_id, controller_id):
+ '''delete sdn controller, can use both uuid or name'''
+ try:
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+ data = nfvo.sdn_controller_delete(mydb, tenant_id, controller_id)
+ return format_out(data)
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_delete_sdn_controller_id error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+@bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/sdn_mapping', method='POST')
+def http_post_datacenter_sdn_port_mapping(tenant_id, datacenter_id):
+ '''Set the sdn port mapping for a datacenter. '''
+ #parse input data
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+ http_content, _ = format_in(sdn_port_mapping_schema)
+# r = utils.remove_extra_items(http_content, datacenter_schema)
+# if r:
+# logger.debug("Remove received extra items %s", str(r))
+ try:
+ data = nfvo.datacenter_sdn_port_mapping_set(mydb, tenant_id, datacenter_id, http_content['sdn_port_mapping'])
+ return format_out({"sdn_port_mapping": data})
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_post_datacenter_sdn_port_mapping error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+@bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/sdn_mapping', method='GET')
+def http_get_datacenter_sdn_port_mapping(tenant_id, datacenter_id):
+ '''get datacenter sdn mapping details, can use both uuid or name'''
+ try:
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+
+ data = nfvo.datacenter_sdn_port_mapping_list(mydb, tenant_id, datacenter_id)
+ return format_out({"sdn_port_mapping": data})
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_get_datacenter_sdn_port_mapping error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))
+
+@bottle.route(url_base + '/<tenant_id>/datacenters/<datacenter_id>/sdn_mapping', method='DELETE')
+def http_delete_datacenter_sdn_port_mapping(tenant_id, datacenter_id):
+ '''clean datacenter sdn mapping, can use both uuid or name'''
+ try:
+ logger.debug('FROM %s %s %s', bottle.request.remote_addr, bottle.request.method, bottle.request.url)
+ data = nfvo.datacenter_sdn_port_mapping_delete(mydb, tenant_id, datacenter_id)
+ return format_out({"result": data})
+ except bottle.HTTPError:
+ raise
+ except (nfvo.NfvoException, db_base_Exception) as e:
+ logger.error("http_delete_datacenter_sdn_port_mapping error {}: {}".format(e.http_code, str(e)))
+ bottle.abort(e.http_code, str(e))
+ except Exception as e:
+ logger.error("Unexpected exception: ", exc_info=True)
+ bottle.abort(HTTP_Internal_Server_Error, type(e).__name__ + ": " + str(e))