'Check usage thresholds for Docker dm storage driver. Return: result dict.
Backing assumptions: We expect devicemapper to be backed by an auto-expanding thin pool
implemented as an LV in an LVM2 VG. This is how docker-storage-setup currently configures
devicemapper storage. The LV is "thin" because it does not use all available storage
from its VG, instead expanding as needed; so to determine available space, we gather
current usage as the Docker API reports for the driver as well as space available for
expansion in the pool\'s VG.
Usage within the LV is divided into pools allocated to data and metadata, either of which
could run out of space first; so we check both.'

def check_dm_usage(self, driver_status):

    vals = dict(vg_free=self.get_vg_free(driver_status.get('Pool    Name')), data_used=driver_status.get('Data    Space    Used'), data_total=driver_status.get('Data    Space    Total'), metadata_used=driver_status.get('Metadata    Space    Used'), metadata_total=driver_status.get('Metadata    Space    Total'))
    for (key, value) in vals.copy().items():
        try:
            vals[(key + '_bytes')] = self.convert_to_bytes(value)
        except ValueError as err:
            return {'failed': True, 'values': vals, 'msg': "Could    not    interpret    {}    value    '{}'    as    bytes:    {}".format(key, value, str(err))}
    for (name, default) in [('data', self.max_thinpool_data_usage_percent), ('metadata', self.max_thinpool_meta_usage_percent)]:
        percent = self.get_var((('max_thinpool_' + name) + '_usage_percent'), default=default)
        try:
            vals[(name + '_threshold')] = float(percent)
        except ValueError:
            return {'failed': True, 'msg': "Specified    thinpool    {}    usage    limit    '{}'    is    not    a    percentage".format(name, percent)}
    messages = []
    for name in ['data', 'metadata']:
        vals[(name + '_pct_used')] = ((100 * vals[(name + '_used_bytes')]) / (vals[(name + '_total_bytes')] + vals['vg_free_bytes']))
        if (vals[(name + '_pct_used')] > vals[(name + '_threshold')]):
            messages.append('Docker    thinpool    {name}    usage    percentage    {pct:.1f}    is    higher    than    threshold    {thresh:.1f}.'.format(name=name, pct=vals[(name + '_pct_used')], thresh=vals[(name + '_threshold')]))
            vals['failed'] = True
    vals['msg'] = '\n'.join((messages or ['Thinpool    usage    is    within    thresholds.']))
    return vals
