From: tierno Date: Tue, 29 Aug 2017 09:43:46 +0000 (+0200) Subject: Some fixes at Affinity/antiaffinity X-Git-Tag: v3.0.0~17^2~7 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F03%2F2103%2F4;p=osm%2FRO.git Some fixes at Affinity/antiaffinity Change-Id: I7b30cf86bc244b223f502b07ad5054e6f0067547 Signed-off-by: tierno --- diff --git a/database_utils/migrate_mano_db.sh b/database_utils/migrate_mano_db.sh index b6e4f8e1..68727c02 100755 --- a/database_utils/migrate_mano_db.sh +++ b/database_utils/migrate_mano_db.sh @@ -190,7 +190,7 @@ fi #[ $OPENMANO_VER_NUM -ge 5009 ] && DB_VERSION=20 #0.5.9 => 20 #[ $OPENMANO_VER_NUM -ge 5015 ] && DB_VERSION=21 #0.5.15 => 21 #[ $OPENMANO_VER_NUM -ge 5016 ] && DB_VERSION=22 #0.5.16 => 22 -#[ $OPENMANO_VER_NUM -ge 5019 ] && DB_VERSION=23 #0.5.20 => 23 +#[ $OPENMANO_VER_NUM -ge 5020 ] && DB_VERSION=23 #0.5.20 => 23 #TODO ... put next versions here function upgrade_to_1(){ diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 66ea1b2d..9cd39950 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -1700,11 +1700,17 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc #myvim.new_vminstance(self,vimURI,tenant_id,name,description,image_id,flavor_id,net_dict) i = 0 for sce_vnf in scenarioDict['vnfs']: - nfv_availability_zones = [] + vnf_availability_zones = [] for vm in sce_vnf['vms']: vm_av = vm.get('availability_zone') - if vm_av and vm_av not in nfv_availability_zones: - nfv_availability_zones.append(vm_av) + if vm_av and vm_av not in vnf_availability_zones: + vnf_availability_zones.append(vm_av) + + # check if there is enough availability zones available at vim level. + if myvims[datacenter_id].availability_zone and vnf_availability_zones: + if len(vnf_availability_zones) > len(myvims[datacenter_id].availability_zone): + raise NfvoException('No enough availability zones at VIM for this deployment', HTTP_Bad_Request) + for vm in sce_vnf['vms']: i += 1 myVMDict = {} @@ -1793,14 +1799,14 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc #print ">>>>>>>>>>>>>>>>>>>>>>>>>>>" if 'availability_zone' in myVMDict: - counter_availability_zone = nfv_availability_zones.index(myVMDict['availability_zone']) + av_index = vnf_availability_zones.index(myVMDict['availability_zone']) else: - counter_availability_zone = None + av_index = None vm_id = myvim.new_vminstance(myVMDict['name'], myVMDict['description'], myVMDict.get('start', None), myVMDict['imageRef'], myVMDict['flavorRef'], myVMDict['networks'], - availavility_zone_index=counter_availability_zone, - nfv_availability_zones=nfv_availability_zones) + availability_zone_index=av_index, + availability_zone_list=vnf_availability_zones) #print "VIM vm instance id (server id) for scenario %s: %s" % (scenarioDict['name'],vm_id) vm['vim_id'] = vm_id rollbackList.append({'what':'vm','where':'vim','vim_id':datacenter_id,'uuid':vm_id}) @@ -2211,18 +2217,16 @@ def create_instance(mydb, tenant_id, instance_dict): sce_vnf_list = sorted(scenarioDict['vnfs'], key=lambda k: k['name']) #for sce_vnf in scenarioDict['vnfs']: for sce_vnf in sce_vnf_list: - nfv_availability_zones = [] + vnf_availability_zones = [] for vm in sce_vnf['vms']: vm_av = vm.get('availability_zone') - if vm_av and vm_av not in nfv_availability_zones: - nfv_availability_zones.append(vm_av) + if vm_av and vm_av not in vnf_availability_zones: + vnf_availability_zones.append(vm_av) # check if there is enough availability zones available at vim level. - if myvims[datacenter_id].availability_zone: - vim_availability_zones = myvims[datacenter_id].availability_zone - nfv_availability_zones_num = len(vim_availability_zones) - if len(nfv_availability_zones) > nfv_availability_zones_num: - raise NfvoException('No enough availablity zones for this deployment', HTTP_Bad_Request) + if myvims[datacenter_id].availability_zone and vnf_availability_zones: + if len(vnf_availability_zones) > len(myvims[datacenter_id].availability_zone): + raise NfvoException('No enough availability zones at VIM for this deployment', HTTP_Bad_Request) if sce_vnf.get("datacenter"): vim = myvims[ sce_vnf["datacenter"] ] @@ -2340,14 +2344,14 @@ def create_instance(mydb, tenant_id, instance_dict): else: cloud_config_vm = cloud_config - if 'availability_zone' in myVMDict and myVMDict.get('availability_zone'): - counter_availability_zone = nfv_availability_zones.index(myVMDict['availability_zone']) + if myVMDict.get('availability_zone'): + av_index = vnf_availability_zones.index(myVMDict['availability_zone']) else: - counter_availability_zone = None + av_index = None task = new_task("new-vm", (myVMDict['name'], myVMDict['description'], myVMDict.get('start', None), myVMDict['imageRef'], myVMDict['flavorRef'], myVMDict['networks'], - cloud_config_vm, myVMDict['disks'], counter_availability_zone, - nfv_availability_zones), depends=task_depends) + cloud_config_vm, myVMDict['disks'], av_index, + vnf_availability_zones), depends=task_depends) instance_tasks[task["id"]] = task tasks_to_launch[myvim_thread_id].append(task) vm_id = task["id"] diff --git a/osm_ro/vimconn.py b/osm_ro/vimconn.py index b0a40114..a669612b 100644 --- a/osm_ro/vimconn.py +++ b/osm_ro/vimconn.py @@ -356,7 +356,7 @@ class vimconnector(): raise vimconnNotImplemented( "Should have implemented this" ) def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None, - availavility_zone_index=None, nfv_availability_zones=None): + availability_zone_index=None, availability_zone_list=None): """Adds a VM instance to VIM Params: 'start': (boolean) indicates if VM must start or created in pause mode. @@ -399,9 +399,9 @@ class vimconnector(): 'disk_list': (optional) list with additional disks to the VM. Each item is a dict with: 'image_id': (optional). VIM id of an existing image. If not provided an empty disk must be mounted 'size': (mandatory) string with the size of the disk in GB - availavility_zone_index: Index of nfv_availability_zones to use for this this VM - nfv_availability_zones: list of availability zones given by user in the VNFC descriptor. Ignore if - availability_zone_index is None + availability_zone_index: Index of availability_zone_list to use for this this VM. None if not AV required + availability_zone_list: list of availability zones given by user in the VNFD descriptor. Ignore if + availability_zone_index is None Returns the instance identifier or raises an exception on error """ raise vimconnNotImplemented( "Should have implemented this" ) diff --git a/osm_ro/vimconn_aws.py b/osm_ro/vimconn_aws.py index 6621345b..3cccbfcf 100644 --- a/osm_ro/vimconn_aws.py +++ b/osm_ro/vimconn_aws.py @@ -590,7 +590,7 @@ class vimconnector(vimconn.vimconnector): self.format_vimconn_exception(e) def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, - disk_list=None): + disk_list=None, availability_zone_index=None, availability_zone_list=None): """Create a new VM/instance in AWS Params: name decription diff --git a/osm_ro/vimconn_openstack.py b/osm_ro/vimconn_openstack.py index c66d74cd..4ac58286 100644 --- a/osm_ro/vimconn_openstack.py +++ b/osm_ro/vimconn_openstack.py @@ -732,36 +732,38 @@ class vimconnector(vimconn.vimconnector): else: self.availability_zone = self._get_openstack_availablity_zones() - def _get_vm_availavility_zone(self, availavility_zone_index, nfv_availability_zones): + def _get_vm_availability_zone(self, availability_zone_index, availability_zone_list): """ - Return a list with all availability zones create during datacenter attach. - :return: List with availability zones + Return thge availability zone to be used by the created VM. + :return: The VIM availability zone to be used or None """ - openstack_avilability_zone = self.availability_zone - - # check if VIM offer enough availability zones describe in the VNFC - if self.availability_zone and availavility_zone_index is not None \ - and 0 <= len(nfv_availability_zones) <= len(self.availability_zone): - - if nfv_availability_zones: - vnf_azone = nfv_availability_zones[availavility_zone_index] - zones_available = [] - - for nfv_zone in nfv_availability_zones: - for vim_zone in openstack_avilability_zone: - if nfv_zone is vim_zone: - zones_available.append(nfv_zone) - - if len(zones_available) == len(openstack_avilability_zone) and vnf_azone in openstack_avilability_zone: - return vnf_azone - else: - return openstack_avilability_zone[availavility_zone_index] + if availability_zone_index is None: + if not self.config.get('availability_zone'): + return None + elif isinstance(self.config.get('availability_zone'), str): + return self.config['availability_zone'] + else: + # TODO consider using a different parameter at config for default AV and AV list match + return self.config['availability_zone'][0] + + vim_availability_zones = self.availability_zone + # check if VIM offer enough availability zones describe in the VNFD + if vim_availability_zones and len(availability_zone_list) <= len(vim_availability_zones): + # check if all the names of NFV AV match VIM AV names + match_by_index = False + for av in availability_zone_list: + if av not in vim_availability_zones: + match_by_index = True + break + if match_by_index: + return vim_availability_zones[availability_zone_index] + else: + return availability_zone_list[availability_zone_index] else: - raise vimconn.vimconnConflictException("No enough availablity zones for this deployment") - return None + raise vimconn.vimconnConflictException("No enough availability zones at VIM for this deployment") - def new_vminstance(self, name, description, start, image_id, flavor_id, net_list,cloud_config=None,disk_list=None, - availavility_zone_index=None, nfv_availability_zones=None): + def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None, + availability_zone_index=None, availability_zone_list=None): '''Adds a VM instance to VIM Params: start: indicates if VM must start or boot in pause mode. Ignored @@ -793,8 +795,9 @@ class vimconnector(vimconn.vimconnector): 'disk_list': (optional) list with additional disks to the VM. Each item is a dict with: 'image_id': (optional). VIM id of an existing image. If not provided an empty disk must be mounted 'size': (mandatory) string with the size of the disk in GB - availavility_zone_index:counter for instance order in vim availability_zones availables - nfv_availability_zones: Lost given by user in the VNFC descriptor. + availability_zone_index: Index of availability_zone_list to use for this this VM. None if not AV required + availability_zone_list: list of availability zones given by user in the VNFD descriptor. Ignore if + availability_zone_index is None #TODO ip, security groups Returns the instance identifier ''' @@ -967,7 +970,7 @@ class vimconnector(vimconn.vimconnector): raise vimconn.vimconnException('Timeout creating volumes for instance ' + name, http_code=vimconn.HTTP_Request_Timeout) # get availability Zone - vm_av_zone = self._get_vm_availavility_zone(availavility_zone_index, nfv_availability_zones) + vm_av_zone = self._get_vm_availability_zone(availability_zone_index, availability_zone_list) self.logger.debug("nova.servers.create({}, {}, {}, nics={}, meta={}, security_groups={}, " "availability_zone={}, key_name={}, userdata={}, config_drive={}, " diff --git a/osm_ro/vimconn_openvim.py b/osm_ro/vimconn_openvim.py index e722dc8d..abfffbe0 100644 --- a/osm_ro/vimconn_openvim.py +++ b/osm_ro/vimconn_openvim.py @@ -785,7 +785,8 @@ 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, disk_list=None): + def new_vminstance(self, name, description, start, image_id, flavor_id, net_list, cloud_config=None, disk_list=None, + availability_zone_index=None, availability_zone_list=None): '''Adds a VM instance to VIM Params: start: indicates if VM must start or boot in pause mode. Ignored diff --git a/osm_ro/vimconn_vmware.py b/osm_ro/vimconn_vmware.py index 701008f2..7fd7f9d1 100644 --- a/osm_ro/vimconn_vmware.py +++ b/osm_ro/vimconn_vmware.py @@ -1373,7 +1373,7 @@ class vimconnector(vimconn.vimconnector): return None def new_vminstance(self, name=None, description="", start=False, image_id=None, flavor_id=None, net_list={}, - cloud_config=None, disk_list=None): + cloud_config=None, disk_list=None, availability_zone_index=None, availability_zone_list=None): """Adds a VM instance to VIM Params: start: indicates if VM must start or boot in pause mode. Ignored