def _RemoveBlockDevLinks(instance_name, disks):
  def _remove_symlink(link_name):
    if os.path.islink(link_name):
      try:
        os.remove(link_name)
      except OSError:
        logging.exception("Can't remove symlink '%s'", link_name)

  for idx, disk in enumerate(disks):
    link_name = _GetBlockDevSymlinkPath(instance_name, uuid=disk.uuid)
    _remove_symlink(link_name)
    # Remove also the deprecated symlink (if any)
    link_name = _GetBlockDevSymlinkPath(instance_name, idx=idx)
    _remove_symlink(link_name)
Remove the block device symlinks belonging to the given instance.
dataset/ETHPy150Open ganeti/ganeti/lib/backend.py/_RemoveBlockDevLinks