vmware_guest: fix datastore selection on equal sized disks and add tests (#26774)
* Fix datastore selection on equal sized disks and add tests
This commit is contained in:
parent
df321e8579
commit
245a4d30b9
3 changed files with 43 additions and 1 deletions
|
@ -1086,7 +1086,7 @@ class PyVmomiHelper(object):
|
||||||
|
|
||||||
datastore_freespace = 0
|
datastore_freespace = 0
|
||||||
for ds in datastores:
|
for ds in datastores:
|
||||||
if ds.summary.freeSpace > datastore_freespace:
|
if (ds.summary.freeSpace > datastore_freespace) or (ds.summary.freeSpace == datastore_freespace and not datastore):
|
||||||
# If datastore field is provided, filter destination datastores
|
# If datastore field is provided, filter destination datastores
|
||||||
if 'datastore' in self.params['disk'][0] and \
|
if 'datastore' in self.params['disk'][0] and \
|
||||||
isinstance(self.params['disk'][0]['datastore'], str) and \
|
isinstance(self.params['disk'][0]['datastore'], str) and \
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
- 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: get a list of VMS from vcsim
|
||||||
|
uri:
|
||||||
|
url: "{{ 'http://' + vcsim + ':5000/govc_find?filter=VM' }}"
|
||||||
|
register: vmlist
|
||||||
|
|
||||||
|
- debug: var=vcsim_instance
|
||||||
|
- debug: var=vmlist
|
||||||
|
|
||||||
|
- name: set state to poweroff on all VMs
|
||||||
|
vmware_guest:
|
||||||
|
validate_certs: False
|
||||||
|
hostname: "{{ vcsim }}"
|
||||||
|
username: "{{ vcsim_instance['json']['username'] }}"
|
||||||
|
password: "{{ vcsim_instance['json']['password'] }}"
|
||||||
|
name: "{{ 'newvm_' + item|basename }}"
|
||||||
|
template: "{{ item|basename }}"
|
||||||
|
datacenter: "{{ (item|basename).split('_')[0] }}"
|
||||||
|
disk:
|
||||||
|
- size: 0gb
|
||||||
|
type: thin
|
||||||
|
autoselect_datastore: True
|
||||||
|
state: poweredoff
|
||||||
|
folder: "{{ item|dirname }}"
|
||||||
|
with_items: "{{ vmlist['json'] }}"
|
||||||
|
register: clone_d1_c1_f0
|
||||||
|
|
||||||
|
- debug: var=clone_d1_c1_f0
|
||||||
|
|
||||||
|
- name: assert that changes were made
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]"
|
|
@ -2,6 +2,7 @@
|
||||||
pip:
|
pip:
|
||||||
name: pyvmomi
|
name: pyvmomi
|
||||||
state: latest
|
state: latest
|
||||||
|
when: "{{ ansible_user_id == 'root' }}"
|
||||||
|
|
||||||
- name: store the vcenter container ip
|
- name: store the vcenter container ip
|
||||||
set_fact:
|
set_fact:
|
||||||
|
@ -10,3 +11,4 @@
|
||||||
|
|
||||||
- include: poweroff_d1_c1_f0.yml
|
- include: poweroff_d1_c1_f0.yml
|
||||||
- include: poweroff_d1_c1_f1.yml
|
- include: poweroff_d1_c1_f1.yml
|
||||||
|
- include: clone_d1_c1_f0.yml
|
||||||
|
|
Loading…
Reference in a new issue