def _SymlinkBlockDev(instance_name, device_path, idx=None, uuid=None):
  """Set up symlinks to a instance's block device.

  This is an auxiliary function run when an instance is start (on the primary
  node) or when an instance is migrated (on the target node).


  @param instance_name: the name of the target instance
  @param device_path: path of the physical block device, on the node
  @param idx: the disk index
  @param uuid: the disk uuid
  @return: absolute path to the disk's symlink

  """
  # In case we have only a userspace access URI, device_path is None
  if not device_path:
    return None

  link_name = _GetBlockDevSymlinkPath(instance_name, idx, uuid)

  try:
    os.symlink(device_path, link_name)
  except __HOLE__, err:
    if err.errno == errno.EEXIST:
      if (not os.path.islink(link_name) or
          os.readlink(link_name) != device_path):
        os.remove(link_name)
        os.symlink(device_path, link_name)
    else:
      raise

  return link_name
dataset/ETHPy150Open ganeti/ganeti/lib/backend.py/_SymlinkBlockDev