mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00:00
VMware: Update vmware_guest_powerstate (#57000)
* Updated documentation * Updated testcases * Updated example * Updated logic * Provided option to specify task name, task description, task enable status etc. Fixes: #56987 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
setup_attach_host: true
|
||||
setup_datastore: true
|
||||
setup_virtualmachines: true
|
||||
|
||||
- name: set state to poweroff the first VM
|
||||
vmware_guest_powerstate:
|
||||
validate_certs: False
|
||||
@@ -19,9 +20,29 @@
|
||||
state: powered-off
|
||||
register: poweroff_d1_c1_f0
|
||||
|
||||
- debug: var=poweroff_d1_c1_f0
|
||||
- debug:
|
||||
var: poweroff_d1_c1_f0
|
||||
|
||||
- name: make sure change was made
|
||||
assert:
|
||||
that:
|
||||
- poweroff_d1_c1_f0.changed
|
||||
|
||||
- when: vcsim is not defined
|
||||
block:
|
||||
- name: Set a schedule task for first VM
|
||||
vmware_guest_powerstate:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcenter_hostname }}"
|
||||
username: "{{ vcenter_username }}"
|
||||
password: "{{ vcenter_password }}"
|
||||
name: "{{ virtual_machines[0].name }}"
|
||||
folder: "{{ virtual_machines[0].folder }}"
|
||||
scheduled_at: "10/10/2030 10:10"
|
||||
state: powered-on
|
||||
register: poweron_d1_c1_f0
|
||||
|
||||
- name: Check that task is schedule
|
||||
assert:
|
||||
that:
|
||||
- poweron_d1_c1_f0.changed
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
# Test code for the vmware_guest_powerstate module.
|
||||
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.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
|
||||
|
||||
- debug: var=vcsim_instance
|
||||
- debug: var=vmlist
|
||||
|
||||
- name: set state to poweroff on all VMs
|
||||
vmware_guest_powerstate:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcsim }}"
|
||||
username: "{{ vcsim_instance['json']['username'] }}"
|
||||
password: "{{ vcsim_instance['json']['password'] }}"
|
||||
name: "{{ item|basename }}"
|
||||
state: powered-off
|
||||
folder: "{{ item|dirname }}"
|
||||
with_items: "{{ virtual_machines }}"
|
||||
register: poweroff_d1_c1_f0
|
||||
|
||||
- debug: var=poweroff_d1_c1_f0
|
||||
|
||||
# vcsim (v0.18.0) VMs are spawned PoweredOn
|
||||
- name: make sure changes were made
|
||||
assert:
|
||||
that:
|
||||
- "poweroff_d1_c1_f0.results|map(attribute='changed')|unique|list == [True]"
|
||||
@@ -1,58 +0,0 @@
|
||||
# Test code for the vmware_guest_powerstate module.
|
||||
# Copyright: (c) 2017, Abhijeet Kasurde <akasurde@redhat.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 folders
|
||||
uri:
|
||||
url: http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=1&folder=1
|
||||
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
|
||||
|
||||
- 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_powerstate:
|
||||
validate_certs: False
|
||||
hostname: "{{ vcsim }}"
|
||||
username: "{{ vcsim_instance['json']['username'] }}"
|
||||
password: "{{ vcsim_instance['json']['password'] }}"
|
||||
name: "{{ item|basename }}"
|
||||
state: powered-off
|
||||
folder: "{{ item|dirname }}"
|
||||
with_items: "{{ vmlist['json'] }}"
|
||||
register: poweroff_d1_c1_f1
|
||||
|
||||
- debug: var=poweroff_d1_c1_f1
|
||||
|
||||
# vcsim (v0.18.0) VMs are spawned PoweredOn
|
||||
- name: make sure changes were made
|
||||
assert:
|
||||
that:
|
||||
- "poweroff_d1_c1_f1.results|map(attribute='changed')|unique|list == [True]"
|
||||
Reference in New Issue
Block a user