Skip to content

Commit ac60fa5

Browse files
authored
add --page-size option to devices cmds (#383)
* add --page-size option to devices cmds * add default to help
1 parent 5a000cf commit ac60fa5

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
The intended audience of this file is for py42 consumers -- as such, changes that don't affect
99
how a consumer would use the library (e.g. adding unit tests, updating documentation, etc) are not captured here.
1010

11+
## 1.14.5 - 2022-08-01
12+
13+
### Added
14+
15+
- `code42 devices list` and `code42 devices list-backup-sets` now accept a `--page-size <int>` option to enable manually configuring optimal page size.
16+
1117
## 1.14.4 - 2022-07-21
1218

1319
### Changed

src/code42cli/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.14.4"
1+
__version__ = "1.14.5"

src/code42cli/cmds/devices.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ def _get_device_info(sdk, device_guid):
243243
help="Limit devices to only those in the organization you specify. "
244244
"Note that child organizations will be included.",
245245
)
246+
page_size_option = click.option(
247+
"--page-size",
248+
required=False,
249+
type=int,
250+
default=100,
251+
help="Number of devices to retrieve per API call. "
252+
"Lower this value if you are getting timeouts when retrieving devices with backup info. Default: 100",
253+
)
246254

247255
include_usernames_option = click.option(
248256
"--include-usernames",
@@ -323,6 +331,7 @@ def _get_device_info(sdk, device_guid):
323331
help="Include devices only when 'creationDate' field is greater than the provided value. "
324332
"Argument format options are the same as --last-connected-before.",
325333
)
334+
@page_size_option
326335
@format_option
327336
@sdk_options()
328337
def list_devices(
@@ -340,6 +349,7 @@ def list_devices(
340349
last_connected_before,
341350
created_after,
342351
created_before,
352+
page_size,
343353
format,
344354
):
345355
"""Get information about many devices."""
@@ -359,11 +369,12 @@ def list_devices(
359369
"userUid",
360370
]
361371
df = _get_device_dataframe(
362-
state.sdk,
363-
columns,
364-
active,
365-
org_uid,
366-
(include_backup_usage or include_total_storage),
372+
sdk=state.sdk,
373+
columns=columns,
374+
page_size=page_size,
375+
active=active,
376+
org_uid=org_uid,
377+
include_backup_usage=(include_backup_usage or include_total_storage),
367378
)
368379
if exclude_most_recently_connected:
369380
most_recent = (
@@ -429,13 +440,13 @@ def _get_all_active_hold_memberships(sdk):
429440

430441

431442
def _get_device_dataframe(
432-
sdk, columns, active=None, org_uid=None, include_backup_usage=False
443+
sdk, columns, page_size, active=None, org_uid=None, include_backup_usage=False
433444
):
434445
devices_generator = sdk.devices.get_all(
435446
active=active,
436447
include_backup_usage=include_backup_usage,
437448
org_uid=org_uid,
438-
page_size=100,
449+
page_size=page_size,
439450
)
440451
devices_list = []
441452
if include_backup_usage:
@@ -514,6 +525,7 @@ def _break_backup_usage_into_total_storage(backup_usage):
514525
@inactive_option
515526
@org_uid_option
516527
@include_usernames_option
528+
@page_size_option
517529
@format_option
518530
@sdk_options()
519531
def list_backup_sets(
@@ -522,6 +534,7 @@ def list_backup_sets(
522534
inactive,
523535
org_uid,
524536
include_usernames,
537+
page_size,
525538
format,
526539
):
527540
"""Get information about many devices and their backup sets."""

tests/cmds/test_devices.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def test_get_device_dataframe_returns_correct_columns(
690690
"osVersion",
691691
"userUid",
692692
]
693-
result = _get_device_dataframe(cli_state.sdk, columns)
693+
result = _get_device_dataframe(cli_state.sdk, columns, page_size=100)
694694
assert "computerId" in result.columns
695695
assert "guid" in result.columns
696696
assert "name" in result.columns
@@ -710,7 +710,9 @@ def test_get_device_dataframe_returns_correct_columns(
710710
def test_device_dataframe_return_includes_backupusage_when_flag_passed(
711711
cli_state, get_all_devices_success
712712
):
713-
result = _get_device_dataframe(cli_state.sdk, columns=[], include_backup_usage=True)
713+
result = _get_device_dataframe(
714+
cli_state.sdk, columns=[], page_size=100, include_backup_usage=True
715+
)
714716
assert "backupUsage" in result.columns
715717

716718

@@ -738,6 +740,24 @@ def test_add_legal_hold_membership_to_device_dataframe_adds_legal_hold_columns_t
738740
assert "legalHoldName" in result.columns
739741

740742

743+
def test_list_without_page_size_option_defaults_to_100_results_per_page(
744+
cli_state, runner
745+
):
746+
runner.invoke(cli, ["devices", "list"], obj=cli_state)
747+
cli_state.sdk.devices.get_all.assert_called_once_with(
748+
active=None, include_backup_usage=False, org_uid=None, page_size=100
749+
)
750+
751+
752+
def test_list_with_page_size_option_sets_expected_page_size_in_request(
753+
cli_state, runner
754+
):
755+
runner.invoke(cli, ["devices", "list", "--page-size", "1000"], obj=cli_state)
756+
cli_state.sdk.devices.get_all.assert_called_once_with(
757+
active=None, include_backup_usage=False, org_uid=None, page_size=1000
758+
)
759+
760+
741761
def test_list_include_legal_hold_membership_pops_legal_hold_if_device_deactivated(
742762
cli_state, get_all_matter_success, get_all_custodian_success
743763
):

0 commit comments

Comments
 (0)