From: tierno Date: Mon, 30 Jan 2017 13:07:06 +0000 (+0100) Subject: Fixes 162. Re-use an existing flavor at openstack without EPA parameters X-Git-Tag: v1.1.0~9 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F48%2F1048%2F3;p=osm%2FRO.git Fixes 162. Re-use an existing flavor at openstack without EPA parameters Change-Id: I675eab965fd00f86b0a5ce55944b121d45c9825d Signed-off-by: tierno --- diff --git a/nfvo.py b/nfvo.py index 21e57195..4eea2770 100644 --- a/nfvo.py +++ b/nfvo.py @@ -465,9 +465,16 @@ def create_or_use_flavor(mydb, vims, flavor_dict, rollback_list, only_create_at_ #create flavor at vim logger.debug("nfvo.create_or_use_flavor() adding flavor to VIM %s", vim["name"]) try: - flavor_vim_id = vim.new_flavor(flavor_dict) - rollback_list.append({"where":"vim", "vim_id": vim_id, "what":"flavor","uuid":flavor_vim_id}) - flavor_created="true" + flavor_vim_id = None + flavor_vim_id=vim.get_flavor_id_from_data(flavor_dict) + flavor_create="false" + except vimconn.vimconnException as e: + pass + try: + if not flavor_vim_id: + flavor_vim_id = vim.new_flavor(flavor_dict) + rollback_list.append({"where":"vim", "vim_id": vim_id, "what":"flavor","uuid":flavor_vim_id}) + flavor_created="true" except vimconn.vimconnException as e: if return_on_error: logger.error("Error creating flavor at VIM %s: %s.", vim["name"], str(e)) diff --git a/vimconn.py b/vimconn.py index 814be65a..ad06dc8b 100644 --- a/vimconn.py +++ b/vimconn.py @@ -242,7 +242,13 @@ class vimconnector(): Returns the flavor dict details {'id':<>, 'name':<>, other vim specific } #TODO to concrete ''' raise vimconnNotImplemented( "Should have implemented this" ) - + + def get_flavor_id_from_data(self, flavor_dict): + """Obtain flavor id that match the flavor description + Returns the flavor_id or raises a vimconnNotFoundException + """ + raise vimconnNotImplemented( "Should have implemented this" ) + def new_flavor(self, flavor_data): '''Adds a tenant flavor to VIM flavor_data contains a dictionary with information, keys: @@ -287,7 +293,9 @@ class vimconnector(): raise vimconnNotImplemented( "Should have implemented this" ) def get_image_id_from_path(self, path): - '''Get the image id from image path in the VIM database. Returns the image_id''' + """Get the image id from image path in the VIM database. + Returns the image_id or raises a vimconnNotFoundException + """ raise vimconnNotImplemented( "Should have implemented this" ) def get_image_list(self, filter_dict={}): diff --git a/vimconn_openstack.py b/vimconn_openstack.py index e94b96d8..80ea09c6 100644 --- a/vimconn_openstack.py +++ b/vimconn_openstack.py @@ -464,6 +464,38 @@ class vimconnector(vimconn.vimconnector): except (nvExceptions.NotFound, nvExceptions.ClientException, ksExceptions.ClientException, ConnectionError) as e: self._format_exception(e) + def get_flavor_id_from_data(self, flavor_dict): + """Obtain flavor id that match the flavor description + Returns the flavor_id or raises a vimconnNotFoundException + """ + try: + self._reload_connection() + numa=None + numas = flavor_dict.get("extended",{}).get("numas") + if numas: + #TODO + raise vimconn.vimconnNotFoundException("Flavor with EPA still not implemted") + # if len(numas) > 1: + # raise vimconn.vimconnNotFoundException("Cannot find any flavor with more than one numa") + # numa=numas[0] + # numas = extended.get("numas") + for flavor in self.nova.flavors.list(): + epa = flavor.get_keys() + if epa: + continue + #TODO + if flavor.ram != flavor_dict["ram"]: + continue + if flavor.vcpus != flavor_dict["vcpus"]: + continue + if flavor.disk != flavor_dict["disk"]: + continue + return flavor.id + raise vimconn.vimconnNotFoundException("Cannot find any flavor matching '{}'".format(str(flavor_dict))) + except (nvExceptions.NotFound, nvExceptions.ClientException, ksExceptions.ClientException, ConnectionError) as e: + self._format_exception(e) + + def new_flavor(self, flavor_data, change_name_if_used=True): '''Adds a tenant flavor to openstack VIM if change_name_if_used is True, it will change name in case of conflict, because it is not supported name repetition