X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=RO-VIM-openstack%2Fosm_rovim_openstack%2Fvimconn_openstack.py;h=82a1e37a59bbe663d6a7e7d7a63a6bc90c557157;hb=210ec7ca0dc0df57a9302486eedea70f9afafb18;hp=3eac3a1abbe502503499fa28010b2d11c7f4a3f4;hpb=d0571febfae2dea93305bd99d09ff52204c26662;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 3eac3a1a..82a1e37a 100644 --- a/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py +++ b/RO-VIM-openstack/osm_rovim_openstack/vimconn_openstack.py @@ -339,7 +339,7 @@ class vimconnector(vimconn.VimConnector): version = self.config.get("microversion") if not version: - version = "2.1" + version = "2.60" # addedd region_name to keystone, nova, neutron and cinder to support distributed cloud for Wind River # Titanium cloud and StarlingX @@ -355,12 +355,21 @@ class vimconnector(vimconn.VimConnector): endpoint_type=self.endpoint_type, region_name=region_name, ) - self.cinder = self.session["cinder"] = cClient.Client( - 2, - session=sess, - endpoint_type=self.endpoint_type, - region_name=region_name, - ) + + if sess.get_all_version_data(service_type="volumev2"): + self.cinder = self.session["cinder"] = cClient.Client( + 2, + session=sess, + endpoint_type=self.endpoint_type, + region_name=region_name, + ) + else: + self.cinder = self.session["cinder"] = cClient.Client( + 3, + session=sess, + endpoint_type=self.endpoint_type, + region_name=region_name, + ) try: self.my_tenant_id = self.session["my_tenant_id"] = sess.get_project_id() @@ -880,7 +889,7 @@ class vimconnector(vimconn.VimConnector): if not ip_profile.get("subnet_address"): # Fake subnet is required - subnet_rand = random.randint(0, 255) + subnet_rand = random.SystemRandom().randint(0, 255) ip_profile["subnet_address"] = "192.168.{}.0/24".format(subnet_rand) if "ip_version" not in ip_profile: @@ -925,6 +934,15 @@ class vimconnector(vimconn.VimConnector): ip_str = str(netaddr.IPAddress(ip_int)) subnet["allocation_pools"][0]["end"] = ip_str + if ( + ip_profile.get("ipv6_address_mode") + and ip_profile["ip_version"] != "IPv4" + ): + subnet["ipv6_address_mode"] = ip_profile["ipv6_address_mode"] + # ipv6_ra_mode can be set to the same value for most use cases, see documentation: + # https://docs.openstack.org/neutron/latest/admin/config-ipv6.html#ipv6-ra-mode-and-ipv6-address-mode-combinations + subnet["ipv6_ra_mode"] = ip_profile["ipv6_address_mode"] + # self.logger.debug(">>>>>>>>>>>>>>>>>> Subnet: %s", str(subnet)) self.neutron.create_subnet({"subnet": subnet}) @@ -1393,10 +1411,6 @@ class vimconnector(vimconn.VimConnector): extra_specs (dict): Extra specs dict to be updated """ - # If there is not any numa, numas_nodes equals to 0. - if not numa_nodes: - extra_specs["vmware:extra_config"] = '{"numa.nodeAffinity":"0"}' - # If there are several numas, we do not define specific affinity. extra_specs["vmware:latency_sensitivity_level"] = "high" @@ -1548,7 +1562,6 @@ class vimconnector(vimconn.VimConnector): return new_flavor.id except nvExceptions.Conflict as e: - if change_name_if_used and retry < max_retries: continue @@ -1892,7 +1905,6 @@ class vimconnector(vimconn.VimConnector): # For VF elif net["type"] == "VF" or net["type"] == "SR-IOV": - port_dict["binding:vnic_type"] = "direct" # VIO specific Changes @@ -1934,8 +1946,14 @@ class vimconnector(vimconn.VimConnector): if net.get("mac_address"): port_dict["mac_address"] = net["mac_address"] - if net.get("ip_address"): - port_dict["fixed_ips"] = [{"ip_address": net["ip_address"]}] + ip_dual_list = [] + if ip_list := net.get("ip_address"): + if not isinstance(ip_list, list): + ip_list = [ip_list] + for ip in ip_list: + ip_dict = {"ip_address": ip} + ip_dual_list.append(ip_dict) + port_dict["fixed_ips"] = ip_dual_list # TODO add "subnet_id": def _create_new_port(self, port_dict: dict, created_items: dict, net: dict) -> Dict: @@ -1952,7 +1970,7 @@ class vimconnector(vimconn.VimConnector): """ new_port = self.neutron.create_port({"port": port_dict}) created_items["port:" + str(new_port["port"]["id"])] = True - net["mac_adress"] = new_port["port"]["mac_address"] + net["mac_address"] = new_port["port"]["mac_address"] net["vim_id"] = new_port["port"]["id"] return new_port @@ -2080,7 +2098,6 @@ class vimconnector(vimconn.VimConnector): key_id = "vim_volume_id" if "vim_volume_id" in disk.keys() else "vim_id" if disk.get(key_id): - block_device_mapping["vd" + chr(base_disk_index)] = disk[key_id] existing_vim_volumes.append({"id": disk[key_id]}) @@ -2134,6 +2151,38 @@ class vimconnector(vimconn.VimConnector): created_items[volume_txt] = True block_device_mapping["vd" + chr(base_disk_index)] = volume.id + def new_shared_volumes(self, shared_volume_data) -> (str, str): + try: + volume = self.cinder.volumes.create( + size=shared_volume_data["size"], + name=shared_volume_data["name"], + volume_type="multiattach", + ) + return (volume.name, volume.id) + except (ConnectionError, KeyError) as e: + self._format_exception(e) + + def _prepare_shared_volumes( + self, + name: str, + disk: dict, + base_disk_index: int, + block_device_mapping: dict, + existing_vim_volumes: list, + created_items: dict, + ): + volumes = {volume.name: volume.id for volume in self.cinder.volumes.list()} + if volumes.get(disk["name"]): + sv_id = volumes[disk["name"]] + volume = self.cinder.volumes.get(sv_id) + self.update_block_device_mapping( + volume=volume, + block_device_mapping=block_device_mapping, + base_disk_index=base_disk_index, + disk=disk, + created_items=created_items, + ) + def _prepare_non_root_persistent_volumes( self, name: str, @@ -2158,18 +2207,15 @@ class vimconnector(vimconn.VimConnector): # Non-root persistent volumes # Disk may include only vim_volume_id or only vim_id." key_id = "vim_volume_id" if "vim_volume_id" in disk.keys() else "vim_id" - if disk.get(key_id): - # Use existing persistent volume block_device_mapping["vd" + chr(base_disk_index)] = disk[key_id] existing_vim_volumes.append({"id": disk[key_id]}) - else: - # Create persistent volume + volume_name = f"{name}vd{chr(base_disk_index)}" volume = self.cinder.volumes.create( size=disk["size"], - name=name + "vd" + chr(base_disk_index), + name=volume_name, # Make sure volume is in the same AZ as the VM to be attached to availability_zone=vm_av_zone, ) @@ -2194,7 +2240,6 @@ class vimconnector(vimconn.VimConnector): elapsed_time (int): Time spent while waiting """ - while elapsed_time < volume_timeout: for created_item in created_items: v, volume_id = ( @@ -2202,7 +2247,13 @@ class vimconnector(vimconn.VimConnector): created_item.split(":")[1], ) if v == "volume": - if self.cinder.volumes.get(volume_id).status != "available": + volume = self.cinder.volumes.get(volume_id) + if ( + volume.volume_type == "multiattach" + and volume.status == "in-use" + ): + return elapsed_time + elif volume.status != "available": break else: # All ready: break from while @@ -2229,7 +2280,10 @@ class vimconnector(vimconn.VimConnector): while elapsed_time < volume_timeout: for volume in existing_vim_volumes: - if self.cinder.volumes.get(volume["id"]).status != "available": + v = self.cinder.volumes.get(volume["id"]) + if v.volume_type == "multiattach" and v.status == "in-use": + return elapsed_time + elif v.status != "available": break else: # all ready: break from while break @@ -2263,7 +2317,6 @@ class vimconnector(vimconn.VimConnector): base_disk_index = ord("b") boot_volume_id = None elapsed_time = 0 - for disk in disk_list: if "image_id" in disk: # Root persistent volume @@ -2277,6 +2330,15 @@ class vimconnector(vimconn.VimConnector): existing_vim_volumes=existing_vim_volumes, created_items=created_items, ) + elif disk.get("multiattach"): + self._prepare_shared_volumes( + name=name, + disk=disk, + base_disk_index=base_disk_index, + block_device_mapping=block_device_mapping, + existing_vim_volumes=existing_vim_volumes, + created_items=created_items, + ) else: # Non-root persistent volume self._prepare_non_root_persistent_volumes( @@ -2491,7 +2553,6 @@ class vimconnector(vimconn.VimConnector): # In case of RO in HA there can be conflicts, two RO trying to assign same floating IP, so retry # several times while not assigned: - free_floating_ip = self._get_free_floating_ip( server, floating_network ) @@ -2588,7 +2649,6 @@ class vimconnector(vimconn.VimConnector): self.neutron.update_port(port[0], port_update) except Exception: - raise vimconn.VimConnException( "It was not possible to disable port security for port {}".format( port[0] @@ -2734,7 +2794,6 @@ class vimconnector(vimconn.VimConnector): server_group_id, ) ) - # Create VM server = self.nova.servers.create( name=name, @@ -2895,7 +2954,6 @@ class vimconnector(vimconn.VimConnector): k_id (str): Port id in the VIM """ try: - port_dict = self.neutron.list_ports() existing_ports = [port["id"] for port in port_dict["ports"] if port_dict] @@ -2903,9 +2961,25 @@ class vimconnector(vimconn.VimConnector): self.neutron.delete_port(k_id) except Exception as e: - self.logger.error("Error deleting port: {}: {}".format(type(e).__name__, e)) + def delete_shared_volumes(self, shared_volume_vim_id: str) -> bool: + """Cinder delete volume by id. + Args: + shared_volume_vim_id (str): ID of shared volume in VIM + """ + try: + if self.cinder.volumes.get(shared_volume_vim_id).status != "available": + return True + + else: + self.cinder.volumes.delete(shared_volume_vim_id) + + except Exception as e: + self.logger.error( + "Error deleting volume: {}: {}".format(type(e).__name__, e) + ) + def _delete_volumes_by_id_wth_cinder( self, k: str, k_id: str, volumes_to_hold: list, created_items: dict ) -> bool: @@ -2983,9 +3057,7 @@ class vimconnector(vimconn.VimConnector): try: k_item, k_id = self._get_item_name_id(k) - if k_item == "volume": - unavailable_vol = self._delete_volumes_by_id_wth_cinder( k, k_id, volumes_to_hold, created_items ) @@ -2994,7 +3066,6 @@ class vimconnector(vimconn.VimConnector): keep_waiting = True elif k_item == "floating_ip": - self._delete_floating_ip_by_id(k, k_id, created_items) except Exception as e: @@ -3216,7 +3287,8 @@ class vimconnector(vimconn.VimConnector): def action_vminstance(self, vm_id, action_dict, created_items={}): """Send and action over a VM instance from VIM - Returns None or the console dict if the action was successfully sent to the VIM""" + Returns None or the console dict if the action was successfully sent to the VIM + """ self.logger.debug("Action over VM '%s': %s", vm_id, str(action_dict)) try: @@ -3460,45 +3532,6 @@ class vimconnector(vimconn.VimConnector): ) ) - def delete_user(self, user_id): - """Delete a user from openstack VIM - Returns the user identifier""" - if self.debug: - print("osconnector: Deleting a user from VIM") - - try: - self._reload_connection() - self.keystone.users.delete(user_id) - - return 1, user_id - except ksExceptions.ConnectionError as e: - error_value = -vimconn.HTTP_Bad_Request - error_text = ( - type(e).__name__ - + ": " - + (str(e) if len(e.args) == 0 else str(e.args[0])) - ) - except ksExceptions.NotFound as e: - error_value = -vimconn.HTTP_Not_Found - error_text = ( - type(e).__name__ - + ": " - + (str(e) if len(e.args) == 0 else str(e.args[0])) - ) - except ksExceptions.ClientException as e: # TODO remove - error_value = -vimconn.HTTP_Bad_Request - error_text = ( - type(e).__name__ - + ": " - + (str(e) if len(e.args) == 0 else str(e.args[0])) - ) - - # TODO insert exception vimconn.HTTP_Unauthorized - # if reaching here is because an exception - self.logger.debug("delete_tenant " + error_text) - - return error_value, error_text - def get_hosts_info(self): """Get the information of deployed hosts Returns the hosts content""" @@ -3572,619 +3605,6 @@ class vimconnector(vimconn.VimConnector): return error_value, error_text - def new_classification(self, name, ctype, definition): - self.logger.debug( - "Adding a new (Traffic) Classification to VIM, named %s", name - ) - - try: - new_class = None - self._reload_connection() - - if ctype not in supportedClassificationTypes: - raise vimconn.VimConnNotSupportedException( - "OpenStack VIM connector does not support provided " - "Classification Type {}, supported ones are: {}".format( - ctype, supportedClassificationTypes - ) - ) - - if not self._validate_classification(ctype, definition): - raise vimconn.VimConnException( - "Incorrect Classification definition for the type specified." - ) - - classification_dict = definition - classification_dict["name"] = name - new_class = self.neutron.create_sfc_flow_classifier( - {"flow_classifier": classification_dict} - ) - - return new_class["flow_classifier"]["id"] - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self.logger.error("Creation of Classification failed.") - self._format_exception(e) - - def get_classification(self, class_id): - self.logger.debug(" Getting Classification %s from VIM", class_id) - filter_dict = {"id": class_id} - class_list = self.get_classification_list(filter_dict) - - if len(class_list) == 0: - raise vimconn.VimConnNotFoundException( - "Classification '{}' not found".format(class_id) - ) - elif len(class_list) > 1: - raise vimconn.VimConnConflictException( - "Found more than one Classification with this criteria" - ) - - classification = class_list[0] - - return classification - - def get_classification_list(self, filter_dict={}): - self.logger.debug( - "Getting Classifications from VIM filter: '%s'", str(filter_dict) - ) - - try: - filter_dict_os = filter_dict.copy() - self._reload_connection() - - if self.api_version3 and "tenant_id" in filter_dict_os: - filter_dict_os["project_id"] = filter_dict_os.pop("tenant_id") - - classification_dict = self.neutron.list_sfc_flow_classifiers( - **filter_dict_os - ) - classification_list = classification_dict["flow_classifiers"] - self.__classification_os2mano(classification_list) - - return classification_list - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def delete_classification(self, class_id): - self.logger.debug("Deleting Classification '%s' from VIM", class_id) - - try: - self._reload_connection() - self.neutron.delete_sfc_flow_classifier(class_id) - - return class_id - except ( - neExceptions.ConnectionFailed, - neExceptions.NeutronException, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def new_sfi(self, name, ingress_ports, egress_ports, sfc_encap=True): - self.logger.debug( - "Adding a new Service Function Instance to VIM, named '%s'", name - ) - - try: - new_sfi = None - self._reload_connection() - correlation = None - - if sfc_encap: - correlation = "nsh" - - if len(ingress_ports) != 1: - raise vimconn.VimConnNotSupportedException( - "OpenStack VIM connector can only have 1 ingress port per SFI" - ) - - if len(egress_ports) != 1: - raise vimconn.VimConnNotSupportedException( - "OpenStack VIM connector can only have 1 egress port per SFI" - ) - - sfi_dict = { - "name": name, - "ingress": ingress_ports[0], - "egress": egress_ports[0], - "service_function_parameters": {"correlation": correlation}, - } - new_sfi = self.neutron.create_sfc_port_pair({"port_pair": sfi_dict}) - - return new_sfi["port_pair"]["id"] - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - if new_sfi: - try: - self.neutron.delete_sfc_port_pair(new_sfi["port_pair"]["id"]) - except Exception: - self.logger.error( - "Creation of Service Function Instance failed, with " - "subsequent deletion failure as well." - ) - - self._format_exception(e) - - def get_sfi(self, sfi_id): - self.logger.debug("Getting Service Function Instance %s from VIM", sfi_id) - filter_dict = {"id": sfi_id} - sfi_list = self.get_sfi_list(filter_dict) - - if len(sfi_list) == 0: - raise vimconn.VimConnNotFoundException( - "Service Function Instance '{}' not found".format(sfi_id) - ) - elif len(sfi_list) > 1: - raise vimconn.VimConnConflictException( - "Found more than one Service Function Instance with this criteria" - ) - - sfi = sfi_list[0] - - return sfi - - def get_sfi_list(self, filter_dict={}): - self.logger.debug( - "Getting Service Function Instances from VIM filter: '%s'", str(filter_dict) - ) - - try: - self._reload_connection() - filter_dict_os = filter_dict.copy() - - if self.api_version3 and "tenant_id" in filter_dict_os: - filter_dict_os["project_id"] = filter_dict_os.pop("tenant_id") - - sfi_dict = self.neutron.list_sfc_port_pairs(**filter_dict_os) - sfi_list = sfi_dict["port_pairs"] - self.__sfi_os2mano(sfi_list) - - return sfi_list - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def delete_sfi(self, sfi_id): - self.logger.debug("Deleting Service Function Instance '%s' from VIM", sfi_id) - - try: - self._reload_connection() - self.neutron.delete_sfc_port_pair(sfi_id) - - return sfi_id - except ( - neExceptions.ConnectionFailed, - neExceptions.NeutronException, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def new_sf(self, name, sfis, sfc_encap=True): - self.logger.debug("Adding a new Service Function to VIM, named '%s'", name) - - try: - new_sf = None - self._reload_connection() - # correlation = None - # if sfc_encap: - # correlation = "nsh" - - for instance in sfis: - sfi = self.get_sfi(instance) - - if sfi.get("sfc_encap") != sfc_encap: - raise vimconn.VimConnNotSupportedException( - "OpenStack VIM connector requires all SFIs of the " - "same SF to share the same SFC Encapsulation" - ) - - sf_dict = {"name": name, "port_pairs": sfis} - new_sf = self.neutron.create_sfc_port_pair_group( - {"port_pair_group": sf_dict} - ) - - return new_sf["port_pair_group"]["id"] - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - if new_sf: - try: - self.neutron.delete_sfc_port_pair_group( - new_sf["port_pair_group"]["id"] - ) - except Exception: - self.logger.error( - "Creation of Service Function failed, with " - "subsequent deletion failure as well." - ) - - self._format_exception(e) - - def get_sf(self, sf_id): - self.logger.debug("Getting Service Function %s from VIM", sf_id) - filter_dict = {"id": sf_id} - sf_list = self.get_sf_list(filter_dict) - - if len(sf_list) == 0: - raise vimconn.VimConnNotFoundException( - "Service Function '{}' not found".format(sf_id) - ) - elif len(sf_list) > 1: - raise vimconn.VimConnConflictException( - "Found more than one Service Function with this criteria" - ) - - sf = sf_list[0] - - return sf - - def get_sf_list(self, filter_dict={}): - self.logger.debug( - "Getting Service Function from VIM filter: '%s'", str(filter_dict) - ) - - try: - self._reload_connection() - filter_dict_os = filter_dict.copy() - - if self.api_version3 and "tenant_id" in filter_dict_os: - filter_dict_os["project_id"] = filter_dict_os.pop("tenant_id") - - sf_dict = self.neutron.list_sfc_port_pair_groups(**filter_dict_os) - sf_list = sf_dict["port_pair_groups"] - self.__sf_os2mano(sf_list) - - return sf_list - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def delete_sf(self, sf_id): - self.logger.debug("Deleting Service Function '%s' from VIM", sf_id) - - try: - self._reload_connection() - self.neutron.delete_sfc_port_pair_group(sf_id) - - return sf_id - except ( - neExceptions.ConnectionFailed, - neExceptions.NeutronException, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def new_sfp(self, name, classifications, sfs, sfc_encap=True, spi=None): - self.logger.debug("Adding a new Service Function Path to VIM, named '%s'", name) - - try: - new_sfp = None - self._reload_connection() - # In networking-sfc the MPLS encapsulation is legacy - # should be used when no full SFC Encapsulation is intended - correlation = "mpls" - - if sfc_encap: - correlation = "nsh" - - sfp_dict = { - "name": name, - "flow_classifiers": classifications, - "port_pair_groups": sfs, - "chain_parameters": {"correlation": correlation}, - } - - if spi: - sfp_dict["chain_id"] = spi - - new_sfp = self.neutron.create_sfc_port_chain({"port_chain": sfp_dict}) - - return new_sfp["port_chain"]["id"] - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - if new_sfp: - try: - self.neutron.delete_sfc_port_chain(new_sfp["port_chain"]["id"]) - except Exception: - self.logger.error( - "Creation of Service Function Path failed, with " - "subsequent deletion failure as well." - ) - - self._format_exception(e) - - def get_sfp(self, sfp_id): - self.logger.debug(" Getting Service Function Path %s from VIM", sfp_id) - - filter_dict = {"id": sfp_id} - sfp_list = self.get_sfp_list(filter_dict) - - if len(sfp_list) == 0: - raise vimconn.VimConnNotFoundException( - "Service Function Path '{}' not found".format(sfp_id) - ) - elif len(sfp_list) > 1: - raise vimconn.VimConnConflictException( - "Found more than one Service Function Path with this criteria" - ) - - sfp = sfp_list[0] - - return sfp - - def get_sfp_list(self, filter_dict={}): - self.logger.debug( - "Getting Service Function Paths from VIM filter: '%s'", str(filter_dict) - ) - - try: - self._reload_connection() - filter_dict_os = filter_dict.copy() - - if self.api_version3 and "tenant_id" in filter_dict_os: - filter_dict_os["project_id"] = filter_dict_os.pop("tenant_id") - - sfp_dict = self.neutron.list_sfc_port_chains(**filter_dict_os) - sfp_list = sfp_dict["port_chains"] - self.__sfp_os2mano(sfp_list) - - return sfp_list - except ( - neExceptions.ConnectionFailed, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def delete_sfp(self, sfp_id): - self.logger.debug("Deleting Service Function Path '%s' from VIM", sfp_id) - - try: - self._reload_connection() - self.neutron.delete_sfc_port_chain(sfp_id) - - return sfp_id - except ( - neExceptions.ConnectionFailed, - neExceptions.NeutronException, - ksExceptions.ClientException, - neExceptions.NeutronException, - ConnectionError, - ) as e: - self._format_exception(e) - - def refresh_sfps_status(self, sfp_list): - """Get the status of the service function path - Params: the list of sfp identifiers - Returns a dictionary with: - vm_id: #VIM id of this service function path - status: #Mandatory. Text with one of: - # DELETED (not found at vim) - # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) - # OTHER (Vim reported other status not understood) - # ERROR (VIM indicates an ERROR status) - # ACTIVE, - # CREATING (on building process) - error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR - vim_info: #Text with plain information obtained from vim (yaml.safe_dump)F - """ - sfp_dict = {} - self.logger.debug( - "refresh_sfps status: Getting tenant SFP information from VIM" - ) - - for sfp_id in sfp_list: - sfp = {} - - try: - sfp_vim = self.get_sfp(sfp_id) - - if sfp_vim["spi"]: - sfp["status"] = vmStatus2manoFormat["ACTIVE"] - else: - sfp["status"] = "OTHER" - sfp["error_msg"] = "VIM status reported " + sfp["status"] - - sfp["vim_info"] = self.serialize(sfp_vim) - - if sfp_vim.get("fault"): - sfp["error_msg"] = str(sfp_vim["fault"]) - except vimconn.VimConnNotFoundException as e: - self.logger.error("Exception getting sfp status: %s", str(e)) - sfp["status"] = "DELETED" - sfp["error_msg"] = str(e) - except vimconn.VimConnException as e: - self.logger.error("Exception getting sfp status: %s", str(e)) - sfp["status"] = "VIM_ERROR" - sfp["error_msg"] = str(e) - - sfp_dict[sfp_id] = sfp - - return sfp_dict - - def refresh_sfis_status(self, sfi_list): - """Get the status of the service function instances - Params: the list of sfi identifiers - Returns a dictionary with: - vm_id: #VIM id of this service function instance - status: #Mandatory. Text with one of: - # DELETED (not found at vim) - # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) - # OTHER (Vim reported other status not understood) - # ERROR (VIM indicates an ERROR status) - # ACTIVE, - # CREATING (on building process) - error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR - vim_info: #Text with plain information obtained from vim (yaml.safe_dump) - """ - sfi_dict = {} - self.logger.debug( - "refresh_sfis status: Getting tenant sfi information from VIM" - ) - - for sfi_id in sfi_list: - sfi = {} - - try: - sfi_vim = self.get_sfi(sfi_id) - - if sfi_vim: - sfi["status"] = vmStatus2manoFormat["ACTIVE"] - else: - sfi["status"] = "OTHER" - sfi["error_msg"] = "VIM status reported " + sfi["status"] - - sfi["vim_info"] = self.serialize(sfi_vim) - - if sfi_vim.get("fault"): - sfi["error_msg"] = str(sfi_vim["fault"]) - except vimconn.VimConnNotFoundException as e: - self.logger.error("Exception getting sfi status: %s", str(e)) - sfi["status"] = "DELETED" - sfi["error_msg"] = str(e) - except vimconn.VimConnException as e: - self.logger.error("Exception getting sfi status: %s", str(e)) - sfi["status"] = "VIM_ERROR" - sfi["error_msg"] = str(e) - - sfi_dict[sfi_id] = sfi - - return sfi_dict - - def refresh_sfs_status(self, sf_list): - """Get the status of the service functions - Params: the list of sf identifiers - Returns a dictionary with: - vm_id: #VIM id of this service function - status: #Mandatory. Text with one of: - # DELETED (not found at vim) - # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) - # OTHER (Vim reported other status not understood) - # ERROR (VIM indicates an ERROR status) - # ACTIVE, - # CREATING (on building process) - error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR - vim_info: #Text with plain information obtained from vim (yaml.safe_dump) - """ - sf_dict = {} - self.logger.debug("refresh_sfs status: Getting tenant sf information from VIM") - - for sf_id in sf_list: - sf = {} - - try: - sf_vim = self.get_sf(sf_id) - - if sf_vim: - sf["status"] = vmStatus2manoFormat["ACTIVE"] - else: - sf["status"] = "OTHER" - sf["error_msg"] = "VIM status reported " + sf_vim["status"] - - sf["vim_info"] = self.serialize(sf_vim) - - if sf_vim.get("fault"): - sf["error_msg"] = str(sf_vim["fault"]) - except vimconn.VimConnNotFoundException as e: - self.logger.error("Exception getting sf status: %s", str(e)) - sf["status"] = "DELETED" - sf["error_msg"] = str(e) - except vimconn.VimConnException as e: - self.logger.error("Exception getting sf status: %s", str(e)) - sf["status"] = "VIM_ERROR" - sf["error_msg"] = str(e) - - sf_dict[sf_id] = sf - - return sf_dict - - def refresh_classifications_status(self, classification_list): - """Get the status of the classifications - Params: the list of classification identifiers - Returns a dictionary with: - vm_id: #VIM id of this classifier - status: #Mandatory. Text with one of: - # DELETED (not found at vim) - # VIM_ERROR (Cannot connect to VIM, VIM response error, ...) - # OTHER (Vim reported other status not understood) - # ERROR (VIM indicates an ERROR status) - # ACTIVE, - # CREATING (on building process) - error_msg: #Text with VIM error message, if any. Or the VIM connection ERROR - vim_info: #Text with plain information obtained from vim (yaml.safe_dump) - """ - classification_dict = {} - self.logger.debug( - "refresh_classifications status: Getting tenant classification information from VIM" - ) - - for classification_id in classification_list: - classification = {} - - try: - classification_vim = self.get_classification(classification_id) - - if classification_vim: - classification["status"] = vmStatus2manoFormat["ACTIVE"] - else: - classification["status"] = "OTHER" - classification["error_msg"] = ( - "VIM status reported " + classification["status"] - ) - - classification["vim_info"] = self.serialize(classification_vim) - - if classification_vim.get("fault"): - classification["error_msg"] = str(classification_vim["fault"]) - except vimconn.VimConnNotFoundException as e: - self.logger.error("Exception getting classification status: %s", str(e)) - classification["status"] = "DELETED" - classification["error_msg"] = str(e) - except vimconn.VimConnException as e: - self.logger.error("Exception getting classification status: %s", str(e)) - classification["status"] = "VIM_ERROR" - classification["error_msg"] = str(e) - - 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: @@ -4459,3 +3879,19 @@ class vimconnector(vimconn.VimConnector): self.__wait_for_vm(vm_id, "ACTIVE") instance_status = self.get_vdu_state(vm_id)[0] return instance_status + + def get_monitoring_data(self): + try: + self.logger.debug("Getting servers and ports data from Openstack VIMs.") + self._reload_connection() + all_servers = self.nova.servers.list(detailed=True) + all_ports = self.neutron.list_ports() + return all_servers, all_ports + except ( + vimconn.VimConnException, + vimconn.VimConnNotFoundException, + vimconn.VimConnConnectionException, + ) as e: + raise vimconn.VimConnException( + f"Exception in monitoring while getting VMs and ports status: {str(e)}" + )