mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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 4b41bb75207b5f88573df556cf94cfd64c843e56. * Add changelog fragment * Minor changes Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
55f0cfb2b8
commit
134b77961b
2 changed files with 54 additions and 2 deletions
2
changelogs/fragments/vmware-deploy-ovf-inject.yml
Normal file
2
changelogs/fragments/vmware-deploy-ovf-inject.yml
Normal file
|
@ -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…
Reference in a new issue