|
18 | 18 | from videoipath_automation_tool.apps.inventory.model.inventory_request_rpc import InventoryRequestRpc |
19 | 19 | from videoipath_automation_tool.connector.models.response_rpc import ResponseRPC |
20 | 20 | from videoipath_automation_tool.connector.vip_connector import VideoIPathConnector |
21 | | -from videoipath_automation_tool.utils.cross_app_utils import create_fallback_logger |
| 21 | +from videoipath_automation_tool.utils.cross_app_utils import create_fallback_logger, extract_natural_sort_key |
22 | 22 | from videoipath_automation_tool.validators.device_id import validate_device_id |
23 | 23 |
|
24 | 24 |
|
@@ -372,16 +372,27 @@ def fetch_device_ids_list(self) -> List[str]: |
372 | 372 | return [device["_id"] for device in response.data["config"]["devman"]["devices"]["_items"]] |
373 | 373 |
|
374 | 374 | def fetch_device_ids_by_driver(self, driver: DriverLiteral) -> List[str]: |
375 | | - """Method to fetch all device ids by driver id from VideoIPath-Inventory""" |
| 375 | + """Fetch all device IDs by driver ID from VideoIPath-Inventory with natural sorting.""" |
376 | 376 | driver_organization, driver_name, driver_version = extract_driver_info_from_id(driver_id=driver) |
| 377 | + |
377 | 378 | escaped_driver_organization = urllib.parse.quote(driver_organization, safe="") |
378 | 379 | escaped_driver_name = urllib.parse.quote(driver_name, safe="") |
379 | 380 | escaped_driver_version = urllib.parse.quote(driver_version, safe="") |
380 | | - url_path = f"/rest/v2/data/config/devman/devices/* where (config.driver.name='{escaped_driver_name}' and config.driver.version='{escaped_driver_version}' and config.driver.organization='{escaped_driver_organization}') /**" |
| 381 | + |
| 382 | + url_path = ( |
| 383 | + f"/rest/v2/data/config/devman/devices/* " |
| 384 | + f"where (config.driver.name='{escaped_driver_name}' " |
| 385 | + f"and config.driver.version='{escaped_driver_version}' " |
| 386 | + f"and config.driver.organization='{escaped_driver_organization}') /**" |
| 387 | + ) |
| 388 | + |
381 | 389 | response = self.vip_connector.rest.get(url_path) |
| 390 | + |
382 | 391 | if not response.data: |
383 | 392 | raise ValueError("Response data is empty.") |
384 | | - return [device["_id"] for device in response.data["config"]["devman"]["devices"]["_items"]] |
| 393 | + |
| 394 | + device_ids = [device["_id"] for device in response.data["config"]["devman"]["devices"]["_items"]] |
| 395 | + return sorted(device_ids, key=extract_natural_sort_key) |
385 | 396 |
|
386 | 397 | # --- Bulk Device Label Fetching Methods --- |
387 | 398 | def fetch_devices_factory_labels_as_dict(self) -> dict[str, str]: |
|
0 commit comments