X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_openvim%2Fovim.py;h=a0c380d3388421caf1fa9f9c0edfe6f666f77f76;hb=dc7a2da1e4f9e6db785f4a4d700d5b8eaa42c70a;hp=a4108b6af5d302c1e3b690f7f552b628ae47dc2b;hpb=27c1c9221acccde1378a12404054f1e545de8ca5;p=osm%2Fopenvim.git diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py index a4108b6..a0c380d 100755 --- a/osm_openvim/ovim.py +++ b/osm_openvim/ovim.py @@ -22,21 +22,15 @@ # contact with: nfvlabs@tid.es ## -''' +""" This is the thread for the http server North API. Two thread will be launched, with normal and administrative permissions. -''' - -__author__ = "Alfonso Tierno, Leonardo Mirabal" -__date__ = "$06-Feb-2017 12:07:15$" -__version__ = "0.5.10-r526" -version_date = "Apr 2017" -database_version = "0.17" #expected database schema version +""" import threading import vim_db import logging -import imp +# import imp import argparse from netaddr import IPNetwork from jsonschema import validate as js_v, exceptions as js_e @@ -45,6 +39,11 @@ import dhcp_thread as dt import openflow_thread as oft import openflow_conn +__author__ = "Alfonso Tierno, Leonardo Mirabal" +__date__ = "$06-Feb-2017 12:07:15$" +__version__ = "0.5.11-r527" +version_date = "Apr 2017" +database_version = "0.17" #expected database schema version HTTP_Bad_Request = 400 HTTP_Unauthorized = 401 @@ -371,27 +370,29 @@ class ovim(): module = temp_dict['of_controller'] if module not in ovim.of_module: - module_info = imp.find_module(module) - of_conn_module = imp.load_module("OF_conn", *module_info) - ovim.of_module[module] = of_conn_module + for base in ("", "osm_openvim.", "lib_osm_openvim."): + try: + pkg = __import__(base + module) + if base: + of_conn_module = getattr(pkg, module) + else: + of_conn_module = pkg + ovim.of_module[module] = of_conn_module + self.logger.debug("Module load from {}".format(base + module)) + break + except Exception as e: + self.logger.warning("Module {} not found {}".format(base + module, e)) + else: + self.logger.error("Cannot open openflow controller module of type '%s'", module) + raise ovimException("Cannot open openflow controller of type module '{}'" + "Revise it is installed".format(module), + HTTP_Internal_Server_Error) else: of_conn_module = ovim.of_module[module] - - try: - return of_conn_module.OF_conn(temp_dict) - except Exception as e: - self.logger.error("Cannot open the Openflow controller '%s': %s", type(e).__name__, str(e)) - if module_info and module_info[0]: - file.close(module_info[0]) - raise ovimException("Cannot open the Openflow controller '{}': '{}'".format(type(e).__name__, str(e)), - HTTP_Internal_Server_Error) - except (IOError, ImportError) as e: - if module_info and module_info[0]: - file.close(module_info[0]) - self.logger.error("Cannot open openflow controller module '%s'; %s: %s; revise 'of_controller' " - "field of configuration file.", module, type(e).__name__, str(e)) - raise ovimException("Cannot open openflow controller module '{}'; {}: {}; revise 'of_controller' " - "field of configuration file.".format(module, type(e).__name__, str(e)), + return of_conn_module.OF_conn(temp_dict) + except Exception as e: + self.logger.error("Cannot open the Openflow controller '%s': %s", type(e).__name__, str(e)) + raise ovimException("Cannot open the Openflow controller '{}': '{}'".format(type(e).__name__, str(e)), HTTP_Internal_Server_Error) def _create_ofc_thread(self, of_conn, ofc_uuid="Default"):