in pygenie/client.py [0:0]
def get_commands(self, filters=None, req_size=1000):
"""
Get all of the commands in a cluster.
Note:
This function takes advantage of Genie's paging process. It will
make all of the additional calls required until it retrieves all
of the commands in the Genie cluster.
Args:
filters (dict): a dictionary of filters to use. Valid key parameters
are: name, user, status, tag
req_size (int): the number of items to return per request.
Yields:
dict: a command dictionary
Examples:
>>> [i for i in get_commands()]
>>> [{...}, {...}, {...}]
>>> [i for i in get_commands(filters={'status':'OUT_OF_SERVICE'})]
>>> [{...}, {...}, {...}]
"""
filters = filters or {}
_check_type(filters, dict)
params = filters or {}
_verify_filters(params, ['name', 'user', 'size', 'status', 'tag'])
# Iterate through any responses until we get to the end
params['page'] = 0
params['size'] = req_size
while True:
resp = self.call(self.path_command, method='GET', params=params)
# TODO: Check to see if _imbedded key is missing, then break
if resp:
for command in resp['response'].get('commandList', []):
yield DotDict(command)
else:
yield None
# Break if we're at the end
if (resp['page']['totalPages']) <= (resp['page']['number'] + 1):
break
# On to the next iteration
params['page'] += 1
logger.info('Fetching additional commands from genie [%s/%s]',
params['page'], resp['page']['totalPages'])