diff options
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/multivimbroker/forwarder/views.py | 30 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/pub/utils/restcall.py | 12 |
2 files changed, 31 insertions, 11 deletions
diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py index e1013c7..ca93b8e 100644 --- a/multivimbroker/multivimbroker/forwarder/views.py +++ b/multivimbroker/multivimbroker/forwarder/views.py @@ -34,12 +34,31 @@ def route(request, vimid=''): status_code = status.HTTP_200_OK try: vim = get_vim_by_id(vimid) + if vim["type"] and vim["version"]: + pass - # if vim type is openstack, use latest "newton" version as default - if vim["type"] == "openstack": - vim["type"] = "multivim-newton" + except Exception as e: + logger.error("get_vim_by_id, exception: %s" % e) + return HttpResponse("Not a valid VIM instance", status=status.HTTP_404_NOT_FOUND) + + try: + if vim and vim["type"] == "openstack": + if vim["version"] == "kilo": + multivimdriver = "multivim-kilo" + elif vim["version"] == "newton": + multivimdriver = "multivim-newton" + else: + # if vim type is openstack, use latest "newton" version as default + multivimdriver = "multivim-newton" + elif vim and vim["type"] == "vmware": + multivimdriver = "multivim-vio" + else: + logger.error("wrong vim id: %s, return from extsys:%s" % + vimid, vim) + return HttpResponse("Not support VIM type", status=status.HTTP_404_NOT_FOUND) + + route_uri = re.sub('multivim', multivimdriver, request.get_full_path()) - route_uri = re.sub('multivim', vim["type"], request.get_full_path()) retcode, content, status_code = \ req_by_msb(route_uri, request.method, request.body) if retcode != 0: @@ -49,4 +68,5 @@ def route(request, vimid=''): except Exception as e: content = e status_code = status.HTTP_500_INTERNAL_SERVER_ERROR - return HttpResponse(content, status_code) + logger.error("exception: %s" % e) + return HttpResponse(content, status=status_code) diff --git a/multivimbroker/multivimbroker/pub/utils/restcall.py b/multivimbroker/multivimbroker/pub/utils/restcall.py index d1c7b77..0b76bae 100644 --- a/multivimbroker/multivimbroker/pub/utils/restcall.py +++ b/multivimbroker/multivimbroker/pub/utils/restcall.py @@ -28,8 +28,8 @@ logger = logging.getLogger(__name__) def call_req(base_url, user, passwd, auth_type, resource, method, content=''): callid = str(uuid.uuid1()) - logger.debug("[%s]call_req('%s','%s','%s',%s,'%s','%s','%s')" % ( - callid, base_url, user, passwd, auth_type, resource, method, content)) +# logger.debug("[%s]call_req('%s','%s','%s',%s,'%s','%s','%s')" % ( +# callid, base_url, user, passwd, auth_type, resource, method, content)) ret = None resp_status = '' try: @@ -42,10 +42,10 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content=''): http = httplib2.Http(ca_certs=ca_certs, disable_ssl_certificate_validation=(auth_type == rest_no_auth)) http.follow_all_redirects = True try: - logger.debug("request=%s)" % full_url) +# logger.debug("request=%s)" % full_url) resp, resp_content = http.request(full_url, method=method.upper(), body=content, headers=headers) resp_status, resp_body = resp['status'], resp_content.decode('UTF-8') - logger.debug("[%s][%d]status=%s,resp_body=%s)" % (callid, retry_times, resp_status, resp_body)) +# logger.debug("[%s][%d]status=%s,resp_body=%s)" % (callid, retry_times, resp_status, resp_body)) if resp_status in status_ok_list: ret = [0, resp_body, resp_status] else: @@ -53,7 +53,7 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content=''): break except Exception as ex: if 'httplib.ResponseNotReady' in str(sys.exc_info()): - logger.debug("retry_times=%d", retry_times) +# logger.debug("retry_times=%d", retry_times) logger.error(traceback.format_exc()) ret = [1, "Unable to connect to %s" % full_url, resp_status] continue @@ -71,7 +71,7 @@ def call_req(base_url, user, passwd, auth_type, resource, method, content=''): logger.error(traceback.format_exc()) ret = [4, str(sys.exc_info()), resp_status] - logger.debug("[%s]ret=%s" % (callid, str(ret))) +# logger.debug("[%s]ret=%s" % (callid, str(ret))) return ret |