Fixes 162. Re-use an existing flavor at openstack without EPA parameters 48/1048/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 30 Jan 2017 13:07:06 +0000 (14:07 +0100)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Mon, 30 Jan 2017 14:44:32 +0000 (15:44 +0100)
Change-Id: I675eab965fd00f86b0a5ce55944b121d45c9825d
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
nfvo.py
vimconn.py
vimconn_openstack.py

diff --git a/nfvo.py b/nfvo.py
index 21e5719..4eea277 100644 (file)
--- 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))
index 814be65..ad06dc8 100644 (file)
@@ -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={}):
index e94b96d..80ea09c 100644 (file)
@@ -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