mirror of https://git.48k.eu/ogclient
src: report used and free partition data in bytes
Add "used_size" and "free_size" to the partition data and the cache data. Old response from ogClient for /cache/delete, /cache/fetch and /image/restore: { 'cache': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } New response: { 'cache': { 'used_size': 4520232322423, 'free_size': 48273465287452945, 'images': [ {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'}, {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'} ] } }master
parent
3b40ec7918
commit
8754c21694
|
@ -61,7 +61,8 @@ class OgLiveOperations:
|
|||
part_setup['filesystem'] = ''
|
||||
part_setup['os'] = ''
|
||||
part_setup['size'] = str(cxt.nsectors * cxt.sector_size // 1024)
|
||||
part_setup['used_size'] = '0'
|
||||
part_setup['used_size'] = 0
|
||||
part_setup['free_size'] = 0
|
||||
if not cxt.label:
|
||||
part_setup['code'] = '0'
|
||||
else:
|
||||
|
@ -84,11 +85,15 @@ class OgLiveOperations:
|
|||
if mount_mkdir(source, target):
|
||||
probe_result = os_probe(target)
|
||||
part_setup['os'] = probe_result
|
||||
part_setup['used_size'] = get_usedperc(target)
|
||||
|
||||
total, used, free = shutil.disk_usage(target)
|
||||
part_setup['used_size'] = used
|
||||
part_setup['free_size'] = free
|
||||
umount(target)
|
||||
else:
|
||||
part_setup['os'] = ''
|
||||
part_setup['used_size'] = '0'
|
||||
part_setup['used_size'] = 0
|
||||
part_setup['free_size'] = 0
|
||||
|
||||
|
||||
part_setup['disk_type'] = ''
|
||||
|
@ -111,9 +116,10 @@ class OgLiveOperations:
|
|||
part_setup['code'] = 'ca'
|
||||
|
||||
def _get_cache_contents(self):
|
||||
cache_contents = []
|
||||
cache_contents = {}
|
||||
|
||||
if not mount_cache():
|
||||
cache_mnt = mount_cache()
|
||||
if not cache_mnt:
|
||||
return cache_contents
|
||||
|
||||
img_dir = OG_CACHE_IMAGE_PATH
|
||||
|
@ -121,6 +127,8 @@ class OgLiveOperations:
|
|||
if not os.path.isdir(img_dir):
|
||||
return cache_contents
|
||||
|
||||
image_list = []
|
||||
|
||||
for file_name in os.listdir(img_dir):
|
||||
file_path = os.path.join(img_dir, file_name)
|
||||
|
||||
|
@ -151,10 +159,15 @@ class OgLiveOperations:
|
|||
continue
|
||||
|
||||
image_size = os.stat(file_path).st_size
|
||||
cache_contents.append({
|
||||
image_list.append({
|
||||
'name': file_name,
|
||||
'size': image_size,
|
||||
'checksum': image_checksum})
|
||||
|
||||
total, used, free = shutil.disk_usage(cache_mnt)
|
||||
cache_contents['used_size'] = used
|
||||
cache_contents['free_size'] = free
|
||||
cache_contents['images'] = image_list
|
||||
return cache_contents
|
||||
|
||||
def _get_boot_entry_data(self):
|
||||
|
|
|
@ -81,17 +81,6 @@ def umount_all():
|
|||
umount(path)
|
||||
|
||||
|
||||
def get_usedperc(mountpoint):
|
||||
"""
|
||||
Returns percetage of used filesystem as decimal number.
|
||||
"""
|
||||
try:
|
||||
total, used, free, perc = psutil.disk_usage(mountpoint)
|
||||
except FileNotFoundError:
|
||||
return '0'
|
||||
return str(perc)
|
||||
|
||||
|
||||
def ogReduceFs(disk, part):
|
||||
"""
|
||||
Shrink filesystem of a partition. Supports ext4 and ntfs partitions.
|
||||
|
|
|
@ -286,6 +286,7 @@ class OgVirtualOperations:
|
|||
part['os'] = ''
|
||||
part['size'] = 0
|
||||
part['used_size'] = 0
|
||||
part['free_size'] = 0
|
||||
part['virt-drive'] = ''
|
||||
continue
|
||||
g = guestfs.GuestFS(python_return_dict=True)
|
||||
|
@ -332,7 +333,8 @@ class OgVirtualOperations:
|
|||
'filesystem': '',
|
||||
'os': '',
|
||||
'size': int(free_disk / 1024),
|
||||
'used_size': int(100 * used_disk / total_disk)}],
|
||||
'used_size': used_disk,
|
||||
'free_size': free_disk}],
|
||||
'partition_setup': []}
|
||||
for i in range(4):
|
||||
part_json = {'disk': 1,
|
||||
|
@ -342,6 +344,7 @@ class OgVirtualOperations:
|
|||
'os': '',
|
||||
'size': 0,
|
||||
'used_size': 0,
|
||||
'free_size': 0,
|
||||
'virt-drive': ''}
|
||||
data['partition_setup'].append(part_json)
|
||||
with open(self.OG_PARTITIONS_CFG_PATH, 'w+') as f:
|
||||
|
|
Loading…
Reference in New Issue