Fixing managed disk facts (#51781)

(cherry picked from commit 0c8c72a0bf)
This commit is contained in:
Zim Kalinowski 2019-02-15 17:07:30 +08:00 committed by Toshio Kuratomi
parent 0e4f07b5ae
commit 40055b4507
2 changed files with 16 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- azure_rm_managed_disk_facts - added missing implementation of listing managed disks by resource group

View file

@ -125,7 +125,7 @@ class AzureRMManagedDiskFacts(AzureRMModuleBase):
self.results['ansible_facts']['azure_managed_disk'] = (
self.get_item() if self.name
else self.list_items()
else (self.list_items_by_resource_group() if self.resource_group else self.list_items())
)
return self.results
@ -160,6 +160,19 @@ class AzureRMManagedDiskFacts(AzureRMModuleBase):
results.append(managed_disk_to_dict(item))
return results
def list_items_by_resource_group(self):
"""Get managed disks in a resource group"""
try:
response = self.compute_client.disks.list_by_resource_group(resource_group_name=self.resource_group)
except CloudError as exc:
self.fail('Failed to list items by resource group - {}'.format(str(exc)))
results = []
for item in response:
if self.has_tags(item.tags, self.tags):
results.append(managed_disk_to_dict(item))
return results
def main():
"""Main module execution code path"""