Skip to content

Instantly share code, notes, and snippets.

@sudorandom
Forked from underscorephil/resultLimit.py
Last active December 21, 2015 05:29
Show Gist options
  • Save sudorandom/6257349 to your computer and use it in GitHub Desktop.
Save sudorandom/6257349 to your computer and use it in GitHub Desktop.
import SoftLayer
from pprint import pprint as pp
client = SoftLayer.Client(username=apiUsername, api_key=apiKey)
mask = {
'hardware': {
'datacenter': {},
'privateIpAddress': {},
'primaryNetworkComponent': {
'primaryIpAddressRecord': {
'subnet': {}
}
},
'primaryBackendNetworkComponent': {
'primaryIpAddressRecord': {
'subnet': {}
}
}
}
}
# Using the iterator to chunk download all results
hardware = [hardware for hardware in client['Account'].getHardware(
iter=True, chunk=100)]
pp.pprint(hardware)
# Using limit and offset
resultAmount = 100
offset = 0
hardware = []
while True:
result = client['Account'].getHardware(limit=100, offset=offset)
if len(result) < 1:
break
for server in result:
hardware.append(server)
offset += 100
pp.pprint(hardware)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment