VMware: Fix custom value in vmware_guest (#58157)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
51083537fa
commit
bafd06bc89
1 changed files with 15 additions and 22 deletions
|
@ -1521,30 +1521,28 @@ class PyVmomiHelper(PyVmomi):
|
||||||
self.configspec.vAppConfig = new_vmconfig_spec
|
self.configspec.vAppConfig = new_vmconfig_spec
|
||||||
self.change_detected = True
|
self.change_detected = True
|
||||||
|
|
||||||
def customize_customvalues(self, vm_obj, config_spec):
|
def customize_customvalues(self, vm_obj):
|
||||||
if len(self.params['customvalues']) == 0:
|
if len(self.params['customvalues']) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
vm_custom_spec = config_spec
|
|
||||||
vm_custom_spec.extraConfig = []
|
|
||||||
|
|
||||||
changed = False
|
|
||||||
facts = self.gather_facts(vm_obj)
|
facts = self.gather_facts(vm_obj)
|
||||||
for kv in self.params['customvalues']:
|
for kv in self.params['customvalues']:
|
||||||
if 'key' not in kv or 'value' not in kv:
|
if 'key' not in kv or 'value' not in kv:
|
||||||
self.module.exit_json(msg="customvalues items required both 'key' and 'value fields.")
|
self.module.exit_json(msg="customvalues items required both 'key' and 'value' fields.")
|
||||||
|
|
||||||
|
key_id = None
|
||||||
|
for field in self.content.customFieldsManager.field:
|
||||||
|
if field.name == kv['key']:
|
||||||
|
key_id = field.key
|
||||||
|
break
|
||||||
|
|
||||||
|
if not key_id:
|
||||||
|
self.module.fail_json(msg="Unable to find custom value key %s" % kv['key'])
|
||||||
|
|
||||||
# If kv is not kv fetched from facts, change it
|
# If kv is not kv fetched from facts, change it
|
||||||
if kv['key'] not in facts['customvalues'] or facts['customvalues'][kv['key']] != kv['value']:
|
if kv['key'] not in facts['customvalues'] or facts['customvalues'][kv['key']] != kv['value']:
|
||||||
option = vim.option.OptionValue()
|
self.content.customFieldsManager.SetField(entity=vm_obj, key=key_id, value=kv['value'])
|
||||||
option.key = kv['key']
|
self.change_detected = True
|
||||||
option.value = kv['value']
|
|
||||||
|
|
||||||
vm_custom_spec.extraConfig.append(option)
|
|
||||||
changed = True
|
|
||||||
|
|
||||||
if changed:
|
|
||||||
self.change_detected = True
|
|
||||||
|
|
||||||
def customize_vm(self, vm_obj):
|
def customize_vm(self, vm_obj):
|
||||||
|
|
||||||
|
@ -2316,12 +2314,7 @@ class PyVmomiHelper(PyVmomi):
|
||||||
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg, 'op': 'annotation'}
|
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg, 'op': 'annotation'}
|
||||||
|
|
||||||
if self.params['customvalues']:
|
if self.params['customvalues']:
|
||||||
vm_custom_spec = vim.vm.ConfigSpec()
|
self.customize_customvalues(vm_obj=vm)
|
||||||
self.customize_customvalues(vm_obj=vm, config_spec=vm_custom_spec)
|
|
||||||
task = vm.ReconfigVM_Task(vm_custom_spec)
|
|
||||||
self.wait_for_task(task)
|
|
||||||
if task.info.state == 'error':
|
|
||||||
return {'changed': self.change_applied, 'failed': True, 'msg': task.info.error.msg, 'op': 'customvalues'}
|
|
||||||
|
|
||||||
if self.params['wait_for_ip_address'] or self.params['wait_for_customization'] or self.params['state'] in ['poweredon', 'restarted']:
|
if self.params['wait_for_ip_address'] or self.params['wait_for_customization'] or self.params['state'] in ['poweredon', 'restarted']:
|
||||||
set_vm_power_state(self.content, vm, 'poweredon', force=False)
|
set_vm_power_state(self.content, vm, 'poweredon', force=False)
|
||||||
|
@ -2359,7 +2352,7 @@ class PyVmomiHelper(PyVmomi):
|
||||||
self.configure_disks(vm_obj=self.current_vm_obj)
|
self.configure_disks(vm_obj=self.current_vm_obj)
|
||||||
self.configure_network(vm_obj=self.current_vm_obj)
|
self.configure_network(vm_obj=self.current_vm_obj)
|
||||||
self.configure_cdrom(vm_obj=self.current_vm_obj)
|
self.configure_cdrom(vm_obj=self.current_vm_obj)
|
||||||
self.customize_customvalues(vm_obj=self.current_vm_obj, config_spec=self.configspec)
|
self.customize_customvalues(vm_obj=self.current_vm_obj)
|
||||||
self.configure_resource_alloc_info(vm_obj=self.current_vm_obj)
|
self.configure_resource_alloc_info(vm_obj=self.current_vm_obj)
|
||||||
self.configure_vapp_properties(vm_obj=self.current_vm_obj)
|
self.configure_vapp_properties(vm_obj=self.current_vm_obj)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue