mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds attached volumes to instance facts (#23132)
* Adds attached volumes to instance facts * Fixed identation and modified coding style * includes revisions after maintainers review * Coding style modified * simplifies getting items from dict
This commit is contained in:
parent
69c8dcc811
commit
e8f1747a88
1 changed files with 22 additions and 0 deletions
|
@ -180,6 +180,11 @@ cloudstack_instance.instance_name:
|
|||
returned: success
|
||||
type: string
|
||||
sample: i-44-3992-VM
|
||||
cloudstack_instance.volumes:
|
||||
description: List of dictionaries of the volumes attached to the instance.
|
||||
returned: success
|
||||
type: list
|
||||
sample: '[ { name: "ROOT-1369", type: "ROOT", size: 10737418240 }, { name: "data01, type: "DATADISK", size: 10737418240 } ]'
|
||||
'''
|
||||
|
||||
import base64
|
||||
|
@ -227,6 +232,20 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
|
|||
break
|
||||
return self.instance
|
||||
|
||||
def get_volumes(self, instance):
|
||||
volume_details = []
|
||||
if instance:
|
||||
args = {}
|
||||
args['account'] = instance.get('account')
|
||||
args['domainid'] = instance.get('domainid')
|
||||
args['projectid'] = instance.get('projectid')
|
||||
args['virtualmachineid'] = instance['id']
|
||||
|
||||
volumes = self.cs.listVolumes(**args)
|
||||
if volumes:
|
||||
for vol in volumes['volume']:
|
||||
volume_details.append({'size': vol['size'], 'type': vol['type'], 'name': vol['name']})
|
||||
return volume_details
|
||||
|
||||
def run(self):
|
||||
instance = self.get_instance()
|
||||
|
@ -253,6 +272,9 @@ class AnsibleCloudStackInstanceFacts(AnsibleCloudStack):
|
|||
for nic in instance['nic']:
|
||||
if nic['isdefault'] and 'ipaddress' in nic:
|
||||
self.result['default_ip'] = nic['ipaddress']
|
||||
volumes = self.get_volumes(instance)
|
||||
if volumes:
|
||||
self.result['volumes'] = volumes
|
||||
return self.result
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue