agaiswin
Contributor
Contributor

Problems with OSCustomizationSpec

Jump to solution

If I want to deploy a new VM from a template by using a customization specification, I get the following error:

... define variables, blablabla ...

PS C:\WINDOWS> new-vm -host $esx -template $t -name "test2" -datastore $ds[2] -OSCustomizationSpec $cs

New-VM : 5/15/2008 1:24:40 PM New-VM 14ED62C5-4254-44B1-96E6-097713141A2B

The operation for the entity vm-162 failed with the following message: "Customization failed."

At line:1 char:7+ new-vm <<<< -host $esx -template $t -name "test2" -datastore $ds[2] -OSCustomizationSpec $cs

However, if I start the "Deploy Virtual Machine from this template" from Virtual Center and use the same customization specification, it works!

Strange enough...

I'm using ESX3.5 U1 and the latest VC built.

Toolkit built is 81531

I need this to work urgently, since I have to deploy hundreds of VMs automatically.

Thanks for any feedback

Alex

0 Kudos
1 Solution

Accepted Solutions
admin
Immortal
Immortal

I have a different workaround that shouldn't require storing plaintext passwords.


 
function Clone-Template($folder, $pool, $template, $name, $specname) {
 $folderView = get-view $folder.ID
 $templateView = get-view $template.ID
 $poolView = get-view $pool.ID
 $templateView = get-view $template.ID
 
 
 # Look up the customization spec.
 $svcRef = new-object VMware.Vim.ManagedObjectReference
 $svcRef.Type = "ServiceInstance"
 $svcRef.Value = "ServiceInstance"
 $serviceInstance = get-view $svcRef
 $csMgr = get-view $serviceInstance.Content.CustomizationSpecManager
 $spec = $csMgr.GetCustomizationSpec($specname)
 
 
 $vmclonespec = New-Object VMware.Vim.VirtualMachineCloneSpec
 $vmclonespec.Customization = $spec.Spec
 $vmclonespec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec
 $vmclonespec.location.pool = $poolView.MoRef
 $vmclonespec.powerOn = $false
 $vmclonespec.template = $false
 
 
 return $templateView.CloneVM_Task($folderView.MoRef, $name, $vmclonespec)
}
 
 
# Example Usage, I have a customization spec called Spec1 that I defined through the VI Client.
# Clone-Template -folder (get-folder vm) -pool (get-resourcepool resources) -template (get-template email-appliance) -name testing -specname Spec1
 
 

This worked for me, though I didn't join the VM to a domain, so I'm not 100% sure that will work, could someone give it a try? I've also attached the script to avoid formatting problems.

Also, I would like to mention that this will be fixed in the 1.0 release.

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership

Did you already check out this thread ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
agaiswin
Contributor
Contributor

yeah, but there is no solution either....

Looks like this is still a bug in the beta product.

I already wrote a mail to the vmware team that is referenced in the documentation of the tools.

Regards

Alex

0 Kudos
piglet
Enthusiast
Enthusiast

Here's the fix... myself and Mike ('fleeb') had a flurry of PMs a couple of weeks ago on this topic. I hope he doesn't mind me posting his response below.

In brief, so long as you're prepared to weather the security implications, it works very well. The -runasync switch also allows up to 4 clones to be generated in parallel. When using foreach syntax, you can spit these bad boys out like sausages.

Bon chance,

piglet

"The issue is related to encryption of the customization spec in the database and how it is decrypted. I believe it uses the SSL certificates of virtual center, but I'm battling with the exact same problem. However, I do have a workaround... albeit it is not ideal.

You can export the customization spec to an XML file by going in Virtual Center to Edit > Customization Specifications > Right click which you want to export and save it to an XML file. Edit this file with wordpad or another text editor.

You'll see several locations that have . You'll need to put your password there.

It is not ideal because it is in plain text, anyone who has access to your VC server can see this value. That's not great in my opinion.

I'm working on finding out what the exact issue is, if I figure it out I'll let you know.

Let me know if you have any more questions,

Mike"

agaiswin
Contributor
Contributor

Thanks Mike, that's great!

Here's what I've got back from VMWARE product management:

Unfortunately the VI Toolkit Beta has a bug related to deploying from templates.

Until 1.0 GA, you can use this function as a workaround:

function Clone-Template($template, $name) {

$folder = get-folder vm

$template = get-template $template

$templateMor = get-view $template.ID

$pool = get-resourcepool resources

$poolView = get-view $pool.ID

$vmclonespec = New-Object VMware.Vim.VirtualMachineCloneSpec

$vmclonespec.Customization = New-Object VMware.Vim.CustomizationSpec

$vmclonespec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec

$vmclonespec.location.pool = $poolView.MoRef

$vmclonespec.powerOn = $false

$vmclonespec.template = $false

return $templateMor.CloneVM_Task($folderView.MoRef, $name, $vmclonespec)

}

If you log into your VirtualCenter server you can use the function above like this:

clone-template -template

Please note that this function as written above does not support customization specs, and is not compatible with new-oscustomizationspec. If you need to use this, you will need to construct your own customization spec in vmclonespec.Customization. If you need more help with this you can use the forum or refer to our FAQ, which has an example (you can search for NicSettingMap to see the example).

0 Kudos
halr9000
Commander
Commander

As a workaround for your workaround, you could do the manipulation in powershell, and prompt for the password at runtime, then write a new XML out.

89# [xml]$osspec = gc .\tlzero.osspec.xml
90# $osspec.ConfigRoot.spec.identity.guiUnattended.password

_type                           plainText                       value
-----                           ---------                       -----
vim.vm.customization.Password   false                            PLAINTEXTPASSWORD


91# $pw = Read-Host 'enter password'
enter password: mypassword
92# $osspec.ConfigRoot.spec.identity.guiUnattended.password.value = $pw.ToString()
93# $osspec.ConfigRoot.spec.identity.guiUnattended.password.plainText = "true"
94# $osspec.Save("$(pwd)\newosspec.xml")
95# Select-String -Path .\newosspec.xml -Pattern 'mypassword'

newosspec.xml:1531:          <value>mypassword</value>

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
admin
Immortal
Immortal

I have a different workaround that shouldn't require storing plaintext passwords.


 
function Clone-Template($folder, $pool, $template, $name, $specname) {
 $folderView = get-view $folder.ID
 $templateView = get-view $template.ID
 $poolView = get-view $pool.ID
 $templateView = get-view $template.ID
 
 
 # Look up the customization spec.
 $svcRef = new-object VMware.Vim.ManagedObjectReference
 $svcRef.Type = "ServiceInstance"
 $svcRef.Value = "ServiceInstance"
 $serviceInstance = get-view $svcRef
 $csMgr = get-view $serviceInstance.Content.CustomizationSpecManager
 $spec = $csMgr.GetCustomizationSpec($specname)
 
 
 $vmclonespec = New-Object VMware.Vim.VirtualMachineCloneSpec
 $vmclonespec.Customization = $spec.Spec
 $vmclonespec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec
 $vmclonespec.location.pool = $poolView.MoRef
 $vmclonespec.powerOn = $false
 $vmclonespec.template = $false
 
 
 return $templateView.CloneVM_Task($folderView.MoRef, $name, $vmclonespec)
}
 
 
# Example Usage, I have a customization spec called Spec1 that I defined through the VI Client.
# Clone-Template -folder (get-folder vm) -pool (get-resourcepool resources) -template (get-template email-appliance) -name testing -specname Spec1
 
 

This worked for me, though I didn't join the VM to a domain, so I'm not 100% sure that will work, could someone give it a try? I've also attached the script to avoid formatting problems.

Also, I would like to mention that this will be fixed in the 1.0 release.

0 Kudos
agaiswin
Contributor
Contributor

This little function is working for me, thanks!

Would be still great to have a destination datastore as parameter...

Regards

Alex

0 Kudos
admin
Immortal
Immortal

This little function is working for me, thanks!

Would be still great to have a destination datastore as parameter...

Regards

Alex

Easy enough.



function Clone-Template($folder, $pool, $template, $name, $specname, $datastore) {
 $folderView = get-view $folder.ID
 $templateView = get-view $template.ID
 $poolView = get-view $pool.ID
 $templateView = get-view $template.ID


 # Look up the customization spec.
 $svcRef = new-object VMware.Vim.ManagedObjectReference
 $svcRef.Type = "ServiceInstance"
 $svcRef.Value = "ServiceInstance"
 $serviceInstance = get-view $svcRef
 $csMgr = get-view $serviceInstance.Content.CustomizationSpecManager
 $spec = $csMgr.GetCustomizationSpec($specname)


 $vmclonespec = New-Object VMware.Vim.VirtualMachineCloneSpec
 $vmclonespec.Customization = $spec.Spec
 $vmclonespec.location = New-Object VMware.Vim.VirtualMachineRelocateSpec
 $vmclonespec.location.pool = $poolView.MoRef
 if ($datastore) {
  $datastoreView = Get-View $datastore.ID
  $vmclonespec.location.datastore = $datastoreView.MoRef
 }
 $vmclonespec.powerOn = $false
 $vmclonespec.template = $false


 return $templateView.CloneVM_Task($folderView.MoRef, $name, $vmclonespec)
}


# Example Usage, I have a customization spec called Spec1 that I defined through the VI Client.
# Clone-Template -folder (get-folder vm) -pool (get-resourcepool resources) -template (get-template email-appliance) -name testing -specname Spec1 -datastore (get-datastore 33GB_Shared)


Again, this is just a temporary measure until we have the 1.0 release.

0 Kudos