From 8f34ec01660b58500732640728b1b74a4b76fb75 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Fri, 6 Sep 2024 20:15:12 +0500 Subject: [PATCH] Add an endpoint for UI to retrieve available space for ix-apps This commit adds changes to add an endpoint which UI can consume to retrieve available space in ix-apps dataset so it can show to a user when he wants to install an app that by default X space is available in ix-apps dataset. --- .../middlewared/plugins/apps/resources.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/middlewared/middlewared/plugins/apps/resources.py b/src/middlewared/middlewared/plugins/apps/resources.py index 728377478391f..3a59c529b5600 100644 --- a/src/middlewared/middlewared/plugins/apps/resources.py +++ b/src/middlewared/middlewared/plugins/apps/resources.py @@ -112,6 +112,29 @@ async def ip_choices(self): for ip in await self.middleware.call('interface.ip_in_use', {'static': True, 'any': True}) } + @accepts(roles=['CATALOG_READ']) + @returns(Dict( + 'available_space', + additional_attrs=True, + example={ + 'parsed': 21289574400, + 'rawvalue': '21289574400', + 'value': '19.8G', + 'source': 'NONE', + 'source_info': None, + } + )) + async def available_space(self): + """ + Returns space available in the configured apps pool which apps can consume + """ + await self.middleware.call('docker.state.validate') + return (await self.middleware.call( + 'zfs.dataset.get_instance', (await self.middleware.call('docker.config'))['dataset'], { + 'extra': {'retrieve_children': False, 'properties': ['available']}, + } + ))['properties']['available'] + @accepts(roles=['APPS_READ']) @returns(Dict('gpu_choices', additional_attrs=True)) async def gpu_choices(self):