mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
vmware_guest: use the datacenter as a context for clone specs (#26511)
* Slight refactor on vmware_guest to fix path searching and vcsim compatibility. * Clean up pep8 errors * Fix more pep8 issues * Add assertions * Remove debug failure * Update docsting for folder with examples * Revise _get_vm_prop based on suggestions * Implement folder walker to find a folder path * More enhancements for datacenter->datacenter cloning * Fix a few pep8 issues * Remove useless check for subclass of None * Fix a few suggestions * Move serialize_spec to a util function * Group exceptions together Fixes #25011
This commit is contained in:
parent
5b898a7732
commit
10fc4417f7
6 changed files with 364 additions and 37 deletions
3
test/integration/targets/vmware_guest/aliases
Normal file
3
test/integration/targets/vmware_guest/aliases
Normal file
|
@ -0,0 +1,3 @@
|
|||
posix/ci/cloud/vcenter
|
||||
cloud/vcenter
|
||||
skip/python3
|
12
test/integration/targets/vmware_guest/tasks/main.yml
Normal file
12
test/integration/targets/vmware_guest/tasks/main.yml
Normal file
|
@ -0,0 +1,12 @@
|
|||
#- name: make sure pyvmomi is installed
|
||||
# pip:
|
||||
# name: pyvmomi
|
||||
# state: latest
|
||||
|
||||
- name: store the vcenter container ip
|
||||
set_fact:
|
||||
vcsim: "{{ lookup('env', 'vcenter_host') }}"
|
||||
- debug: var=vcsim
|
||||
|
||||
- include: poweroff_d1_c1_f0.yml
|
||||
- include: poweroff_d1_c1_f1.yml
|
|
@ -0,0 +1,40 @@
|
|||
#- name: make sure pyvmomi is installed
|
||||
# pip:
|
||||
# name: pyvmomi
|
||||
# state: latest
|
||||
|
||||
- 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: "{{ item|basename }}"
|
||||
datacenter: "{{ (item|basename).split('_')[0] }}"
|
||||
state: poweredoff
|
||||
folder: "{{ item|dirname }}"
|
||||
with_items: "{{ vmlist['json'] }}"
|
||||
register: poweroff_d1_c1_f0
|
||||
|
||||
- debug: var=poweroff_d1_c1_f0
|
||||
|
||||
- name: make sure no changes were made
|
||||
assert:
|
||||
that:
|
||||
- "poweroff_d1_c1_f0.results|map(attribute='changed')|unique|list == [False]"
|
|
@ -0,0 +1,51 @@
|
|||
#- name: make sure pyvmomi is installed
|
||||
# pip:
|
||||
# name: pyvmomi
|
||||
# state: latest
|
||||
|
||||
- name: store the vcenter container ip
|
||||
set_fact:
|
||||
vcsim: "{{ lookup('env', 'vcenter_host') }}"
|
||||
- debug: var=vcsim
|
||||
|
||||
- name: kill vcsim
|
||||
uri:
|
||||
url: "{{ 'http://' + vcsim + ':5000/killall' }}"
|
||||
- name: start vcsim with folders
|
||||
uri:
|
||||
url: "{{ 'http://' + vcsim + ':5000/spawn?datacenter=1&cluster=1&folder=1' }}"
|
||||
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
|
||||
|
||||
# https://github.com/ansible/ansible/issues/25011
|
||||
# Sending "-folders 1" to vcsim nests the datacenter under
|
||||
# the folder so that the path prefix is no longer /vm
|
||||
#
|
||||
# /F0/DC0/vm/F0/DC0_H0_VM0
|
||||
|
||||
- name: set state to poweredoff on all VMs
|
||||
vmware_guest:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcsim }}"
|
||||
username: "{{ vcsim_instance['json']['username'] }}"
|
||||
password: "{{ vcsim_instance['json']['password'] }}"
|
||||
name: "{{ item|basename }}"
|
||||
datacenter: "{{ (item|basename).split('_')[0] }}"
|
||||
state: poweredoff
|
||||
folder: "{{ item|dirname }}"
|
||||
with_items: "{{ vmlist['json'] }}"
|
||||
register: poweroff_d1_c1_f1
|
||||
|
||||
- debug: var=poweroff_d1_c1_f1
|
||||
|
||||
- name: make sure no changes were made
|
||||
assert:
|
||||
that:
|
||||
- "poweroff_d1_c1_f1.results|map(attribute='changed')|unique|list == [False]"
|
Loading…
Add table
Add a link
Reference in a new issue