summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-23 13:08:51 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-25 14:35:41 +0200
commit8754c21694b5dff69105a0d9b739dd87088626ee (patch)
tree57ecca7dc8fcc01d67aa6755924124ed8bce76a5 /src
parent3b40ec7918531cf60d9d4b7749d97ea3f0bf1b1f (diff)
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'} ] } }
Diffstat (limited to 'src')
-rw-r--r--src/live/ogOperations.py25
-rw-r--r--src/utils/fs.py11
-rw-r--r--src/virtual/ogOperations.py5
3 files changed, 23 insertions, 18 deletions
diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py
index c51215c..76999ba 100644
--- a/src/live/ogOperations.py
+++ b/src/live/ogOperations.py
@@ -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):
diff --git a/src/utils/fs.py b/src/utils/fs.py
index 3de8ee2..381f65b 100644
--- a/src/utils/fs.py
+++ b/src/utils/fs.py
@@ -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.
diff --git a/src/virtual/ogOperations.py b/src/virtual/ogOperations.py
index 763c126..836967a 100644
--- a/src/virtual/ogOperations.py
+++ b/src/virtual/ogOperations.py
@@ -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: