cloudscale_volume: fail fast on volume type change (#52231)

* cloudscale_volume: fail fast on volume type change

Currently a volume gets resized before the type change check. With this
change, we check early and ensure we fail before any changes made.

* fix too many blank lines
This commit is contained in:
René Moser 2019-02-18 18:48:47 +01:00 committed by John R Barker
parent fcb6f136cd
commit a1ec74334a

View file

@ -261,18 +261,18 @@ def main():
volume.delete() volume.delete()
if module.params['state'] == 'present': if module.params['state'] == 'present':
for param, conv in (('server_uuids', set), ('size_gb', int)):
if module.params[param] is None:
continue
if conv(volume.info[param]) != conv(module.params[param]):
volume.update(param)
if (module.params['type'] is not None if (module.params['type'] is not None
and volume.info['type'] != module.params['type']): and volume.info['type'] != module.params['type']):
module.fail_json( module.fail_json(
msg='Cannot change type of an existing volume.', msg='Cannot change type of an existing volume.',
) )
for param, conv in (('server_uuids', set), ('size_gb', int)):
if module.params[param] is None:
continue
if conv(volume.info[param]) != conv(module.params[param]):
volume.update(param)
module.exit_json(changed=volume.changed, **volume.info) module.exit_json(changed=volume.changed, **volume.info)