code: def _create_sibling_ria(
      ds,
      url,
      push_url,
      name,
      storage_sibling,
      storage_name,
      alias,
      existing,
      shared,
      group,
      post_update_hook,
      trust_level,
      res_kwargs,
  ):
      # be safe across datasets
      res_kwargs = res_kwargs.copy()
      # update dataset
      res_kwargs["ds"] = ds
  
      if not isinstance(ds.repo, AnnexRepo):
          # No point in dealing with a special remote when there's no annex.
          # Note, that in recursive invocations this might only apply to some of
          # the datasets. Therefore dealing with it here rather than one level up.
          lgr.debug(
              "No annex at %s. Ignoring special remote options.",
              ds.path,
          )
          storage_sibling = False
          storage_name = None
  
      # parse target URL
      try:
          ssh_host, url_base_path, rewritten_url = verify_ria_url(
              push_url if push_url else url, ds.config
          )
      except ValueError as e:
          yield get_status_dict(
              status="error", message=str(e), **res_kwargs
          )
          return
  
      local_base_path = Path(url_path2local_path(url_base_path))
  
      git_url = decode_source_spec(
          # append dataset id to url and use magic from clone-helper:
          url + "#{}".format(ds.id),
          cfg=ds.config,
      )["giturl"]
      git_push_url = (
          decode_source_spec(
              push_url + "#{}".format(ds.id), cfg=ds.config
          )["giturl"]
          if push_url
          else None
      )
  
      # determine layout locations; go for a v1 store-level layout
      repo_path, _, _ = get_layout_locations(1, local_base_path, ds.id)
  
      ds_siblings = [
          r["name"]
          for r in ds.siblings(
              result_renderer="disabled", return_type="generator"
          )
      ]
      # Figure whether we are supposed to skip this very dataset
      if existing == "skip" and (
          name in ds_siblings
          or (storage_name and storage_name in ds_siblings)
      ):
          yield get_status_dict(
              status="notneeded",
              message="Skipped on existing sibling",
              **res_kwargs,
          )
          # if we skip here, nothing else can change that decision further
          # down
          return
  
      # figure whether we need to skip or error due an existing target repo before
      # we try to init a special remote.
      if ssh_host:
          from datalad import ssh_manager
  
          ssh = ssh_manager.get_connection(
              ssh_host, use_remote_annex_bundle=False
          )
          ssh.open()
  
      exists = False
      if existing in ["skip", "error", "reconfigure"]:
          config_path = repo_path / "config"
          # No .git -- if it's an existing repo in a RIA store it should be a
          # bare repo.
          # Theoretically we could have additional checks for whether we have
          # an empty repo dir or a non-bare repo or whatever else.
          if ssh_host:
              try:
                  ssh(
                      "[ -e {p} ]".format(
                          p=quote_cmdlinearg(str(config_path))
                      )
                  )
                  exists = True
              except CommandError:
                  exists = False
          else:
              exists = config_path.exists()
  
          if exists:
              if existing == "skip":
                  # 1. not rendered by default
                  # 2. message doesn't show up in ultimate result
                  #    record as shown by -f json_pp
                  yield get_status_dict(
                      status="notneeded",
                      message="Skipped on existing remote "
                      "directory {}".format(repo_path),
                      **res_kwargs,
                  )
                  return
              elif existing == "error":
                  yield get_status_dict(
                      status="error",
                      message="remote directory {} already "
                      "exists.".format(repo_path),
                      **res_kwargs,
                  )
                  return
              else:
                  # reconfigure will be handled later in the code
                  pass
  
      if storage_sibling == "only":
          lgr.info("create storage sibling '%s' ...", name)
      else:
          lgr.info(
              "create sibling%s '%s'%s ...",
              "s" if storage_name else "",
              name,
              " and '{}'".format(storage_name) if storage_name else "",
          )
      create_ds_in_store(
          SSHRemoteIO(ssh_host) if ssh_host else LocalIO(),
          local_base_path,
          ds.id,
          "2",
          "1",
          alias,
          init_obj_tree=storage_sibling is not False,
      )
      if storage_sibling:
          # we are using the main `name`, if the only thing we are creating
          # is the storage sibling
          srname = name if storage_sibling == "only" else storage_name
  
          lgr.debug("init special remote %s", srname)
          special_remote_options = [
              "type=external",
              "externaltype=ora",
              "encryption=none",
              "autoenable=true",
              "url={}".format(url),
          ]
          if push_url:
              special_remote_options.append(
                  "push-url={}".format(push_url)
              )
          try:
              ds.repo.init_remote(
                  srname, options=special_remote_options
              )
          except CommandError as e:
              if (
                  existing == "reconfigure"
                  and "There is already a special remote" in e.stderr
              ):
                  # run enableremote instead
                  lgr.debug(
                      "special remote '%s' already exists. "
                      "Run enableremote instead.",
                      srname,
                  )
                  # TODO: Use AnnexRepo.enable_remote (which needs to get
                  #       `options` first)
                  ds.repo.call_annex(
                      ["enableremote", srname] + special_remote_options
                  )
              else:
                  yield get_status_dict(
                      status="error",
                      message="initremote failed.\nstdout: %s\nstderr: %s"
                      % (e.stdout, e.stderr),
                      **res_kwargs,
                  )
                  return
  
          if trust_level:
              trust_cmd = [trust_level]
              if trust_level == "trust":
                  # Following git-annex 8.20201129-73-g6a0030a11, using `git
                  # annex trust` requires --force.
                  trust_cmd.append("--force")
              ds.repo.call_annex(trust_cmd + [srname])
          # get uuid for use in bare repo's config
          uuid = ds.config.get("remote.{}.annex-uuid".format(srname))
  
      if storage_sibling == "only":
          # we can stop here, the rest of the function is about setting up
          # the git remote part of the sibling
          yield get_status_dict(
              status="ok",
              **res_kwargs,
          )
          return
  
      # 2. create a bare repository in-store:
  
      lgr.debug("init bare repository")
      # TODO: we should prob. check whether it's there already. How?
      # Note: like the special remote itself, we assume local FS if no
      # SSH host is specified
      disabled_hook = repo_path / "hooks" / "post-update.sample"
      enabled_hook = repo_path / "hooks" / "post-update"
  
      if group:
          chgrp_cmd = "chgrp -R {} {}".format(
              quote_cmdlinearg(str(group)),
              quote_cmdlinearg(str(repo_path)),
          )
  
      if ssh_host:
          ssh(
              "cd {rootdir} && git init --bare{shared}".format(
                  rootdir=quote_cmdlinearg(str(repo_path)),
                  shared=" --shared='{}'".format(
                      quote_cmdlinearg(shared)
                  )
                  if shared
                  else "",
              )
          )
  
          if storage_sibling:
              # write special remote's uuid into git-config, so clone can
              # which one it is supposed to be and enable it even with
              # fallback URL
              ssh(
                  "cd {rootdir} && git config datalad.ora-remote.uuid {uuid}"
                  "".format(
                      rootdir=quote_cmdlinearg(str(repo_path)),
                      uuid=uuid,
                  )
              )
  
          if post_update_hook:
              ssh(
                  "mv {} {}".format(
                      quote_cmdlinearg(str(disabled_hook)),
                      quote_cmdlinearg(str(enabled_hook)),
                  )
              )
  
          if group:
              # Either repository existed before or a new directory was
              # created for it, set its group to a desired one if was
              # provided with the same chgrp
              ssh(chgrp_cmd)
  
          # finally update server
          if post_update_hook:
              # Conditional on post_update_hook, since one w/o the other doesn't
              # seem to make much sense.
              ssh(
                  "cd {rootdir} && git update-server-info".format(
                      rootdir=quote_cmdlinearg(str(repo_path))
                  )
              )
      else:
          gr = GitRepo(
              repo_path,
              create=True,
              bare=True,
              shared=shared if shared else None,
          )
          if exists and existing == "reconfigure":
              # if the repo exists at the given path, the GitRepo would not
              # (re)-run git init, and just return an instance of GitRepo;
              # skip & error have been handled at this point
              gr.init(
                  sanity_checks=False,
                  init_options=["--bare"]
                  + ([f"--shared={shared}"] if shared else []),
              )
          if storage_sibling:
              # write special remote's uuid into git-config, so clone can
              # which one it is supposed to be and enable it even with
              # fallback URL
              gr.config.add(
                  "datalad.ora-remote.uuid", uuid, scope="local"
              )
  
          if post_update_hook:
              disabled_hook.rename(enabled_hook)
          if group:
              # No CWD needed here, since `chgrp` is expected to be found via PATH
              # and the path it's operating on is absolute (repo_path). No
              # repository operation involved.
              Runner().run(chgrp_cmd)
          # finally update server
          if post_update_hook:
              # Conditional on post_update_hook, since one w/o the other doesn't
              # seem to make much sense.
              gr.call_git(["update-server-info"])
  
      # add a git remote to the bare repository
      # Note: needs annex-ignore! Otherwise we might push into dirhash
      # lower annex/object tree instead of mixed, since it's a bare
      # repo. This in turn would be an issue, if we want to pack the
      # entire thing into an archive. Special remote will then not be
      # able to access content in the "wrong" place within the archive
      lgr.debug("set up git remote")
      if name in ds_siblings:
          # otherwise we should have skipped or failed before
          assert existing == "reconfigure"
      ds.config.set(
          "remote.{}.annex-ignore".format(name),
          value="true",
          scope="local",
      )
      yield from ds.siblings(
          "configure",
          name=name,
          url=str(repo_path) if url.startswith("ria+file") else git_url,
          pushurl=git_push_url,
          recursive=False,
          # Note, that this should be None if storage_sibling was not set
          publish_depends=storage_name,
          result_renderer="disabled",
          return_type="generator",
          # Note, that otherwise a subsequent publish will report
          # "notneeded".
          fetch=True,
      )
  
      yield get_status_dict(
          status="ok",
          **res_kwargs,
      )
  
imports: import logging
  from pathlib import PurePosixPath
  from datalad.cmd import WitlessRunner
  from datalad.core.distributed.clone import decode_source_spec
  from datalad.customremotes.ria_utils import create_ds_in_store, create_store, get_layout_locations, verify_ria_url
  from datalad.distributed.ora_remote import LocalIO, RemoteCommandFailedError, RIARemoteError, SSHRemoteIO
  from datalad.distribution.dataset import EnsureDataset, datasetmethod, require_dataset
  from datalad.distribution.utils import _yield_ds_w_matching_siblings
  from datalad.interface.base import Interface, build_doc, eval_results
  from datalad.interface.common_opts import recursion_flag, recursion_limit
  from datalad.interface.results import get_status_dict
  from datalad.log import log_progress
  from datalad.support.annexrepo import AnnexRepo
  from datalad.support.constraints import EnsureBool, EnsureChoice, EnsureNone, EnsureStr
  from datalad.support.exceptions import CommandError
  from datalad.support.gitrepo import GitRepo
  from datalad.support.network import url_path2local_path
  from datalad.support.param import Parameter
  from datalad.utils import Path, quote_cmdlinearg
label_desc: Use image node_id 1 for calling a global function with example usage: _create_sibling_ria(ds, url, push_url, name, storage_sibling, storage_name, alias, existing, shared, group, post_update_hook, trust_level, res_kwargs) without return types