I need to create several Linux VMs from a few different templates and I'd like to use a Customization Specification profile. The template VM has 3 NICs in 3 different vlans, the 3rd one isn't suppposed to have a default gateway (this isn't my main issue). Cloning via vCenter works, after I provide the 3 IPs the VM is cloned correctly.
I'm trying to script this however this code:
$custSpec = Get-OSCustomizationSpec "D1 RedHat" | New-OSCustomizationSpec -Name "xyz"
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 1 -IpAddress 10.70.236.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.236.1
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 2 -IpAddress 10.70.237.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.237.1
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 3 -IpAddress 10.10.10.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1
$custSpec | Get-OSCustomizationNicMapping
gives some problems with PowerCLI 4.1U1. The first Set-OSCustomizationNicMapping command sets the IP correctly, but the 2nd and 3rd give:
Set-OSCustomizationNicMapping : 4/14/2011 16:23:10 Set-OSCustomizationNicMapping The property Posiotion of the object has been changed. This property represents a part of the Id of the object so this operation is ambiguous. Please get object again and run the operation.
At line:1 char:74
+ $custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping <<<< -IpMode UseStaticIP -position 2 -IpAddress 10.70.237.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.237.1
+ CategoryInfo : ResourceUnavailable: (:) [Set-OSCustomizationNicMapping], VimException
+ FullyQualifiedErrorId : Client20_ObjectVersionService_VerifyIsCurrentVersion_ExpiredObject,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetOSCustomizationNicMapping
and the customization profile is set to:
SpecId Position IPMode IPAddress DefaultGateway
------ -------- ------ --------- --------------
xyz 1 UseStaticIP 10.70.237.99 10.70.237.1
xyz 2 UseStaticIP 10.10.10.99 10.10.10.1
xyz 3 UseStaticIP 10.10.10.99 10.10.10.1
when it should be:
SpecId Position IPMode IPAddress DefaultGateway
------ -------- ------ --------- --------------
xyz 1 UseStaticIP 10.70.236.99 10.70.236.1
xyz 2 UseStaticIP 10.70.237.99 10.70.237.1
xyz 3 UseStaticIP 10.10.10.99 10.10.10.1
Why is it giving the errors above and why is it changing the IPs incorrectly?
Thanks in advance.
Hi,
This behaviour is by design. Here is the explanation:
Cause:
1. Cmdlet missuse
"Set-OSCustomizationNicMapping -Position" sets the posiotion of the passed nic mapping object.
The call below sets consecuently the posiotion of the three nic mapping objects to 1:
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 1 -IpAddress 10.70.236.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.236.1
2. Locking mechanism
So lets have the following nic mapping objects
1. mappingA
2. mappingB
3. mappingC
If you keep reference to A and B and change the posiotion of C to 1st then the references of the of A and B will expire and you will no longer be able to modify them with this old references. The reason behind this is the only identifier of A and B we know is their position and this identifier has changed - they have become 2nd and 3rd. So changing the old references with the wrong identifiers can cause only issues. Thats why we implemented the locking mechanism and you need to get the nic mapping objects again to modify them.
Solution:
$custSpec | Get-OSCustomizationNicMapping | where {$_.Position -eq 1} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.70.236.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.236.1
$custSpec | Get-OSCustomizationNicMapping | where {$_.Position -eq 2} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.70.237.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.237.1
$custSpec | Get-OSCustomizationNicMapping | where {$_.Position -eq 3} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.10.10.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1
I hope this will help.
Thanks,
Nedko
I think you have to fetch the OSCustomizationSpec before you do any change.
Can you try
$custSpec = Get-OSCustomizationSpec "D1 RedHat" | New-OSCustomizationSpec -Name "xyz"
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 1 -IpAddress 10.70.236.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.236.1
$custSpec = Get-OSCustomizationSpec "xyz"
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 2 -IpAddress 10.70.237.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.237.1$custSpec = Get-OSCustomizationSpec "xyz"
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 3 -IpAddress 10.10.10.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Bonsoir LucD,
I tried this but I get the same issue:
SpecId Position IPMode IPAddress DefaultGateway
------ -------- ------ --------- --------------
xyz 1 UseStaticIP 10.70.236.99 10.70.236.1
xyz 2 UseStaticIP 10.70.237.99 10.70.237.1
et-OSCustomizationNicMapping : 4/14/2011 16:48:07 Set-OSCustomizationNicMapping The property Posiotion of the object has been changed. This property represents a part of the Id of the obje
t so this operation is ambiguous. Please get object again and run the operation.
t C:\customer\vmware\scripts\ivdtest.ps1:5 char:75
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping <<<< -IpMode UseStaticIP -position 2 -IpAddress 10.70.237.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.237.1
+ CategoryInfo : ResourceUnavailable: (:) [Set-OSCustomizationNicMapping], VimException
+ FullyQualifiedErrorId : Client20_ObjectVersionService_VerifyIsCurrentVersion_ExpiredObject,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetOSCustomizationNicMapping
xyz 3 UseStaticIP 10.10.10.99 10.10.10.1
et-OSCustomizationNicMapping : 4/14/2011 16:48:13 Set-OSCustomizationNicMapping The property Posiotion of the object has been changed. This property represents a part of the Id of the obje
t so this operation is ambiguous. Please get object again and run the operation.
t C:\customer\vmware\scripts\ivdtest.ps1:7 char:75
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping <<<< -IpMode UseStaticIP -position 3 -IpAddress 10.10.10.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1
+ CategoryInfo : ResourceUnavailable: (:) [Set-OSCustomizationNicMapping], VimException
+ FullyQualifiedErrorId : Client20_ObjectVersionService_VerifyIsCurrentVersion_ExpiredObject,VMware.VimAutomation.ViCore.Cmdlets.Commands.SetOSCustomizationNicMapping
xyz 1 UseStaticIP 10.70.237.99 10.70.237.1
xyz 2 UseStaticIP 10.10.10.99 10.10.10.1
xyz 3 UseStaticIP 10.10.10.99 10.10.10.1
Can't get it to work either.
This looks indeed like a bug.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
This behaviour is by design. Here is the explanation:
Cause:
1. Cmdlet missuse
"Set-OSCustomizationNicMapping -Position" sets the posiotion of the passed nic mapping object.
The call below sets consecuently the posiotion of the three nic mapping objects to 1:
$custSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -position 1 -IpAddress 10.70.236.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.236.1
2. Locking mechanism
So lets have the following nic mapping objects
1. mappingA
2. mappingB
3. mappingC
If you keep reference to A and B and change the posiotion of C to 1st then the references of the of A and B will expire and you will no longer be able to modify them with this old references. The reason behind this is the only identifier of A and B we know is their position and this identifier has changed - they have become 2nd and 3rd. So changing the old references with the wrong identifiers can cause only issues. Thats why we implemented the locking mechanism and you need to get the nic mapping objects again to modify them.
Solution:
$custSpec | Get-OSCustomizationNicMapping | where {$_.Position -eq 1} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.70.236.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.236.1
$custSpec | Get-OSCustomizationNicMapping | where {$_.Position -eq 2} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.70.237.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.70.237.1
$custSpec | Get-OSCustomizationNicMapping | where {$_.Position -eq 3} | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 10.10.10.99 -SubnetMask 255.255.255.0 -DefaultGateway 10.10.10.1
I hope this will help.
Thanks,
Nedko
Thank you Nedko, this works perfectly.