X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=vimconn_openvim.py;h=e86b54db2734fa6d363252f089d86f603a1064af;hb=06e6c396413630640cafae3488442a0869f1642d;hp=62c167748015204a31387e373f8537202ba14b86;hpb=7432e7c67d269c65dd3528d5cd660ebe7c426fa5;p=osm%2FRO.git diff --git a/vimconn_openvim.py b/vimconn_openvim.py index 62c16774..e86b54db 100644 --- a/vimconn_openvim.py +++ b/vimconn_openvim.py @@ -323,11 +323,13 @@ get_processor_rankings_response_schema = { } class vimconnector(vimconn.vimconnector): - def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None,log_level="DEBUG",config={}): + def __init__(self, uuid, name, tenant_id, tenant_name, url, url_admin=None, user=None, passwd=None, + log_level="DEBUG", config={}, persistent_info={}): vimconn.vimconnector.__init__(self, uuid, name, tenant_id, tenant_name, url, url_admin, user, passwd, log_level, config) self.tenant = None self.headers_req = {'content-type': 'application/json'} self.logger = logging.getLogger('openmano.vim.openvim') + self.persistent_info = persistent_info if tenant_id: self.tenant = tenant_id @@ -377,7 +379,7 @@ class vimconnector(vimconn.vimconnector): js_v(client_data, schema) #print "Input data: ", str(client_data) return True, client_data - except js_e.ValidationError, exc: + except js_e.ValidationError as exc: print "validate_in error, jsonschema exception ", exc.message, "at", exc.path return False, ("validate_in error, jsonschema exception ", exc.message, "at", exc.path) @@ -481,7 +483,7 @@ class vimconnector(vimconn.vimconnector): except requests.exceptions.RequestException as e: self._format_request_exception(e) - def new_network(self,net_name, net_type, ip_profile=None, shared=False, **vim_specific): + def new_network(self,net_name, net_type, ip_profile=None, shared=False, vlan=None): #, **vim_specific): '''Adds a tenant network to VIM''' '''Returns the network identifier''' try: @@ -489,7 +491,9 @@ class vimconnector(vimconn.vimconnector): if net_type=="bridge": net_type="bridge_data" payload_req = {"name": net_name, "type": net_type, "tenant_id": self.tenant, "shared": shared} - payload_req.update(vim_specific) + if vlan: + payload_req["provider:vlan"] = vlan + # payload_req.update(vim_specific) url = self.url+'/networks' self.logger.info("Adding a new network POST: %s DATA: %s", url, str(payload_req)) vim_response = requests.post(url, headers = self.headers_req, data=json.dumps({"network": payload_req}) ) @@ -753,7 +757,7 @@ class vimconnector(vimconn.vimconnector): payload_req = vm_data try: vim_response = requests.post(self.url+'/'+self.tenant+'/servers', headers = self.headers_req, data=payload_req) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: print "new_vminstancefromJSON Exception: ", e.args return -vimconn.HTTP_Not_Found, str(e.args[0]) print vim_response @@ -795,6 +799,7 @@ class vimconnector(vimconn.vimconnector): #TODO ip, security groups Returns the instance identifier ''' + self.logger.debug("new_vminstance input: image='%s' flavor='%s' nics='%s'", image_id, flavor_id, str(net_list)) try: self._get_my_tenant() # net_list = [] @@ -1079,7 +1084,7 @@ class vimconnector(vimconn.vimconnector): url=self.url+'/hosts' try: vim_response = requests.get(url) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: print "get_hosts_info Exception: ", e.args return -vimconn.HTTP_Not_Found, str(e.args[0]) print "vim get", url, "response:", vim_response.status_code, vim_response.json() @@ -1101,7 +1106,7 @@ class vimconnector(vimconn.vimconnector): url=self.url+'/hosts/'+host['id'] try: vim_response = requests.get(url) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: print "get_hosts_info Exception: ", e.args return -vimconn.HTTP_Not_Found, str(e.args[0]) print "vim get", url, "response:", vim_response.status_code, vim_response.json() @@ -1123,7 +1128,7 @@ class vimconnector(vimconn.vimconnector): url=self.url+'/hosts' try: vim_response = requests.get(url) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: print "get_hosts Exception: ", e.args return -vimconn.HTTP_Not_Found, str(e.args[0]) print "vim get", url, "response:", vim_response.status_code, vim_response.json() @@ -1144,7 +1149,7 @@ class vimconnector(vimconn.vimconnector): url=self.url+'/' + vim_tenant + '/servers?hostId='+host['id'] try: vim_response = requests.get(url) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: print "get_hosts Exception: ", e.args return -vimconn.HTTP_Not_Found, str(e.args[0]) print "vim get", url, "response:", vim_response.status_code, vim_response.json() @@ -1164,7 +1169,7 @@ class vimconnector(vimconn.vimconnector): url=self.url+'/processor_ranking' try: vim_response = requests.get(url) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: print "get_processor_rankings Exception: ", e.args return -vimconn.HTTP_Not_Found, str(e.args[0]) print "vim get", url, "response:", vim_response.status_code, vim_response.json() @@ -1207,7 +1212,7 @@ class vimconnector(vimconn.vimconnector): payload_req = port_data try: vim_response = requests.post(self.url_admin+'/ports', headers = self.headers_req, data=payload_req) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: self.logger.error("new_external_port Exception: ", str(e)) return -vimconn.HTTP_Not_Found, str(e.args[0]) print vim_response @@ -1241,7 +1246,7 @@ class vimconnector(vimconn.vimconnector): payload_req = '{"network":{"name": "' + net_name + '","shared":true,"type": "' + net_type + '"}}' try: vim_response = requests.post(self.url+'/networks', headers = self.headers_req, data=payload_req) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: self.logger.error( "new_external_network Exception: ", e.args) return -vimconn.HTTP_Not_Found, str(e.args[0]) print vim_response @@ -1281,7 +1286,7 @@ class vimconnector(vimconn.vimconnector): url= self.url try: vim_response = requests.put(url +'/ports/'+port_id, headers = self.headers_req, data=payload_req) - except requests.exceptions.RequestException, e: + except requests.exceptions.RequestException as e: print "connect_port_network Exception: ", e.args return -vimconn.HTTP_Not_Found, str(e.args[0]) print vim_response