def _get_capacity_info(self, nfs_share): """Calculate available space on the NFS share. :param nfs_share: example 172.18.194.100:/var/nfs """ nms = self.share2nms[nfs_share] ns_volume, ns_folder = self._get_share_datasets(nfs_share) folder_props = nms.folder.get_child_props("%s/%s" % (ns_volume, ns_folder), "used|available") free = utils.str2size(folder_props["available"]) allocated = utils.str2size(folder_props["used"]) return free + allocated, free, allocated
def _get_capacity_info(self, nfs_share): """Calculate available space on the NFS share. :param nfs_share: example 172.18.194.100:/var/nfs """ nms = self.share2nms[nfs_share] ns_volume, ns_folder = self._get_share_datasets(nfs_share) folder_props = nms.folder.get_child_props( '%s/%s' % (ns_volume, ns_folder), '') free = utils.str2size(folder_props['available']) allocated = utils.str2size(folder_props['used']) return free + allocated, free, allocated
def _get_capacity_info(self, path): """Calculate available space on the NFS share. :param path: example pool/nfs """ pool, fs = self._get_share_datasets(path) url = 'storage/filesystems/%s' % '%2F'.join([pool, fs]) data = self.nef.get(url) free = utils.str2size(data['bytesAvailable']) allocated = utils.str2size(data['bytesUsed']) total = free + allocated return total, free, allocated
def _get_capacity_info(self, path): """Calculate available space on the NFS share. :param path: example pool/nfs """ pool, fs = self._get_share_datasets(path) url = 'storage/pools/%s/filesystems/%s' % (pool, self._escape_path(fs)) data = self.nef.get(url) total = utils.str2size(data['bytesAvailable']) allocated = utils.str2size(data['bytesUsed']) free = total - allocated return total, free, allocated
def _get_capacity_info(self, path): """Calculate available space on the NFS share. :param path: example pool/nfs """ pool, fs = self._get_share_datasets(path) url = "storage/pools/%s/filesystems/%s" % (pool, fs) data = self.nef.get(url) total = utils.str2size(data["bytesAvailable"]) allocated = utils.str2size(data["bytesUsed"]) free = total - allocated return total, free, allocated
def test_str2size(self): values_to_test = ( # Test empty value (None, 0), ('', 0), ('0', 0), ('12', 12), # Test int and long values (10, 10), (long(10), 10), # Test bytes string ('1b', 1), ('1B', 1), ('1023b', 1023), ('0B', 0), # Test other units ('1M', units.MiB), ('1.0M', units.MiB), ) for value, result in values_to_test: self.assertEquals(utils.str2size(value), result) # Invalid format value self.assertRaises(ValueError, utils.str2size, 'A')
def test_str2size(self): values_to_test = ( # Test empty value (None, 0), ("", 0), ("0", 0), ("12", 12), # Test int and long values (10, 10), (long(10), 10), # Test bytes string ("1b", 1), ("1B", 1), ("1023b", 1023), ("0B", 0), # Test other units ("1M", units.MiB), ("1.0M", units.MiB), ) for value, result in values_to_test: self.assertEqual(utils.str2size(value), result) # Invalid format value self.assertRaises(ValueError, utils.str2size, "A")
def _get_capacity_info(self, nfs_share): """Calculate available space on the NFS share. :param nfs_share: example 172.18.194.100:/var/nfs """ nms = self.share2nms[nfs_share] ns_volume, ns_folder = self._get_share_datasets(nfs_share) folder_props = nms.folder.get_child_props('%s/%s' % (ns_volume, ns_folder), 'used|available') free = utils.str2size(folder_props['available']) allocated = utils.str2size(folder_props['used']) self.shares_with_capacities[nfs_share] = { 'free': utils.str2gib_size(free), 'total': utils.str2gib_size(free + allocated)} return free + allocated, free, allocated
def test_str2size(self): values_to_test = ( # Test empty value (None, 0), ('', 0), ('0', 0), ('12', 12), # Test int and long values (10, 10), (long(10), 10), # Test bytes string ('1b', 1), ('1B', 1), ('1023b', 1023), ('0B', 0), # Test other units ('1M', units.MiB), ('1.0M', units.MiB), ) for value, result in values_to_test: self.assertEqual(utils.str2size(value), result) # Invalid format value self.assertRaises(ValueError, utils.str2size, 'A')