VMware: Fix vmware_guest cloning bug (#58737)
* fix vmware_guest cloning bug * added tests for resizing disks during clone
This commit is contained in:
parent
b6273e91cf
commit
3a5d13b0d7
3 changed files with 81 additions and 1 deletions
|
@ -1851,7 +1851,9 @@ class PyVmomiHelper(PyVmomi):
|
|||
continue
|
||||
elif vm_obj is None or self.params['template']:
|
||||
# We are creating new VM or from Template
|
||||
diskspec.fileOperation = vim.vm.device.VirtualDeviceSpec.FileOperation.create
|
||||
# Only create virtual device if not backed by vmdk in original template
|
||||
if diskspec.device.backing.fileName == '':
|
||||
diskspec.fileOperation = vim.vm.device.VirtualDeviceSpec.FileOperation.create
|
||||
|
||||
# which datastore?
|
||||
if expected_disk_spec.get('datastore'):
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
# Test code for the vmware_guest module.
|
||||
# Copyright: (c) 2019, Noe Gonzalez <noe.a.gonzalez@gmail.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
- name: create new VM
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
name: clone_resize_disks_original
|
||||
datacenter: "{{ dc1 }}"
|
||||
cluster: "{{ ccr1 }}"
|
||||
folder: "{{ f0 }}"
|
||||
hardware:
|
||||
num_cpus: 1
|
||||
memory_mb: 128
|
||||
guest_id: centos7_64Guest
|
||||
disk:
|
||||
- size_gb: 1
|
||||
type: thin
|
||||
autoselect_datastore: True
|
||||
state: poweredoff
|
||||
|
||||
- name: convert to VM template
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
name: clone_resize_disks_original
|
||||
datacenter: "{{ dc1 }}"
|
||||
cluster: "{{ ccr1 }}"
|
||||
folder: "{{ f0 }}"
|
||||
is_template: True
|
||||
|
||||
- name: clone template and modify disks
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
name: clone_resize_disks_clone
|
||||
datacenter: "{{ dc1 }}"
|
||||
cluster: "{{ ccr1 }}"
|
||||
folder: "{{ f0 }}"
|
||||
disk:
|
||||
- size_gb: 2
|
||||
type: thin
|
||||
autoselect_datastore: True
|
||||
- size_gb: 3
|
||||
type: thin
|
||||
autoselect_datastore: True
|
||||
template: clone_resize_disks_original
|
||||
state: poweredoff
|
||||
register: l_clone_template_modify_disks
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- l_clone_template_modify_disks.changed | bool
|
||||
|
||||
- name: delete VM clone & original template
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
name: "{{ item }}"
|
||||
datacenter: "{{ dc1 }}"
|
||||
cluster: "{{ ccr1 }}"
|
||||
folder: "{{ f0 }}"
|
||||
state: absent
|
||||
with_items:
|
||||
- clone_resize_disks_original
|
||||
- clone_resize_disks_clone
|
|
@ -15,6 +15,7 @@
|
|||
- include: poweroff_d1_c1_f0.yml
|
||||
- include: poweroff_d1_c1_f1.yml
|
||||
- include: check_mode.yml
|
||||
- include: clone_resize_disks.yml
|
||||
- include: clone_d1_c1_f0.yml
|
||||
- include: create_d1_c1_f0.yml
|
||||
- include: cdrom_d1_c1_f0.yml
|
||||
|
@ -39,6 +40,8 @@
|
|||
with_items:
|
||||
- CDROM-Test
|
||||
- CDROM-Test-38679
|
||||
- clone_resize_disks_clone
|
||||
- clone_resize_disks_original
|
||||
- newvm_2
|
||||
- newvm_3
|
||||
- newvmnw_4
|
||||
|
|
Loading…
Reference in a new issue