vmware/pyvmomi-community-samples
View on GitHubpropertyMapping not applying values to VM
Open
#689 opened on Dec 15, 2021
help wanted
Description
Hi all,
There are a couple old issues posted on this topic that haven't been answered, so I figured I would just open a new issue.
I have an existing OVA that has some custom properties in the OVF that accept values from the user (snippet):
<Property ovf:key="activation_code" ovf:type="string" ovf:userConfigurable="true">
<Label>Activation Code</Label>
<Description>Activation Code</Description>
</Property>
<Property ovf:key="cli_cmds_init" ovf:type="string" ovf:userConfigurable="true">
<Label>Initial CLI commands</Label>
<Description>Base64 encoded set of CLI commands for initial configuration</Description>
</Property>
<Property ovf:key="cli_cmds_init_url" ovf:type="string" ovf:userConfigurable="true">
<Label>Initial CLI commands URL</Label>
<Description>URL to text file that contains set of CLI commands for initial configuration</Description>
</Property>
<Property ovf:key="reset_admin_password" ovf:password="true" ovf:type="string" ovf:userConfigurable="true">
<Label>Reset admin password</Label>
<Description>Reset admin password to this value</Description>
</Property>
Reflected in script:
property = (vim.vApp.PropertyInfo) [
(vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 0,
classId = '',
instanceId = '',
id = 'activation_code',
label = 'Activation Code',
type = 'string',
typeReference = '',
userConfigurable = true,
defaultValue = '',
value = <unset>,
description = 'Activation Code'
},
(vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 1,
classId = '',
instanceId = '',
id = 'cli_cmds_init',
label = 'Initial CLI commands',
type = 'string',
typeReference = '',
userConfigurable = true,
defaultValue = '',
value = <unset>,
description = 'Base64 encoded set of CLI commands for initial configuration'
},
(vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 2,
classId = '',
instanceId = '',
id = 'cli_cmds_init_url',
label = 'Initial CLI commands URL',
type = 'string',
typeReference = '',
userConfigurable = true,
defaultValue = '',
value = <unset>,
description = 'URL to text file that contains set of CLI commands for initial configuration'
},
(vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 3,
classId = '',
instanceId = '',
id = 'reset_admin_password',
label = 'Reset admin password',
type = 'password',
typeReference = '',
userConfigurable = true,
defaultValue = '',
value = <unset>,
description = 'Reset admin password to this value'
},
I'm using the following code in deploy_ova.py to assign values to the properties:
ovf_handle = OvfHandler(ova_path)
ovf_manager = si.content.ovfManager
properties = [
vim.KeyValue(key='activation_code', value=activation_code),
vim.KeyValue(key='cli_cmds_init', value=cli_cmds),
vim.KeyValue(key='reset_admin_password', value=admin_pwd),
]
cisp = vim.OvfManager.CreateImportSpecParams(entityName=vm_name, propertyMapping=properties)
cisr = ovf_manager.CreateImportSpec(ovf_handle.get_descriptor(), resource_pool, datastore, cisp)
if cisr.error:
print("The following errors will prevent import of this OVA:")
for error in cisr.error:
print("%s" % error)
return 1
ovf_handle.set_spec(cisr)
After printing the result, I can see it (seemingly) setting the appropriate value:
property = (vim.vApp.PropertySpec) [
(vim.vApp.PropertySpec) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
operation = 'add',
removeKey = <unset>,
info = (vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 0,
classId = '',
instanceId = '',
id = 'activation_code',
label = 'Activation Code',
type = 'string',
typeReference = <unset>,
userConfigurable = true,
defaultValue = '',
value = 'AC2-LCHL-1L65-TF5Y-GC76-570T-B2JR-X1UE-7XRX-FTKC-QU5E-KNMM-FTB9-QX1E-GLYJ-09EG',
description = 'Activation Code'
}
},
(vim.vApp.PropertySpec) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
operation = 'add',
removeKey = <unset>,
info = (vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 1,
classId = '',
instanceId = '',
id = 'cli_cmds_init',
label = 'Initial CLI commands',
type = 'string',
typeReference = <unset>,
userConfigurable = true,
defaultValue = '',
value = 'ZW5hYmxlCmNvbmZpZ3VyZSB0ZXJtaW5hbAp1c2VybmFtZSBhZG1pbiBhY2Nlc3MgbmV0d29yayBlbmFibGUKaG9zdG5hbWUgMC1mZS1jbQpubyBudHAgc2VydmVyIDAuZmlyZWV5ZS5wb29sLm50cC5vcmcKbm8gbnRwIHNlcnZlciAxLmZpcmVleWUucG9vbC5udHAub3JnCm5vIG50cCBzZXJ2ZXIgMi5maXJlZXllLnBvb2wubnRwLm9yZwpubyBudHAgc2VydmVyIDMuZmlyZWV5ZS5wb29sLm50cC5vcmcKbnRwIHNlcnZlciAxMC42NS4xLjEKbm8gaW50ZXJmYWNlIGV0aGVyMSBkaGNwCm5vIGludGVyZmFjZSBldGhlcjEgemVyb2NvbmYKbm8gaW50ZXJmYWNlIGV0aGVyMSBpcHY2IGVuYWJsZQppbnRlcmZhY2UgZXRoZXIxIGlwIGFkZHJlc3MgMTAuNjUuMS4xIC8yNAppcCBkZWZhdWx0LWdhdGV3YXkgMTAuNjUuMS4xCmlwIG5hbWUtc2VydmVyIDEwLjY1LjEuMQppcCBkb21haW4tbGlzdCBhbmcudGVzdAo=',
description = 'Base64 encoded set of CLI commands for initial configuration'
}
},
(vim.vApp.PropertySpec) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
operation = 'add',
removeKey = <unset>,
info = (vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 2,
classId = '',
instanceId = '',
id = 'cli_cmds_init_url',
label = 'Initial CLI commands URL',
type = 'string',
typeReference = <unset>,
userConfigurable = true,
defaultValue = '',
value = '',
description = 'URL to text file that contains set of CLI commands for initial configuration'
}
},
(vim.vApp.PropertySpec) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
operation = 'add',
removeKey = <unset>,
info = (vim.vApp.PropertyInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 3,
classId = '',
instanceId = '',
id = 'reset_admin_password',
label = 'Reset admin password',
type = 'password',
typeReference = <unset>,
userConfigurable = true,
defaultValue = '',
value = 'xxxxxx',
description = 'Reset admin password to this value'
}
},
However, when the OVA gets deployed, it does not apply the new values to the VM.
Hopefully this provides enough info, but I'm happy to add more context. Any help would be greatly appreciated!