proper approach to query paged resources (#53500)
* proper approach to query paged resources * fixed pep8 * removed unnecessary check
This commit is contained in:
parent
a41028244d
commit
9413a6c3f1
1 changed files with 17 additions and 10 deletions
|
@ -183,18 +183,25 @@ class AzureRMResourceFacts(AzureRMModuleBase):
|
|||
|
||||
header_parameters = {}
|
||||
header_parameters['Content-Type'] = 'application/json; charset=utf-8'
|
||||
skiptoken = None
|
||||
|
||||
response = self.mgmt_client.query(self.url, "GET", query_parameters, header_parameters, None, [200, 404], 0, 0)
|
||||
|
||||
try:
|
||||
response = json.loads(response.text)
|
||||
if response is list:
|
||||
self.results['response'] = response
|
||||
else:
|
||||
self.results['response'] = [response]
|
||||
except Exception:
|
||||
self.results['response'] = []
|
||||
while True:
|
||||
if skiptoken:
|
||||
query_parameters['skiptoken'] = skiptoken
|
||||
response = self.mgmt_client.query(self.url, "GET", query_parameters, header_parameters, None, [200, 404], 0, 0)
|
||||
|
||||
try:
|
||||
response = json.loads(response.text)
|
||||
if isinstance(response, dict):
|
||||
if response.get('value'):
|
||||
self.results['response'] = self.results['response'] + response['value']
|
||||
skiptoken = response.get('nextLink')
|
||||
else:
|
||||
self.results['response'] = self.results['response'] + [response]
|
||||
except Exception:
|
||||
self.results['response'] = []
|
||||
if not skiptoken:
|
||||
break
|
||||
return self.results
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue