code: def links(request):
      class Links(object):
          @classmethod
          def set(cls, name, path):
              if (
                  len(request.config.test_logs[request.node.nodeid])
                  >= MAX_ALLOWED_LINKS_COUNT
              ):
                  raise Exception(
                      "Cannot add more than {} links to test".format(
                          MAX_ALLOWED_LINKS_COUNT
                      )
                  )
  
              reserved_names = ["log", "logsdir", "stdout", "stderr"]
              if name in reserved_names:
                  raise Exception(
                      "Attachment name should not belong to the reserved list: {}".format(
                          ", ".join(reserved_names)
                      )
                  )
              output_dir = request.config.ya.output_dir
  
              if not os.path.exists(path):
                  raise Exception(
                      "Path to be attached does not exist: {}".format(
                          path
                      )
                  )
  
              if os.path.isabs(path) and ".." in os.path.relpath(
                  path, output_dir
              ):
                  raise Exception(
                      "Test attachment must be inside yatest.common.output_path()"
                  )
  
              request.config.test_logs[request.node.nodeid][name] = path
  
          @classmethod
          def get(cls, name):
              if (
                  name
                  not in request.config.test_logs[request.node.nodeid]
              ):
                  raise KeyError(
                      "Attachment with name '{}' does not exist".format(
                          name
                      )
                  )
              return request.config.test_logs[request.node.nodeid][name]
  
      return Links
  
imports: import os
  import pytest
  import six
  from library.python.pytest.plugins.metrics import test_metrics
label_desc: Use image node_id 2 for calling a global function with example usage: links(request) and returns: Links, request