[2.8] VMware: Fix vmware_guest cloning bug
* fix vmware_guest cloning bug
* added tests for resizing disks during clone
(cherry picked from commit 3a5d13b0d7
)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
89d5830da0
commit
18fc915b15
4 changed files with 120 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- Fixed disk already exists issue while cloning guest in vmware_guest module (https://github.com/ansible/ansible/issues/56861).
|
|
@ -1841,7 +1841,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,113 @@
|
|||
# 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: Wait for Flask controller to come up online
|
||||
wait_for:
|
||||
host: "{{ vcsim }}"
|
||||
port: 5000
|
||||
state: started
|
||||
|
||||
- name: kill vcsim
|
||||
uri:
|
||||
url: http://{{ vcsim }}:5000/killall
|
||||
- name: start vcsim with no folders
|
||||
uri:
|
||||
url: http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=1&folder=0
|
||||
register: vcsim_instance
|
||||
|
||||
- name: Wait for Flask controller to come up online
|
||||
wait_for:
|
||||
host: "{{ vcsim }}"
|
||||
port: 443
|
||||
state: started
|
||||
|
||||
- name: get a list of VMS from vcsim
|
||||
uri:
|
||||
url: http://{{ vcsim }}:5000/govc_find?filter=VM
|
||||
register: vmlist
|
||||
|
||||
- name: get a list of clusters from vcsim
|
||||
uri:
|
||||
url: http://{{ vcsim }}:5000/govc_find?filter=CCR
|
||||
register: clusters
|
||||
|
||||
- name: get a list of clusters from vcsim
|
||||
uri:
|
||||
url: http://{{ vcsim }}:5000/govc_find?filter=DC
|
||||
register: datacenters
|
||||
|
||||
- debug: var=vcsim_instance
|
||||
- debug: var=vmlist
|
||||
|
||||
- name: create new VM
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcsim }}"
|
||||
username: "{{ vcsim_instance['json']['username'] }}"
|
||||
password: "{{ vcsim_instance['json']['password'] }}"
|
||||
name: clone_resize_disks_original
|
||||
datacenter: "{{ datacenters['json'][0]|basename }}"
|
||||
cluster: "{{ clusters['json'][0]|basename }}"
|
||||
folder: "/{{ (clusters['json'][0]|basename).split('_')[0] }}/vm"
|
||||
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: "{{ vcsim }}"
|
||||
username: "{{ vcsim_instance['json']['username'] }}"
|
||||
password: "{{ vcsim_instance['json']['password'] }}"
|
||||
name: clone_resize_disks_original
|
||||
datacenter: "{{ datacenters['json'][0]|basename }}"
|
||||
cluster: "{{ clusters['json'][0]|basename }}"
|
||||
folder: "/{{ (clusters['json'][0]|basename).split('_')[0] }}/vm"
|
||||
is_template: True
|
||||
|
||||
- name: clone template and modify disks
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcsim }}"
|
||||
username: "{{ vcsim_instance['json']['username'] }}"
|
||||
password: "{{ vcsim_instance['json']['password'] }}"
|
||||
name: clone_resize_disks_clone
|
||||
datacenter: "{{ datacenters['json'][0]|basename }}"
|
||||
cluster: "{{ clusters['json'][0]|basename }}"
|
||||
folder: "/{{ (clusters['json'][0]|basename).split('_')[0] }}/vm"
|
||||
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: "{{ vcsim }}"
|
||||
username: "{{ vcsim_instance['json']['username'] }}"
|
||||
password: "{{ vcsim_instance['json']['password'] }}"
|
||||
name: "{{ item }}"
|
||||
datacenter: "{{ datacenters['json'][0]|basename }}"
|
||||
cluster: "{{ clusters['json'][0]|basename }}"
|
||||
folder: "/{{ (clusters['json'][0]|basename).split('_')[0] }}/vm"
|
||||
state: absent
|
||||
with_items:
|
||||
- clone_resize_disks_original
|
||||
- clone_resize_disks_clone
|
|
@ -28,5 +28,6 @@
|
|||
- include: linked_clone_d1_c1_f0.yml
|
||||
- include: boot_firmware_d1_c1_f0.yml
|
||||
- include: clone_with_convert.yml
|
||||
- include: clone_resize_disks.yml
|
||||
#- include: max_connections.yml
|
||||
- include: mem_reservation.yml
|
||||
- include: mem_reservation.yml
|
||||
|
|
Loading…
Reference in a new issue