-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support boot disk renaming and resizing.
Renames the boot disk when the `boot_disk_name` variable is defined within the profile or the VM properties. (The latter has precedence over the former). The VM disk must have the bootable flag set. By default, if `boot_disk_name` is defined, the VM name will be prepended to the boot disk name so the final name would be: `{{ vm_name }}_{{ boot_disk_name }}` This behavior can be disabled by setting the variable `boot_disk_use_vm_name_prefix` to `false`. In this case the final name of the boot disk will be the value of `boot_disk_name`. The boot disk can also be resized by defining the `boot_disk_size` variable. The value can contain a suffix that complies to the IEC 60027-2 standard (for example 10GiB, 1024MiB) Signed-off-by: Miguel Martín <[email protected]>
- Loading branch information
Showing
4 changed files
with
73 additions
and
3 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/705-support-boot-disk-resizing-renaming.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- vm_infra - Support boot disk renaming and resizing. (https://github.com/oVirt/ovirt-ansible-collection/pull/705) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
- name: "Get the '{{ current_vm.name }}' VM info" | ||
ovirt_vm_info: | ||
auth: "{{ ovirt_auth }}" | ||
pattern: "name={{ current_vm.name }}" | ||
fetch_nested: true | ||
nested_attributes: | ||
- "bootable" | ||
all_content: true | ||
register: current_vm_info | ||
|
||
- name: "Get the '{{ current_vm.name }}' VM boot disk ID" | ||
ansible.builtin.set_fact: | ||
current_vm_boot_disk_id: "{{item.id}}" | ||
loop: "{{current_vm_info.ovirt_vms[0].disk_attachments}}" | ||
when: item.bootable is defined and item.bootable | ||
|
||
- name: "Get the '{{ current_vm.name }}' VM boot disk info" | ||
ovirt_disk_info: | ||
auth: "{{ ovirt_auth }}" | ||
pattern: "id={{ current_vm_boot_disk_id }}" | ||
fetch_nested: true | ||
register: current_vm_boot_disk_info | ||
when: current_vm_boot_disk_id is defined | ||
|
||
- name: "Get the Storage Domain info from the '{{ current_vm.name }}' VM boot disk" | ||
ovirt_storage_domain: | ||
auth: "{{ovirt_auth}}" | ||
id: "{{ current_vm_boot_disk_info.ovirt_disks[0].storage_domains[0].id }}" | ||
register: current_vm_boot_disk_sd_info | ||
when: current_vm_boot_disk_id is defined | ||
|
||
- name: "Get the '{{ current_vm.name }}' VM boot disk name" | ||
ansible.builtin.set_fact: | ||
current_vm_boot_disk_name: "{{ current_vm.boot_disk_name | default(current_vm.profile.boot_disk_name) }}" | ||
when: current_vm.boot_disk_name is defined or current_vm.profile.boot_disk_name is defined | ||
|
||
- name: "Use '{{ current_vm.name }}' as prefix for the VM boot disk name" | ||
ansible.builtin.set_fact: | ||
current_vm_boot_disk_use_vm_name_prefix: "{{ current_vm.boot_disk_use_vm_name_prefix | default(current_vm.profile.boot_disk_use_vm_name_prefix) | default(true) }}" | ||
|
||
- name: "Rename the '{{ current_vm.name }}' VM boot disk" | ||
ovirt_disk: | ||
auth: "{{ ovirt_auth }}" | ||
id: "{{ current_vm_boot_disk_id }}" | ||
name: "{% if current_vm_boot_disk_use_vm_name_prefix %}{{ current_vm.name }}_{% endif %}{{ current_vm_boot_disk_name }}" | ||
vm_name: "{{ current_vm.name }}" | ||
storage_domain: "{{current_vm_boot_disk_sd_info.storagedomain.name}}" | ||
when: current_vm_boot_disk_id is defined and current_vm_boot_disk_name is defined | ||
|
||
- name: "Resize the '{{ current_vm.name }}' VM boot disk" | ||
ovirt_disk: | ||
auth: "{{ ovirt_auth }}" | ||
id: "{{ current_vm_boot_disk_id }}" | ||
size: "{{ current_vm.boot_disk_size | default(current_vm.profile.boot_disk_size) }}" | ||
vm_name: "{{current_vm.name}}" | ||
when: (current_vm.boot_disk_size is defined or current_vm.profile.boot_disk_size is defined) and current_vm_boot_disk_id is defined | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters