Skip to content

Commit

Permalink
NAS-127636 / 24.10 / Expose API arguments to device.get_info (#13642)
Browse files Browse the repository at this point in the history
* expose args to device.get_info

* update callers of api

* fix issues found during QA
  • Loading branch information
yocalebo authored May 1, 2024
1 parent 7b6c6ca commit dc0bce7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions src/middlewared/middlewared/plugins/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ class DeviceService(Service):
class Config:
cli_namespace = 'system.device'

@accepts(Str('type', enum=['SERIAL', 'DISK', 'GPU']), roles=['READONLY_ADMIN'])
@accepts(
Dict(
'data',
Str('type', enum=['SERIAL', 'DISK', 'GPU'], required=True),
Bool('get_partitions', required=False, default=False),
Bool('serials_only', required=False, default=False),
),
roles=['READONLY_ADMIN']
)
@returns(OROperator(
List('serial_info', items=[Dict(
'serial_info',
Expand Down Expand Up @@ -42,8 +50,18 @@ class Config:
Dict('disk_info', additional_attrs=True),
name='device_info',
))
async def get_info(self, _type):
async def get_info(self, data):
"""
Get info for SERIAL/DISK/GPU device types.
Get info for `data['type']` device.
If `type` is "DISK":
`get_partitions`: boolean, when set to True will query partition
information for the disks. NOTE: this can be expensive on
systems with a large number of disks present.
`serials_only`: boolean, when set to True will query serial information
_ONLY_ for the disks.
"""
return await self.middleware.call(f'device.get_{_type.lower()}s')
method = f'device.get_{data["type"].lower()}s'
if method == 'device.get_disks':
return await self.middleware.call(method, data['get_partitions'], data['serials_only'])
return await self.middleware.call(method)
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async def setup(self):
self.logger.error('Unable to configure GPU for node: %s', e, exc_info=True)

async def get_system_gpus(self):
gpus = await self.middleware.call('device.get_info', 'GPU')
gpus = await self.middleware.call('device.get_info', {'type': 'GPU'})
supported_gpus = {'NVIDIA', 'INTEL', 'AMD'}
return supported_gpus.intersection(set([gpu['vendor'] for gpu in gpus if gpu['available_to_host']]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def serial_port_choices(self):
"""
Get available choices for `serialport`.
"""
ports = {e['name']: e['name'] for e in await self.middleware.call('device.get_info', 'SERIAL')}
ports = {e['name']: e['name'] for e in await self.middleware.call('device.get_info', {'type': 'SERIAL'})}
if not ports or (await self.middleware.call('system.advanced.config'))['serialport'] == 'ttyS0':
# We should always add ttyS0 if ports is false or current value is the default one in db
# i.e ttyS0
Expand Down

0 comments on commit dc0bce7

Please sign in to comment.