Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devices): filter device list by name #87

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading