mox = self._mox
drv = self._driver
+ df_total_size = 2620544
df_avail = 1490560
df_head = 'Filesystem 1K-blocks Used Available Use% Mounted on\n'
- df_data = 'glusterfs-host:/export 2620544 996864 %d 41%% /mnt' % \
- df_avail
+ df_data = 'glusterfs-host:/export %d 996864 %d 41%% /mnt' % \
+ (df_total_size, df_avail)
df_output = df_head + df_data
setattr(glusterfs.FLAGS, 'glusterfs_disk_util', 'df')
mox.ReplayAll()
- self.assertEquals(df_avail,
+ self.assertEquals((df_avail, df_total_size),
drv._get_available_capacity(
self.TEST_EXPORT1))
mox.ReplayAll()
- self.assertEquals(df_total_size - du_used,
+ self.assertEquals((df_total_size - du_used, df_total_size),
drv._get_available_capacity(
self.TEST_EXPORT1))
mox.StubOutWithMock(drv, '_get_available_capacity')
drv._get_available_capacity(self.TEST_EXPORT1).\
- AndReturn(2 * self.ONE_GB_IN_BYTES)
+ AndReturn((2 * self.ONE_GB_IN_BYTES, 5 * self.ONE_GB_IN_BYTES))
drv._get_available_capacity(self.TEST_EXPORT2).\
- AndReturn(3 * self.ONE_GB_IN_BYTES)
+ AndReturn((3 * self.ONE_GB_IN_BYTES, 10 * self.ONE_GB_IN_BYTES))
mox.ReplayAll()
mox.StubOutWithMock(drv, '_get_available_capacity')
drv._get_available_capacity(self.TEST_EXPORT1).\
- AndReturn(0)
+ AndReturn((0, 5 * self.ONE_GB_IN_BYTES))
drv._get_available_capacity(self.TEST_EXPORT2).\
- AndReturn(0)
+ AndReturn((0, 10 * self.ONE_GB_IN_BYTES))
mox.ReplayAll()
greatest_share = None
for glusterfs_share in self._mounted_shares:
- capacity = self._get_available_capacity(glusterfs_share)
+ capacity = self._get_available_capacity(glusterfs_share)[0]
if capacity > greatest_size:
greatest_share = glusterfs_share
greatest_size = capacity
available = 0
+ size = int(out.split()[1])
if self.configuration.glusterfs_disk_util == 'df':
available = int(out.split()[3])
else:
- size = int(out.split()[1])
out, _ = self._execute('du', '-sb', '--apparent-size',
'--exclude', '*snapshot*', mount_point,
run_as_root=True)
used = int(out.split()[0])
available = size - used
- return available
+ return available, size
def _mount_glusterfs(self, glusterfs_share, mount_path, ensure=False):
"""Mount GlusterFS share to mount path."""
LOG.warn(_("%s is already mounted"), glusterfs_share)
else:
raise
+
+ def get_volume_stats(self, refresh=False):
+ """Get volume stats.
+
+ If 'refresh' is True, update the stats first."""
+ if refresh or not self._stats:
+ self._update_volume_stats()
+
+ return self._stats
+
+ def _update_volume_stats(self):
+ """Retrieve stats info from volume group."""
+
+ data = {}
+ backend_name = self.configuration.safe_get('volume_backend_name')
+ data['volume_backend_name'] = backend_name or 'GlusterFS'
+ data['vendor_name'] = 'Open Source'
+ data['driver_version'] = '1.0'
+ data['storage_protocol'] = 'glusterfs'
+
+ self._ensure_shares_mounted()
+
+ global_capacity = 0
+ global_free = 0
+ for nfs_share in self._mounted_shares:
+ free, capacity = self._get_available_capacity(nfs_share)
+ global_capacity += capacity
+ global_free += free
+
+ data['total_capacity_gb'] = global_capacity / 1024.0 ** 3
+ data['free_capacity_gb'] = global_free / 1024.0 ** 3
+ data['reserved_percentage'] = 0
+ data['QoS_support'] = False
+ self._stats = data