Skip to content

Commit

Permalink
feat(devices): filter device list by name
Browse files Browse the repository at this point in the history
The list device API supports filtering the list by a device's name. This
commit adds the support in the get_all_devices method.
  • Loading branch information
pallabpain committed Jul 30, 2024
1 parent d0553ce commit 0b60df5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 9 additions & 4 deletions rapyuta_io/clients/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ def _add_auth_token_to_devices(self, devices):
setattr(device, '_auth_token', self._auth_token)
setattr(device, '_project', self._project)

def _get_device(self, device_id=None, retry_limit=0):
def _get_device(self, device_id=None, retry_limit=0, device_name=None):
url = self._device_api_host + DEVICE_API_PATH
if device_id:
url = url + device_id

query = {}
if device_name is not None:
query = {"name": device_name}

headers = create_auth_header(self._auth_token, self._project)
response = RestClient(url).retry(retry_limit).headers(headers).execute()
response = RestClient(url).retry(retry_limit).headers(headers).query_param(query_param=query).execute()
return get_api_response_data(response)

@staticmethod
Expand All @@ -69,14 +74,14 @@ def _device_selection_by_arch(self, arch_list, retry_limit):
def set_project(self, project):
self._project = project

def device_list(self, online_device=False, arch_list=None, retry_limit=0):
def device_list(self, online_device=False, arch_list=None, retry_limit=0, device_name=None):
arch_filtered_uuids = set()
if arch_list:
for device in self._device_selection_by_arch(arch_list, retry_limit):
arch_filtered_uuids.add(device['uuid'])

# TODO(shivam): if arch_list is set there's no need for _get_device all
device_list = self._get_device(retry_limit=retry_limit)
device_list = self._get_device(retry_limit=retry_limit, device_name=device_name)
devices = []
# todo: add a generic filter like status, name etc
for device in device_list:
Expand Down
6 changes: 4 additions & 2 deletions rapyuta_io/rio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def get_user_organizations(self):
"""
return self._core_api_client.get_user_organizations()

def get_all_devices(self, online_device=False, arch_list=None, retry_limit=0):
def get_all_devices(self, online_device=False, arch_list=None, retry_limit=0, device_name=None):
"""
Get all the devices
Expand All @@ -404,6 +404,8 @@ def get_all_devices(self, online_device=False, arch_list=None, retry_limit=0):
:param retry_limit: No of retry attempts to be carried out if any failures occurs\
during the API call.
:type retry_limit: int
:param device_name: Optional parameter to filter the devices based on the device name.
:type device_name: str
:return: List of instances of :py:class:`~Device` class
:raises: :py:class:`APIError`: If the API returns an error, a status code
of anything other than 200/201 is returned
Expand All @@ -418,7 +420,7 @@ def get_all_devices(self, online_device=False, arch_list=None, retry_limit=0):
>>> DeviceArch.ARM32V7, DeviceArch.ARM64V8, DeviceArch.AMD64])
"""
return self._dmClient.device_list(online_device, arch_list, retry_limit)
return self._dmClient.device_list(online_device, arch_list, retry_limit, device_name=device_name)

def get_device(self, device_id, retry_limit=0):
"""
Expand Down

0 comments on commit 0b60df5

Please sign in to comment.