From d5ed8381b66cba47cf3f7f45e30b0da04c26dac5 Mon Sep 17 00:00:00 2001 From: luto Date: Mon, 2 Nov 2015 17:48:37 +0100 Subject: [PATCH 1/2] vsphere_guest: add power status to facts --- cloud/vmware/vsphere_guest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cloud/vmware/vsphere_guest.py b/cloud/vmware/vsphere_guest.py index b8adb7930c3..bee13ed4210 100644 --- a/cloud/vmware/vsphere_guest.py +++ b/cloud/vmware/vsphere_guest.py @@ -266,9 +266,23 @@ EXAMPLES = ''' hw_guest_id: "rhel6_64Guest" hw_memtotal_mb: 2048 hw_name: "centos64Guest" + hw_power_status: "POWERED ON", hw_processor_count: 2 hw_product_uuid: "ef50bac8-2845-40ff-81d9-675315501dac" +hw_power_status will be one of the following values: + - POWERED ON + - POWERED OFF + - SUSPENDED + - POWERING ON + - POWERING OFF + - SUSPENDING + - RESETTING + - BLOCKED ON MSG + - REVERTING TO SNAPSHOT + - UNKNOWN +as seen in the VMPowerState-Class of PySphere: http://git.io/vlwOq + # Remove a vm from vSphere # The VM must be powered_off or you need to use force to force a shutdown @@ -1175,6 +1189,7 @@ def gather_facts(vm): facts = { 'module_hw': True, 'hw_name': vm.properties.name, + 'hw_power_status': vm.get_status(), 'hw_guest_full_name': vm.properties.config.guestFullName, 'hw_guest_id': vm.properties.config.guestId, 'hw_product_uuid': vm.properties.config.uuid, From 7f016008130348793789cb930de365ea32c307d4 Mon Sep 17 00:00:00 2001 From: luto Date: Wed, 25 Nov 2015 17:14:19 +0100 Subject: [PATCH 2/2] vsphere_guest: when creating a guest, gather facts about it *before* disconnect --- cloud/vmware/vsphere_guest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloud/vmware/vsphere_guest.py b/cloud/vmware/vsphere_guest.py index bee13ed4210..8861fbc244d 100644 --- a/cloud/vmware/vsphere_guest.py +++ b/cloud/vmware/vsphere_guest.py @@ -1093,9 +1093,10 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest, # Power on the VM if it was requested power_state(vm, state, True) + vmfacts=gather_facts(vm) vsphere_client.disconnect() module.exit_json( - ansible_facts=gather_facts(vm), + ansible_facts=vmfacts, changed=True, changes="Created VM %s" % guest)