Add inject_ovf_env functionality for vmware_deploy_ovf (#51074)

* Add functionality to set hidden properties. Fixes #50299

* Add inject_ovf_env functionality

* Add xml declaration

* Revert "Add functionality to set hidden properties. Fixes #50299"

This reverts commit 4b41bb7520.

* Add changelog fragment

* Minor changes

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/51397/head
Matt Martz 6 years ago committed by GitHub
parent 55f0cfb2b8
commit 134b77961b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- vmware_deploy_ovf - Add support for 'inject_ovf_env' for injecting user input properties in OVF environment.

@ -65,6 +65,11 @@ options:
description:
- Absolute path of folder to place the virtual machine.
- If not specified, defaults to the value of C(datacenter.vmFolder).
inject_ovf_env:
description:
- Force the given properties to be inserted into an OVF Environment and injected through VMware Tools.
version_added: "2.8"
type: bool
name:
description:
- Name of the VM to work with.
@ -149,6 +154,8 @@ import tarfile
import time
import traceback
import xml.etree.ElementTree as ET
from threading import Thread
from ansible.module_utils._text import to_native
@ -509,8 +516,47 @@ class VMwareDeployOvf:
def complete(self):
self.lease.HttpNfcLeaseComplete()
def power_on(self):
def inject_ovf_env(self):
attrib = {
'xmlns': 'http://schemas.dmtf.org/ovf/environment/1',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:oe': 'http://schemas.dmtf.org/ovf/environment/1',
'xmlns:ve': 'http://www.vmware.com/schema/ovfenv',
'oe:id': '',
've:esxId': self.entity._moId
}
env = ET.Element('Environment', **attrib)
platform = ET.SubElement(env, 'PlatformSection')
ET.SubElement(platform, 'Kind').text = self.si.about.name
ET.SubElement(platform, 'Version').text = self.si.about.version
ET.SubElement(platform, 'Vendor').text = self.si.about.vendor
ET.SubElement(platform, 'Locale').text = 'US'
prop_section = ET.SubElement(env, 'PropertySection')
for key, value in self.params['properties'].items():
params = {
'oe:key': key,
'oe:value': str(value) if isinstance(value, bool) else value
}
ET.SubElement(prop_section, 'Property', **params)
opt = vim.option.OptionValue()
opt.key = 'guestinfo.ovfEnv'
opt.value = '<?xml version="1.0" encoding="UTF-8"?>' + to_native(ET.tostring(env))
config_spec = vim.vm.ConfigSpec()
config_spec.extraConfig = [opt]
task = self.entity.ReconfigVM_Task(config_spec)
wait_for_task(task)
def deploy(self):
facts = {}
if self.params['inject_ovf_env']:
self.inject_ovf_env()
if self.params['power_on']:
task = self.entity.PowerOn()
if self.params['wait']:
@ -546,6 +592,10 @@ def main():
'folder': {
'default': None,
},
'inject_ovf_env': {
'default': False,
'type': 'bool',
},
'resource_pool': {
'default': 'Resources',
},
@ -609,7 +659,7 @@ def main():
deploy_ovf = VMwareDeployOvf(module)
deploy_ovf.upload()
deploy_ovf.complete()
facts = deploy_ovf.power_on()
facts = deploy_ovf.deploy()
module.exit_json(instance=facts, changed=True)

Loading…
Cancel
Save