X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=RO-VIM-openstack%2Fosm_rovim_openstack%2Fvimconn_openstack.py;h=3379f1ae3e895e48f7bc7f4fd7eb3b4994a0cdfe;hb=2a9edc77102f0ec1db31afc0a6fd6aa948d48c57;hp=dcbf5cad4c0edbc06c8b8ee57489e7e4d769bf6b;hpb=b383aa7029e128c646516f9f97599bb522d6eedc;p=osm%2FRO.git diff --git a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py index dcbf5cad..3379f1ae 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py @@ -1200,7 +1200,7 @@ class vimconnector(vimconn.VimConnector): flavor.vcpus, flavor.disk, flavor.ephemeral, - flavor.swap, + flavor.swap if isinstance(flavor.swap, int) else 0, ) if flavor_data == flavor_target: return flavor.id @@ -1291,9 +1291,6 @@ class vimconnector(vimconn.VimConnector): extra_specs["hw:numa_mempolicy"] = "strict" if self.vim_type == "VIO": - extra_specs[ - "vmware:extra_config" - ] = '{"numa.nodeAffinity":"0"}' extra_specs["vmware:latency_sensitivity_level"] = "high" for numa in numas: @@ -1349,6 +1346,26 @@ class vimconnector(vimconn.VimConnector): extended.get("disk-io-quota"), "disk_io", extra_specs ) + # Set the mempage size as specified in the descriptor + if extended.get("mempage-size"): + if extended.get("mempage-size") == "LARGE": + extra_specs["hw:mem_page_size"] = "large" + elif extended.get("mempage-size") == "SMALL": + extra_specs["hw:mem_page_size"] = "small" + elif extended.get("mempage-size") == "SIZE_2MB": + extra_specs["hw:mem_page_size"] = "2MB" + elif extended.get("mempage-size") == "SIZE_1GB": + extra_specs["hw:mem_page_size"] = "1GB" + elif extended.get("mempage-size") == "PREFER_LARGE": + extra_specs["hw:mem_page_size"] = "any" + else: + # The validations in NBI should make reaching here not possible. + # If this message is shown, check validations + self.logger.debug( + "Invalid mempage-size %s. Will be ignored", + extended.get("mempage-size"), + ) + # create flavor new_flavor = self.nova.flavors.create( name=name, @@ -1681,6 +1698,7 @@ class vimconnector(vimconn.VimConnector): start, image_id, flavor_id, + affinity_group_list, net_list, cloud_config=None, disk_list=None, @@ -1690,7 +1708,9 @@ class vimconnector(vimconn.VimConnector): """Adds a VM instance to VIM Params: start: indicates if VM must start or boot in pause mode. Ignored - image_id,flavor_id: iamge and flavor uuid + image_id,flavor_id: image and flavor uuid + affinity_group_list: list of affinity groups, each one is a dictionary. + Ignore if empty. net_list: list of interfaces, each one is a dictionary with: name: net_id: network uuid to connect @@ -1862,8 +1882,14 @@ class vimconnector(vimconn.VimConnector): # cloud config config_drive, userdata = self._create_user_data(cloud_config) + # get availability Zone + vm_av_zone = self._get_vm_availability_zone( + availability_zone_index, availability_zone_list + ) + # Create additional volumes in case these are present in disk_list base_disk_index = ord("b") + boot_volume_id = None if disk_list: block_device_mapping = {} for disk in disk_list: @@ -1873,15 +1899,21 @@ class vimconnector(vimconn.VimConnector): ] else: if "image_id" in disk: + base_disk_index = ord("a") volume = self.cinder.volumes.create( size=disk["size"], name=name + "_vd" + chr(base_disk_index), imageRef=disk["image_id"], + # Make sure volume is in the same AZ as the VM to be attached to + availability_zone=vm_av_zone, ) + boot_volume_id = volume.id else: volume = self.cinder.volumes.create( size=disk["size"], name=name + "_vd" + chr(base_disk_index), + # Make sure volume is in the same AZ as the VM to be attached to + availability_zone=vm_av_zone, ) created_items["volume:" + str(volume.id)] = True @@ -1909,16 +1941,22 @@ class vimconnector(vimconn.VimConnector): "Timeout creating volumes for instance " + name, http_code=vimconn.HTTP_Request_Timeout, ) + if boot_volume_id: + self.cinder.volumes.set_bootable(boot_volume_id, True) - # get availability Zone - vm_av_zone = self._get_vm_availability_zone( - availability_zone_index, availability_zone_list - ) + # Manage affinity groups/server groups + server_group_id = None + scheduller_hints = {} + + if affinity_group_list: + # Only first id on the list will be used. Openstack restriction + server_group_id = affinity_group_list[0]["affinity_group_id"] + scheduller_hints["group"] = server_group_id self.logger.debug( "nova.servers.create({}, {}, {}, nics={}, security_groups={}, " "availability_zone={}, key_name={}, userdata={}, config_drive={}, " - "block_device_mapping={})".format( + "block_device_mapping={}, server_group={})".format( name, image_id, flavor_id, @@ -1929,6 +1967,7 @@ class vimconnector(vimconn.VimConnector): userdata, config_drive, block_device_mapping, + server_group_id, ) ) server = self.nova.servers.create( @@ -1943,6 +1982,7 @@ class vimconnector(vimconn.VimConnector): userdata=userdata, config_drive=config_drive, block_device_mapping=block_device_mapping, + scheduler_hints=scheduller_hints, ) # , description=description) vm_start_time = time.time() @@ -3444,3 +3484,60 @@ class vimconnector(vimconn.VimConnector): classification_dict[classification_id] = classification return classification_dict + + def new_affinity_group(self, affinity_group_data): + """Adds a server group to VIM + affinity_group_data contains a dictionary with information, keys: + name: name in VIM for the server group + type: affinity or anti-affinity + scope: Only nfvi-node allowed + Returns the server group identifier""" + self.logger.debug("Adding Server Group '%s'", str(affinity_group_data)) + + try: + name = affinity_group_data["name"] + policy = affinity_group_data["type"] + + self._reload_connection() + new_server_group = self.nova.server_groups.create(name, policy) + + return new_server_group.id + except ( + ksExceptions.ClientException, + nvExceptions.ClientException, + ConnectionError, + KeyError, + ) as e: + self._format_exception(e) + + def get_affinity_group(self, affinity_group_id): + """Obtain server group details from the VIM. Returns the server group detais as a dict""" + self.logger.debug("Getting flavor '%s'", affinity_group_id) + try: + self._reload_connection() + server_group = self.nova.server_groups.find(id=affinity_group_id) + + return server_group.to_dict() + except ( + nvExceptions.NotFound, + nvExceptions.ClientException, + ksExceptions.ClientException, + ConnectionError, + ) as e: + self._format_exception(e) + + def delete_affinity_group(self, affinity_group_id): + """Deletes a server group from the VIM. Returns the old affinity_group_id""" + self.logger.debug("Getting server group '%s'", affinity_group_id) + try: + self._reload_connection() + self.nova.server_groups.delete(affinity_group_id) + + return affinity_group_id + except ( + nvExceptions.NotFound, + ksExceptions.ClientException, + nvExceptions.ClientException, + ConnectionError, + ) as e: + self._format_exception(e)