-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cs instance root_disk size update resizes the root volume #43817
Changes from all commits
8ce3f57
b8b255a
d70808c
29b7d81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,12 @@ | |
- 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 @@ def update_instance(self, instance, start_vm=True): | |
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one more question, this would also be "true" for enlargement of the disk, would this work as expected? if yes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's really only for _shrinkage http://cloudstack.apache.org/api/apidocs-4.4/user/resizeVolume.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @resmo the shrink option is only for changing the disk size to a smaller partition. It requires more actions from the user if it should success: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so, that means, we should change this condition to the following, right? root_disk_size_changed = root_disk_size < size There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, you can resize the volume up or down, but if you want to resize it down you must specify the flag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, got it! 👍 |
||
|
||
changed = [ | ||
service_offering_changed, | ||
instance_changed, | ||
security_groups_changed, | ||
ssh_key_changed, | ||
root_disk_size_changed, | ||
] | ||
|
||
if any(changed): | ||
|
@@ -787,6 +815,11 @@ def update_instance(self, instance, start_vm=True): | |
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() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we catch a just in case missing volume in the response to be cleaner?:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defensive programming doesn't help figuring it out what's wrong, in case something is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True