def _SymlinkBlockDev(instance_name, device_path, idx=None, uuid=None):
  # 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 OSError, 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
Set up symlinks to a instance's block device.
dataset/ETHPy150Open ganeti/ganeti/lib/backend.py/_SymlinkBlockDev