X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=vimconn_openvim.py;h=d4155320c2b488c25be795b59a0f7eaeddff2cd4;hb=1f3a67138592443a8bd68ab936e071cb5bccda55;hp=ee0f9600628da17c014231b79a054589d6550509;hpb=73ad9e4d8ceff08bd6a9e799cb8b48ad914cd35a;p=osm%2FRO.git diff --git a/vimconn_openvim.py b/vimconn_openvim.py index ee0f9600..d4155320 100644 --- a/vimconn_openvim.py +++ b/vimconn_openvim.py @@ -688,7 +688,7 @@ class vimconnector(vimconn.vimconnector): def get_image_id_from_path(self, path): - '''Get the image id from image path in the VIM database''' + '''Get the image id from image path in the VIM database. Returns the image_id''' try: self._get_my_tenant() url=self.url + '/' + self.tenant + '/images?path='+quote(path) @@ -710,6 +710,36 @@ class vimconnector(vimconn.vimconnector): except (requests.exceptions.RequestException, js_e.ValidationError) as e: self._format_request_exception(e) + def get_image_list(self, filter_dict={}): + '''Obtain tenant images from VIM + Filter_dict can be: + name: image name + id: image uuid + checksum: image checksum + location: image path + Returns the image list of dictionaries: + [{}, ...] + List can be empty + ''' + try: + self._get_my_tenant() + filterquery=[] + filterquery_text='' + for k,v in filter_dict.iteritems(): + filterquery.append(str(k)+'='+str(v)) + if len(filterquery)>0: + filterquery_text='?'+ '&'.join(filterquery) + url = self.url+'/'+self.tenant+'/images'+filterquery_text + self.logger.info("Getting image list GET %s", url) + vim_response = requests.get(url, headers = self.headers_req) + self._check_http_request_response(vim_response) + self.logger.debug(vim_response.text) + #print json.dumps(vim_response.json(), indent=4) + response = vim_response.json() + return response['images'] + except (requests.exceptions.RequestException, js_e.ValidationError) as e: + self._format_request_exception(e) + def new_vminstancefromJSON(self, vm_data): '''Adds a VM instance to VIM''' '''Returns the instance identifier''' @@ -910,7 +940,7 @@ class vimconnector(vimconn.vimconnector): interface={} interface['vim_info'] = yaml.safe_dump(port) interface["mac_address"] = port.get("mac_address") - interface["vim_net_id"] = port["network_id"] + interface["vim_net_id"] = port.get("network_id") interface["vim_interface_id"] = port["id"] interface["ip_address"] = port.get("ip_address") if interface["ip_address"]: