X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=vimconn_openvim.py;h=62c167748015204a31387e373f8537202ba14b86;hb=29c23e2df0e21e31a5af87c905afd27a30b5a609;hp=d0549adf3b74c1846ead9a90034f32fc8d0b9f7a;hpb=a4e1a6ed87de04788ec6855fc8a5e722914e4f03;p=osm%2FRO.git diff --git a/vimconn_openvim.py b/vimconn_openvim.py index d0549adf..62c16774 100644 --- a/vimconn_openvim.py +++ b/vimconn_openvim.py @@ -35,6 +35,7 @@ import logging from openmano_schemas import id_schema, name_schema, nameshort_schema, description_schema, \ vlan1000_schema, integer0_schema from jsonschema import validate as js_v, exceptions as js_e +from urllib import quote '''contain the openvim virtual machine status to openmano status''' vmStatus2manoFormat={'ACTIVE':'ACTIVE', @@ -326,7 +327,7 @@ class vimconnector(vimconn.vimconnector): 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('mano.vim.openvim') + self.logger = logging.getLogger('openmano.vim.openvim') if tenant_id: self.tenant = tenant_id @@ -346,7 +347,7 @@ class vimconnector(vimconn.vimconnector): if self.tenant: return self.tenant - url = self.url+'/tenants?name='+ self.tenant_name + url = self.url+'/tenants?name='+ quote(self.tenant_name) self.logger.info("Getting VIM tenant_id GET %s", url) vim_response = requests.get(url, headers = self.headers_req) self._check_http_request_response(vim_response) @@ -480,7 +481,7 @@ class vimconnector(vimconn.vimconnector): except requests.exceptions.RequestException as e: self._format_request_exception(e) - def new_network(self,net_name,net_type, shared=False, **vim_specific): + def new_network(self,net_name, net_type, ip_profile=None, shared=False, **vim_specific): '''Adds a tenant network to VIM''' '''Returns the network identifier''' try: @@ -590,8 +591,10 @@ class vimconnector(vimconn.vimconnector): '''Adds a tenant flavor to VIM''' '''Returns the flavor identifier''' try: + new_flavor_dict = flavor_data.copy() + new_flavor_dict["name"] = flavor_data["name"][:64] self._get_my_tenant() - payload_req = json.dumps({'flavor': flavor_data}) + payload_req = json.dumps({'flavor': new_flavor_dict}) url = self.url+'/'+self.tenant+'/flavors' self.logger.info("Adding a new VIM flavor POST %s", url) vim_response = requests.post(url, headers = self.headers_req, data=payload_req) @@ -646,7 +649,7 @@ class vimconnector(vimconn.vimconnector): ''' Adds a tenant image to VIM, returns image_id''' try: self._get_my_tenant() - new_image_dict={'name': image_dict['name']} + new_image_dict={'name': image_dict['name'][:64]} if image_dict.get('description'): new_image_dict['description'] = image_dict['description'] if image_dict.get('metadata'): @@ -687,10 +690,10 @@ 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='+path + url=self.url + '/' + self.tenant + '/images?path='+quote(path) self.logger.info("Getting images GET %s", url) vim_response = requests.get(url) self._check_http_request_response(vim_response) @@ -709,6 +712,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''' @@ -745,7 +778,7 @@ class vimconnector(vimconn.vimconnector): #print text return -vim_response.status_code,text - def new_vminstance(self,name,description,start,image_id,flavor_id,net_list, cloud_config=None): + def new_vminstance(self,name,description,start,image_id,flavor_id,net_list, cloud_config=None, disk_list=None): '''Adds a VM instance to VIM Params: start: indicates if VM must start or boot in pause mode. Ignored @@ -780,7 +813,7 @@ class vimconnector(vimconn.vimconnector): if net.get("model"): net_dict["model"] = net["model"] if net.get("mac_address"): net_dict["mac_address"] = net["mac_address"] virtio_net_list.append(net_dict) - payload_dict={ "name": name, + payload_dict={ "name": name[:64], "description": description, "imageRef": image_id, "flavorRef": flavor_id, @@ -898,7 +931,7 @@ class vimconnector(vimconn.vimconnector): #get interfaces info try: management_ip = False - url2 = self.url+'/ports?device_id='+ vm_id + url2 = self.url+'/ports?device_id='+ quote(vm_id) self.logger.info("Getting PORTS GET %s", url2) vim_response2 = requests.get(url2, headers = self.headers_req) self._check_http_request_response(vim_response2) @@ -909,7 +942,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"]: