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:
jctanner 2017-07-13 22:02:33 -04:00 committed by GitHub
parent df321e8579
commit 245a4d30b9
3 changed files with 43 additions and 1 deletions

View file

@ -1086,7 +1086,7 @@ class PyVmomiHelper(object):
datastore_freespace = 0
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' in self.params['disk'][0] and \
isinstance(self.params['disk'][0]['datastore'], str) and \

View file

@ -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]"

View file

@ -2,6 +2,7 @@
pip:
name: pyvmomi
state: latest
when: "{{ ansible_user_id == 'root' }}"
- name: store the vcenter container ip
set_fact:
@ -10,3 +11,4 @@
- include: poweroff_d1_c1_f0.yml
- include: poweroff_d1_c1_f1.yml
- include: clone_d1_c1_f0.yml