X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=httpserver.py;h=6a16f39de20e61b77a6694e9e44fc929546205f2;hb=f9a1a8d51e7525f0d4acfe02dcb7fb8696fc20b0;hp=7ef02f4290b7d7966e8749da653c848fa9adeb69;hpb=6045a9d58eedd073c595f18b4d1b06667f6d6a81;p=osm%2Fopenvim.git diff --git a/httpserver.py b/httpserver.py index 7ef02f4..6a16f39 100644 --- a/httpserver.py +++ b/httpserver.py @@ -1619,14 +1619,18 @@ def http_post_server_id(tenant_id): r,c = config_dic['host_threads'][ server['host_id'] ].insert_task( 'restore-iface',*port ) if r < 0: print ' http_post_servers ERROR RESTORE IFACE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + c - #updata nets - for net in nets: - r,c = config_dic['of_thread'].insert_task("update-net", net) - if r < 0: - print ':http_post_servers ERROR UPDATING NETS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + c - - - #look for dhcp ip address + # update nets + for net_id in nets: + try: + my.ovim.net_update_ofc_thread(net_id) + except ovim.ovimException as e: + raise ovim.ovimException("http_post_servers, Error updating network with id '{}', '{}'". + format(net_id, str(e)), HTTP_Internal_Server_Error) + except Exception as e: + raise ovim.ovimException("http_post_servers, Error updating network with id '{}', '{}'". + format(net_id, str(e)), HTTP_Internal_Server_Error) + + # look for dhcp ip address r2, c2 = my.db.get_table(FROM="ports", SELECT=["mac", "ip_address", "net_id"], WHERE={"instance_id": new_instance}) if r2 >0: for iface in c2: @@ -1806,12 +1810,20 @@ def http_server_action(server_id, tenant_id, action): if r1 < 0: print ' http_post_server_action error at server deletion ERROR resore-iface !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + c1 data={'result' : 'deleting in process, but ifaces cannot be restored!!!!!'} - for net in nets: - r1,c1 = config_dic['of_thread'].insert_task("update-net", net) - if r1 < 0: - print ' http_post_server_action error at server deletion ERROR UPDATING NETS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' + c1 - data={'result' : 'deleting in process, but openflow rules cannot be deleted!!!!!'} - #look for dhcp ip address + for net_id in nets: + try: + my.ovim.net_update_ofc_thread(net_id) + except ovim.ovimException as e: + raise ovim.ovimException("http_post_servers, Error updating network with id '{}', '{}'". + format(net_id, str(e)), HTTP_Internal_Server_Error) + except Exception as e: + raise ovim.ovimException("http_post_server_action error at server deletion " + "ERROR UPDATING NET '{}', '{}'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!". + format(net_id, str(e)), HTTP_Internal_Server_Error) + + data = {'result': 'deleting in process, but openflow rules cannot be deleted!!!!!'} + + # look for dhcp ip address if r2 >0 and config_dic.get("dhcp_server"): for iface in c2: if iface["net_id"] in config_dic["dhcp_nets"]: @@ -1973,7 +1985,7 @@ def http_put_network_id(network_id): http_content = format_in(network_update_schema) change_keys_http2db(http_content['network'], http2db_network) network = http_content['network'] - return my.ovim.edit_network(network_id, network) + return format_out(my.ovim.edit_network(network_id, network)) except ovim.ovimException as e: my.logger.error(str(e), exc_info=True) @@ -2184,9 +2196,9 @@ def http_put_openflow_id(network_id): data = {'result': str(result) + " nets updates"} return format_out(data) - +@bottle.route(url_base + '/networks/clear/openflow/', method='DELETE') @bottle.route(url_base + '/networks/clear/openflow', method='DELETE') -def http_clear_openflow_rules(): +def http_clear_openflow_rules(ofc_id=None): """ To make actions over the net. The action is to delete ALL openflow rules :return: @@ -2196,7 +2208,7 @@ def http_clear_openflow_rules(): if not my.admin: bottle.abort(HTTP_Unauthorized, "Needed admin privileges") try: - my.ovim.delete_openflow_rules() + my.ovim.delete_openflow_rules(ofc_id) except ovim.ovimException as e: my.logger.error(str(e), exc_info=True) bottle.abort(e.http_code, str(e)) @@ -2207,16 +2219,25 @@ def http_clear_openflow_rules(): data = {'result': " Clearing openflow rules in process"} return format_out(data) - +@bottle.route(url_base + '/networks/openflow/ports/', method='GET') @bottle.route(url_base + '/networks/openflow/ports', method='GET') -def http_get_openflow_ports(): +def http_get_openflow_ports(ofc_id=None): """ Obtain switch ports names of openflow controller :return: """ my = config_dic['http_threads'][threading.current_thread().name] - ports = my.ovim.get_openflow_ports() - data = {'ports': ports} + + try: + ports = my.ovim.get_openflow_ports(ofc_id) + data = {'ports': ports} + 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)) + return format_out(data) # # PORTS @@ -2415,3 +2436,4 @@ def delete_of_port_mapping(region): except Exception as e: my.logger.error(str(e), exc_info=True) bottle.abort(HTTP_Bad_Request, str(e)) +