cloudstack: cs_volume: fix volume may be NoneType in check_mode (#2455)
This commit is contained in:
parent
800da3ae16
commit
0daedc05f5
1 changed files with 18 additions and 17 deletions
|
@ -339,27 +339,28 @@ class AnsibleCloudStackVolume(AnsibleCloudStack):
|
||||||
def attached_volume(self):
|
def attached_volume(self):
|
||||||
volume = self.present_volume()
|
volume = self.present_volume()
|
||||||
|
|
||||||
if volume.get('virtualmachineid') != self.get_vm(key='id'):
|
if volume:
|
||||||
self.result['changed'] = True
|
if volume.get('virtualmachineid') != self.get_vm(key='id'):
|
||||||
|
self.result['changed'] = True
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
volume = self.detached_volume()
|
volume = self.detached_volume()
|
||||||
|
|
||||||
if 'attached' not in volume:
|
if 'attached' not in volume:
|
||||||
self.result['changed'] = True
|
self.result['changed'] = True
|
||||||
|
|
||||||
args = {}
|
args = {}
|
||||||
args['id'] = volume['id']
|
args['id'] = volume['id']
|
||||||
args['virtualmachineid'] = self.get_vm(key='id')
|
args['virtualmachineid'] = self.get_vm(key='id')
|
||||||
args['deviceid'] = self.module.params.get('device_id')
|
args['deviceid'] = self.module.params.get('device_id')
|
||||||
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
res = self.cs.attachVolume(**args)
|
res = self.cs.attachVolume(**args)
|
||||||
if 'errortext' in res:
|
if 'errortext' in res:
|
||||||
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
self.module.fail_json(msg="Failed: '%s'" % res['errortext'])
|
||||||
poll_async = self.module.params.get('poll_async')
|
poll_async = self.module.params.get('poll_async')
|
||||||
if poll_async:
|
if poll_async:
|
||||||
volume = self.poll_job(res, 'volume')
|
volume = self.poll_job(res, 'volume')
|
||||||
return volume
|
return volume
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue