Skip to content

Commit

Permalink
Adds attached volumes to instance facts (ansible#23132)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
khnazaretyan authored and resmo committed Apr 9, 2017
1 parent 69c8dcc commit e8f1747
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/ansible/modules/cloud/cloudstack/cs_instance_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@
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
Expand Down Expand Up @@ -227,6 +232,20 @@ def get_instance(self):
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()
Expand All @@ -253,6 +272,9 @@ def get_result(self, instance):
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


Expand Down

0 comments on commit e8f1747

Please sign in to comment.