1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

cs instance root_disk size update resizes the root volume (#43817)

* cloudstack: resize volume on root_disk_size changes

Signed-off-by: Yoan Blanc <yoan.blanc@exoscale.ch>
Reviewed-by: Marc-Aurèle Brothier <m@brothier.org>

* fixup! cloudstack: resize volume on root_disk_size changes

Signed-off-by: Yoan Blanc <yoan.blanc@exoscale.ch>

* fixup! fixup! cloudstack: resize volume on root_disk_size changes

Signed-off-by: Yoan Blanc <yoan.blanc@exoscale.ch>

* cs_instance: rename flag to allow_root_disk_shrink

Signed-off-by: Yoan Blanc <yoan.blanc@exoscale.ch>
This commit is contained in:
Yoan Blanc 2018-08-28 18:19:43 +02:00 committed by ansibot
parent f781f341a2
commit cf61510f48

View file

@ -147,6 +147,12 @@ options:
- Force stop/start the instance if required to apply changes, otherwise a running instance will not be changed.
type: bool
default: no
allow_root_disk_shrink:
description:
- Enables a volume shrinkage when the new size is smaller than the old one.
type: bool
default: no
version_added: '2.7'
tags:
description:
- List of tags. Tags are a list of dictionaries having keys C(key) and C(value).
@ -743,11 +749,33 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
security_groups_changed = self.security_groups_has_changed()
# Volume data
args_volume_update = {}
root_disk_size = self.module.params.get('root_disk_size')
root_disk_size_changed = False
if root_disk_size is not None:
res = self.query_api('listVolumes', type='ROOT', virtualmachineid=instance['id'])
[volume] = res['volume']
size = volume['size'] >> 30
args_volume_update['id'] = volume['id']
args_volume_update['size'] = root_disk_size
shrinkok = self.module.params.get('allow_root_disk_shrink')
if shrinkok:
args_volume_update['shrinkok'] = shrinkok
root_disk_size_changed = root_disk_size != size
changed = [
service_offering_changed,
instance_changed,
security_groups_changed,
ssh_key_changed,
root_disk_size_changed,
]
if any(changed):
@ -787,6 +815,11 @@ class AnsibleCloudStackInstance(AnsibleCloudStack):
instance = self.poll_job(instance, 'virtualmachine')
self.instance = instance
# Root disk size
if root_disk_size_changed:
async_result = self.query_api('resizeVolume', **args_volume_update)
self.poll_job(async_result, 'volume')
# Start VM again if it was running before
if instance_state == 'running' and start_vm:
instance = self.start_instance()
@ -986,6 +1019,7 @@ def main():
tags=dict(type='list', aliases=['tag']),
details=dict(type='dict'),
poll_async=dict(type='bool', default=True),
allow_root_disk_shrink=dict(type='bool', default=False),
))
required_together = cs_required_together()