code: def generate_has_role_function(cls, roles):
          
          def has_role_func(self, role):
              """
              Determine if an instance of this class has the configured role.
  
              :param str role: The role identifier from `oslo.config.cfg` to
                               against which to evaluate this instance for
                               membership.
              :returns: Whether or not the instance has the desired role.
              :rtype: bool
  
              Note that the role passed to this function is the role identifier
              from the :class:`oslo.config.cfg`, rather than a keystone role
              itself.
              """
              if role not in roles:
                  msg = "Evaluating has_role('%s'), Role '%s' does not exist."
                  self.logger.warn(msg % (role, self.user_id))
                  return False
              for group in roles[role]:
                  if self._has_keystone_role(group):
                      return True
              return False
          setattr(cls, "has_role", has_role_func)
docs: Generate a `class.has_role('role_name')` method for a class.
  
          :param class cls: The python class to be modified.
          :param dict roles: The roles to use for generation.
  
          This method is intended to be used by an inheriting class to
          generate the has_role method based on the roles provided.
  
          :class:`FlaskKeystone` uses this to add these methods to a dynamically
          generated class which inherits from this class.