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

Retrieve all objects from list_devices endpoint #53

Merged
merged 3 commits into from
Jul 30, 2019
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
19 changes: 19 additions & 0 deletions packet/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ def list_devices(self, project_id, params={}):
devices.append(device)
return devices

def list_all_devices(self, project_id):
raw_devices = list()
page = 1
while True:
paginate = {"page": page}
data = self.call_api("projects/%s/devices" % project_id, params=paginate)
next = self.meta["next"]
raw_devices.extend(data["devices"])
if next is None:
break
else:
page += 1

all_devices = list()
for raw_device in raw_devices:
device = Device(raw_device, self)
all_devices.append(device)
return all_devices

def create_device(
self,
project_id,
Expand Down
8 changes: 8 additions & 0 deletions test/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def test_list_devices(self):
repr(device)
self.assertIsInstance(device, packet.Device)

# TODO figure out how to properly handle this test case
# def test_list_all_devices(self):
# devices = self.manager.list_all_devices("438659f0")
# for device in devices:
# str(device)
# repr(device)
# self.assertIsInstance(device, packet.Device)

def test_create_device(self):
device = self.manager.create_device(
"438659f0", "hostname", "baremetal_0", "ewr1", "ubuntu_14_04"
Expand Down