def BlockdevAssemble(disk, instance, as_primary, idx):
  """Activate a block device for an instance.

  This is a wrapper over _RecursiveAssembleBD.

  @rtype: str or boolean
  @return: a tuple with the C{/dev/...} path and the created symlink
      for primary nodes, and (C{True}, C{True}) for secondary nodes

  """
  try:
    result = _RecursiveAssembleBD(disk, instance.name, as_primary)
    if isinstance(result, BlockDev):
      # pylint: disable=E1103
      dev_path = result.dev_path
      link_name = None
      uri = None
      if as_primary:
        # Create both index-based and uuid-based symlinks
        # for backwards compatibility
        _SymlinkBlockDev(instance.name, dev_path, idx=idx)
        link_name = _SymlinkBlockDev(instance.name, dev_path, uuid=disk.uuid)
        uri = _CalculateDeviceURI(instance, disk, result)
    elif result:
      return result, result
    else:
      _Fail("Unexpected result from _RecursiveAssembleBD")
  except errors.BlockDeviceError, err:
    _Fail("Error while assembling disk: %s", err, exc=True)
  except __HOLE__, err:
    _Fail("Error while symlinking disk: %s", err, exc=True)

  return dev_path, link_name, uri
dataset/ETHPy150Open ganeti/ganeti/lib/backend.py/BlockdevAssemble