#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))
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:
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={}):
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