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

Read paginated response for gallery image versions #1073

Merged
merged 2 commits into from
Feb 8, 2023
Merged
Changes from 1 commit
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
41 changes: 30 additions & 11 deletions plugins/modules/azure_rm_galleryimageversion_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ def get(self):

def listbygalleryimage(self):
response = None
results = {}
results = dict(
response=[]
)
# prepare url
self.url = ('/subscriptions' +
'/{{ subscription_id }}' +
Expand All @@ -230,20 +232,37 @@ def listbygalleryimage(self):
self.url = self.url.replace('{{ image_name }}', self.gallery_image_name)

try:
response = self.mgmt_client.query(self.url,
'GET',
self.query_parameters,
self.header_parameters,
None,
self.status_code,
600,
30)
results = json.loads(response.text)
skiptoken = None

while True:
if skiptoken:
self.query_parameters['skiptoken'] = skiptoken

response = self.mgmt_client.query(self.url,
'GET',
self.query_parameters,
self.header_parameters,
None,
[200, 404],
0,
0)
try:
response = json.loads(response.text)
if isinstance(response, dict):
if response.get('value'):
results['response'] = results['response'] + response['value']
skiptoken = response.get('nextLink')
else:
results['response'] = results['response'] + [response]
except Exception as e:
self.fail('Failed to parse response: ' + str(e))
if not skiptoken:
break
# self.log('Response : {0}'.format(response))
except CloudError as e:
self.log('Could not get info for @(Model.ModuleOperationNameUpper).')

return [self.format_item(x) for x in results['value']] if results['value'] else []
return [self.format_item(x) for x in results['response']] if results['response'] else []

def format_item(self, item):
d = {
Expand Down