|
|
@ -1425,51 +1425,84 @@ class PyVmomiHelper(PyVmomi):
|
|
|
|
|
|
|
|
|
|
|
|
new_vmconfig_spec = vim.vApp.VmConfigSpec()
|
|
|
|
new_vmconfig_spec = vim.vApp.VmConfigSpec()
|
|
|
|
|
|
|
|
|
|
|
|
# This is primarily for vcsim/integration tests, unset vAppConfig was not seen on my deployments
|
|
|
|
if vm_obj:
|
|
|
|
orig_spec = vm_obj.config.vAppConfig if vm_obj.config.vAppConfig else new_vmconfig_spec
|
|
|
|
# VM exists
|
|
|
|
|
|
|
|
# This is primarily for vcsim/integration tests, unset vAppConfig was not seen on my deployments
|
|
|
|
vapp_properties_current = dict((x.id, x) for x in orig_spec.property)
|
|
|
|
orig_spec = vm_obj.config.vAppConfig if vm_obj.config.vAppConfig else new_vmconfig_spec
|
|
|
|
vapp_properties_to_change = dict((x['id'], x) for x in self.params['vapp_properties'])
|
|
|
|
|
|
|
|
|
|
|
|
vapp_properties_current = dict((x.id, x) for x in orig_spec.property)
|
|
|
|
# each property must have a unique key
|
|
|
|
vapp_properties_to_change = dict((x['id'], x) for x in self.params['vapp_properties'])
|
|
|
|
# init key counter with max value + 1
|
|
|
|
|
|
|
|
all_keys = [x.key for x in orig_spec.property]
|
|
|
|
# each property must have a unique key
|
|
|
|
new_property_index = max(all_keys) + 1 if all_keys else 0
|
|
|
|
# init key counter with max value + 1
|
|
|
|
|
|
|
|
all_keys = [x.key for x in orig_spec.property]
|
|
|
|
for property_id, property_spec in vapp_properties_to_change.items():
|
|
|
|
new_property_index = max(all_keys) + 1 if all_keys else 0
|
|
|
|
is_property_changed = False
|
|
|
|
|
|
|
|
new_vapp_property_spec = vim.vApp.PropertySpec()
|
|
|
|
for property_id, property_spec in vapp_properties_to_change.items():
|
|
|
|
|
|
|
|
is_property_changed = False
|
|
|
|
if property_id in vapp_properties_current:
|
|
|
|
new_vapp_property_spec = vim.vApp.PropertySpec()
|
|
|
|
if property_spec.get('operation') == 'remove':
|
|
|
|
|
|
|
|
new_vapp_property_spec.operation = 'remove'
|
|
|
|
if property_id in vapp_properties_current:
|
|
|
|
new_vapp_property_spec.removeKey = vapp_properties_current[property_id].key
|
|
|
|
if property_spec.get('operation') == 'remove':
|
|
|
|
is_property_changed = True
|
|
|
|
new_vapp_property_spec.operation = 'remove'
|
|
|
|
|
|
|
|
new_vapp_property_spec.removeKey = vapp_properties_current[property_id].key
|
|
|
|
|
|
|
|
is_property_changed = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# this is 'edit' branch
|
|
|
|
|
|
|
|
new_vapp_property_spec.operation = 'edit'
|
|
|
|
|
|
|
|
new_vapp_property_spec.info = vapp_properties_current[property_id]
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
for property_name, property_value in property_spec.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if property_name == 'operation':
|
|
|
|
|
|
|
|
# operation is not an info object property
|
|
|
|
|
|
|
|
# if set to anything other than 'remove' we don't fail
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Updating attributes only if needed
|
|
|
|
|
|
|
|
if getattr(new_vapp_property_spec.info, property_name) != property_value:
|
|
|
|
|
|
|
|
setattr(new_vapp_property_spec.info, property_name, property_value)
|
|
|
|
|
|
|
|
is_property_changed = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
msg = "Failed to set vApp property field='%s' and value='%s'. Error: %s" % (property_name, property_value, to_text(e))
|
|
|
|
|
|
|
|
self.module.fail_json(msg=msg)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# this is 'edit' branch
|
|
|
|
if property_spec.get('operation') == 'remove':
|
|
|
|
new_vapp_property_spec.operation = 'edit'
|
|
|
|
# attempt to delete non-existent property
|
|
|
|
new_vapp_property_spec.info = vapp_properties_current[property_id]
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
|
|
|
|
for property_name, property_value in property_spec.items():
|
|
|
|
# this is add new property branch
|
|
|
|
|
|
|
|
new_vapp_property_spec.operation = 'add'
|
|
|
|
if property_name == 'operation':
|
|
|
|
|
|
|
|
# operation is not an info object property
|
|
|
|
property_info = vim.vApp.PropertyInfo()
|
|
|
|
# if set to anything other than 'remove' we don't fail
|
|
|
|
property_info.classId = property_spec.get('classId')
|
|
|
|
continue
|
|
|
|
property_info.instanceId = property_spec.get('instanceId')
|
|
|
|
|
|
|
|
property_info.id = property_spec.get('id')
|
|
|
|
# Updating attributes only if needed
|
|
|
|
property_info.category = property_spec.get('category')
|
|
|
|
if getattr(new_vapp_property_spec.info, property_name) != property_value:
|
|
|
|
property_info.label = property_spec.get('label')
|
|
|
|
setattr(new_vapp_property_spec.info, property_name, property_value)
|
|
|
|
property_info.type = property_spec.get('type', 'string')
|
|
|
|
is_property_changed = True
|
|
|
|
property_info.userConfigurable = property_spec.get('userConfigurable', True)
|
|
|
|
|
|
|
|
property_info.defaultValue = property_spec.get('defaultValue')
|
|
|
|
|
|
|
|
property_info.value = property_spec.get('value', '')
|
|
|
|
|
|
|
|
property_info.description = property_spec.get('description')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new_vapp_property_spec.info = property_info
|
|
|
|
|
|
|
|
new_vapp_property_spec.info.key = new_property_index
|
|
|
|
|
|
|
|
new_property_index += 1
|
|
|
|
|
|
|
|
is_property_changed = True
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
if is_property_changed:
|
|
|
|
self.module.fail_json(msg="Failed to set vApp property field='%s' and value='%s'. Error: %s"
|
|
|
|
new_vmconfig_spec.property.append(new_vapp_property_spec)
|
|
|
|
% (property_name, property_value, to_text(e)))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# New VM
|
|
|
|
if property_spec.get('operation') == 'remove':
|
|
|
|
all_keys = [x.key for x in new_vmconfig_spec.property]
|
|
|
|
# attemp to delete non-existent property
|
|
|
|
new_property_index = max(all_keys) + 1 if all_keys else 0
|
|
|
|
continue
|
|
|
|
vapp_properties_to_change = dict((x['id'], x) for x in self.params['vapp_properties'])
|
|
|
|
|
|
|
|
is_property_changed = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for property_id, property_spec in vapp_properties_to_change.items():
|
|
|
|
|
|
|
|
new_vapp_property_spec = vim.vApp.PropertySpec()
|
|
|
|
# this is add new property branch
|
|
|
|
# this is add new property branch
|
|
|
|
new_vapp_property_spec.operation = 'add'
|
|
|
|
new_vapp_property_spec.operation = 'add'
|
|
|
|
|
|
|
|
|
|
|
@ -1489,8 +1522,10 @@ class PyVmomiHelper(PyVmomi):
|
|
|
|
new_vapp_property_spec.info.key = new_property_index
|
|
|
|
new_vapp_property_spec.info.key = new_property_index
|
|
|
|
new_property_index += 1
|
|
|
|
new_property_index += 1
|
|
|
|
is_property_changed = True
|
|
|
|
is_property_changed = True
|
|
|
|
if is_property_changed:
|
|
|
|
|
|
|
|
new_vmconfig_spec.property.append(new_vapp_property_spec)
|
|
|
|
if is_property_changed:
|
|
|
|
|
|
|
|
new_vmconfig_spec.property.append(new_vapp_property_spec)
|
|
|
|
|
|
|
|
|
|
|
|
if new_vmconfig_spec.property:
|
|
|
|
if new_vmconfig_spec.property:
|
|
|
|
self.configspec.vAppConfig = new_vmconfig_spec
|
|
|
|
self.configspec.vAppConfig = new_vmconfig_spec
|
|
|
|
self.change_detected = True
|
|
|
|
self.change_detected = True
|
|
|
@ -2157,6 +2192,7 @@ class PyVmomiHelper(PyVmomi):
|
|
|
|
self.configure_cpu_and_memory(vm_obj=vm_obj, vm_creation=True)
|
|
|
|
self.configure_cpu_and_memory(vm_obj=vm_obj, vm_creation=True)
|
|
|
|
self.configure_hardware_params(vm_obj=vm_obj)
|
|
|
|
self.configure_hardware_params(vm_obj=vm_obj)
|
|
|
|
self.configure_resource_alloc_info(vm_obj=vm_obj)
|
|
|
|
self.configure_resource_alloc_info(vm_obj=vm_obj)
|
|
|
|
|
|
|
|
self.configure_vapp_properties(vm_obj=vm_obj)
|
|
|
|
self.configure_disks(vm_obj=vm_obj)
|
|
|
|
self.configure_disks(vm_obj=vm_obj)
|
|
|
|
self.configure_network(vm_obj=vm_obj)
|
|
|
|
self.configure_network(vm_obj=vm_obj)
|
|
|
|
self.configure_cdrom(vm_obj=vm_obj)
|
|
|
|
self.configure_cdrom(vm_obj=vm_obj)
|
|
|
|