'Since glance images are downloaded and snapshotted before they are
used, only a small proportion of its VDI will be in use and it will
never grow.  We only need to count the virtual size for disks that
are attached to a VM - every other disk can count physical.'

def get_disk_used(self, sr_ref):

    def _vdi_attached(vdi_ref):
        try:
            vbds = self._session.VDI.get_VBDs(vdi_ref)
            for vbd in vbds:
                if self._session.VBD.get_currently_attached(vbd):
                    return True
        except self._session.XenAPI.Failure:
            pass
        return False
    allocated = 0
    physical_used = 0
    all_vdis = self._session.SR.get_VDIs(sr_ref)
    for vdi_ref in all_vdis:
        try:
            vdi_physical = int(self._session.VDI.get_physical_utilisation(vdi_ref))
            if _vdi_attached(vdi_ref):
                allocated += int(self._session.VDI.get_virtual_size(vdi_ref))
            else:
                allocated += vdi_physical
            physical_used += vdi_physical
        except (ValueError, self._session.XenAPI.Failure):
            LOG.exception(_('Unable    to    get    size    for    vdi    %s'), vdi_ref)
    return (allocated, physical_used)
