def _check_allowed_port_fields(self, fields): """Check if fetching a particular field of a port is allowed. Check if the required version is being requested for fields that are only allowed to be fetched in a particular API version. :param fields: list or set of fields to check :raises: NotAcceptable if a field is not allowed """ if fields is None: return if (not api_utils.allow_port_advanced_net_fields() and set(fields).intersection(self.advanced_net_fields)): raise exception.NotAcceptable() if ('portgroup_uuid' in fields and not api_utils.allow_portgroups_subcontrollers()): raise exception.NotAcceptable() if ('physical_network' in fields and not api_utils.allow_port_physical_network()): raise exception.NotAcceptable() if ('is_smartnic' in fields and not api_utils.allow_port_is_smartnic()): raise exception.NotAcceptable() if ('local_link_connection/network_type' in fields and not api_utils.allow_local_link_connection_network_type()): raise exception.NotAcceptable() if (isinstance(fields, dict) and fields.get('local_link_connection') is not None): if (not api_utils.allow_local_link_connection_network_type() and 'network_type' in fields['local_link_connection']): raise exception.NotAcceptable()
def hide_fields_in_newer_versions(obj): # if requested version is < 1.18, hide internal_info field if not api_utils.allow_port_internal_info(): obj.internal_info = wsme.Unset # if requested version is < 1.19, hide local_link_connection and # pxe_enabled fields if not api_utils.allow_port_advanced_net_fields(): obj.pxe_enabled = wsme.Unset obj.local_link_connection = wsme.Unset # if requested version is < 1.24, hide portgroup_uuid field if not api_utils.allow_portgroups_subcontrollers(): obj.portgroup_uuid = wsme.Unset # if requested version is < 1.34, hide physical_network field. if not api_utils.allow_port_physical_network(): obj.physical_network = wsme.Unset # if requested version is < 1.53, hide is_smartnic field. if not api_utils.allow_port_is_smartnic(): obj.is_smartnic = wsme.Unset
def hide_fields_in_newer_versions(port): # if requested version is < 1.18, hide internal_info field if not api_utils.allow_port_internal_info(): port.pop('internal_info', None) # if requested version is < 1.19, hide local_link_connection and # pxe_enabled fields if not api_utils.allow_port_advanced_net_fields(): port.pop('pxe_enabled', None) port.pop('local_link_connection', None) # if requested version is < 1.24, hide portgroup_uuid field if not api_utils.allow_portgroups_subcontrollers(): port.pop('portgroup_uuid', None) # if requested version is < 1.34, hide physical_network field. if not api_utils.allow_port_physical_network(): port.pop('physical_network', None) # if requested version is < 1.53, hide is_smartnic field. if not api_utils.allow_port_is_smartnic(): port.pop('is_smartnic', None)
def hide_fields_in_newer_versions(obj): # if requested version is < 1.18, hide internal_info field if not api_utils.allow_port_internal_info(): obj.internal_info = wsme.Unset # if requested version is < 1.19, hide local_link_connection and # pxe_enabled fields if not api_utils.allow_port_advanced_net_fields(): obj.pxe_enabled = wsme.Unset obj.local_link_connection = wsme.Unset # if requested version is < 1.24, hide portgroup_uuid field if not api_utils.allow_portgroups_subcontrollers(): obj.portgroup_uuid = wsme.Unset # if requested version is < 1.34, hide physical_network field. if not api_utils.allow_port_physical_network(): obj.physical_network = wsme.Unset # if requested version is < 1.53, hide is_smartnic field. if not api_utils.allow_port_is_smartnic(): obj.is_smartnic = wsme.Unset
def _check_allowed_port_fields(self, fields): """Check if fetching a particular field of a port is allowed. Check if the required version is being requested for fields that are only allowed to be fetched in a particular API version. :param fields: list or set of fields to check :raises: NotAcceptable if a field is not allowed """ if fields is None: return if (not api_utils.allow_port_advanced_net_fields() and set(fields).intersection(self.advanced_net_fields)): raise exception.NotAcceptable() if ('portgroup_uuid' in fields and not api_utils.allow_portgroups_subcontrollers()): raise exception.NotAcceptable() if ('physical_network' in fields and not api_utils.allow_port_physical_network()): raise exception.NotAcceptable() if ('is_smartnic' in fields and not api_utils.allow_port_is_smartnic()): raise exception.NotAcceptable()
def test_allow_port_is_smartnic(self, mock_request): mock_request.version.minor = 53 self.assertTrue(utils.allow_port_is_smartnic()) mock_request.version.minor = 52 self.assertFalse(utils.allow_port_is_smartnic())
def test_allow_port_is_smartnic(self, mock_request): mock_request.version.minor = 53 self.assertTrue(utils.allow_port_is_smartnic()) mock_request.version.minor = 52 self.assertFalse(utils.allow_port_is_smartnic())