Hello,
My goal: deploy linux vm with specific IP address
Hypervisor: VMware ESXi, 6.7.0, 10302608
PowerCLI Version
----------------
VMware PowerCLI 11.5.0 build 14912921
---------------
Component Versions
---------------
VMware Common PowerCLI Component 11.5 build 14898112
VMware Cis Core PowerCLI Component PowerCLI Component 11.5 build 14898113
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 11.5 build 14899560
PS C:\Users\Galapow> Get-OSCustomizationNicMapping CentOS| select *
Dns :
Wins :
SpecId : CentOS
Spec : CentOS
SpecType : Persistent
NetworkAdapterMac :
Position : 1
IPMode : PromptUser
IPAddress :
SubnetMask : 255.255.248.0
DefaultGateway : 172.25.8.1
AlternateGateway :
VCApplicationArgument :
Id : XX/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-CentOS-Persistent-1/
Uid : XX/OSCustomizationNicMapping=OSCustomizationNicMappingImpl-CentOS-Persistent-1/
ExtensionData : VMware.Vim.CustomizationAdapterMapping
Version : 1
New-VM -Name deploy-infra -Host 172.25.2.2 -Datastore ESXI21_RAID5_3_27_TB -Template centos7.7-rootandvar -DiskStorageFormat Thick -OSCustomizationSpec CentOS | Set-OSCustomizationNicMapping -IpAddress 172.25.10.15 -Confirm:$false
New-VM : 2019. 12. 15. 15:59:39 New-VM The operation for the entity "centos7.7-rootandvar" failed with the following message: "A specified parameter was not correct: nicsettings:adapter:ip"
At line:1 char:1
+ New-VM -Name deploy-infra -Host 172.25.2.2 -Datastore ESXI21_RAID5_3 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], InvalidArgument
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
All my vm will have the same subnetmas and gw.
How can I deploy a vm with specific ip address and Computer name and also using template with OSCustomizationSpec ?
Thanks.
Did you already try like this?
You probably have to provide s SubnetMask and DefaultGateway as well.
$nic = Get-OSCustomizationNicMapping -OSCustomizationSpec $osCust |
Set-OSCustomizationNicMapping -IpAddress 172.25.10.15 -Confirm:$false
New-VM -Name deploy-infra -Host 172.25.2.2 -Datastore ESXI21_RAID5_3_27_TB -Template centos7.7-rootandvar -DiskStorageFormat Thick -OSCustomizationSpec $osCust
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Did you already try like this?
You probably have to provide s SubnetMask and DefaultGateway as well.
$nic = Get-OSCustomizationNicMapping -OSCustomizationSpec $osCust |
Set-OSCustomizationNicMapping -IpAddress 172.25.10.15 -Confirm:$false
New-VM -Name deploy-infra -Host 172.25.2.2 -Datastore ESXI21_RAID5_3_27_TB -Template centos7.7-rootandvar -DiskStorageFormat Thick -OSCustomizationSpec $osCust
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
PS C:\Users\Galapow> New-VM -Name deploy-infra -Host 172.25.2.2 -Datastore ESXI21_RAID5_3_27_TB -Template centos7.7-rootandvar -DiskStorageFormat Thick -OSCustomizationSpec CentOS | Set-OSCustomizationNicMapping -IpAddress 172.25.10.15 -SubnetMask 255.255.248.0 -DefaultGateway 172.25.8.1 -Confirm:$false
New-VM : 2019. 12. 15. 17:42:05 New-VM The operation for the entity "centos7.7-rootandvar" failed with the following message: "A specified parameter was not correct: nicsettings:adapter:ip"
At line:1 char:1
+ New-VM -Name deploy-infra -Host 172.25.2.2 -Datastore ESXI21_RAID5_3 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], InvalidArgument
+ FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
on the UI also asking for hostname, could be that a problem as it is not provided in cli ?
That's not the snippet I posted.
In your code, you are first running the New-VM, which produces if all goes well, a VirtualMachine object.
The Set-OSCustomizationNicMapping is not even executed since you get an error on the New-VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Get-OSCustomizationNicMapping Centos
Position IPMode IPAddress DefaultGateway
-------- ------ --------- --------------
1 PromptUser 172.25.8.1
PS C:\Users\Galapow> $nic = Get-OSCustomizationNicMapping -OSCustomizationSpec $osCust | Set-OSCustomizationNicMapping -Position 1 -IpMode UseStaticIp -IpAddress 172.25.10.15 -DefaultGateway 172.25.8.1 -Confirm:$false
Get-OSCustomizationNicMapping : Cannot bind parameter 'OSCustomizationSpec'. Cannot convert the "PromptUser" value of type "VMware.VimAutomation.ViCore.Impl.V1.OSCustomization.OSCustomizationNicMappingImpl" to type "VMware.VimAutomation.ViCore.Types.V1.OSCustomization.O
SCustomizationSpec".
At line:1 char:59
+ ... = Get-OSCustomizationNicMapping -OSCustomizationSpec $osCust | Set- ...
+ ~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-OSCustomizationNicMapping], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetOSCustomizationNicMapping
If I use without Position and ipmode I got the same error
If I change the customization on the UI for
Position IPMode IPAddress DefaultGateway
-------- ------ --------- --------------
1 UseStaticIP 127.0.0.1 172.25.8.1
$nic = Get-OSCustomizationNicMapping -OSCustomizationSpec $osCust | Set-OSCustomizationNicMapping -IpAddress 172.25.10.15 -Confirm:$false
Get-OSCustomizationNicMapping : Cannot bind parameter 'OSCustomizationSpec'. Cannot convert the "PromptUser" value of type "VMware.VimAutomation.ViCore.Impl.V1.OSCustomization.OSCustomizationNicMappingImpl" to type "VMware.VimAutomation.ViCore.Types.V1.OSCustomization.O
SCustomizationSpec".
Could be there some cache as promptuser is now usestaticip ?
You didn't use the 1st line correctly.
That object needs to be assigned to variable $osCust, which is used in the 2nd line
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I did but forget to copy it here
Just created a new customization
PS C:\Users\Galapow> $osCust = Get-OSCustomizationNicMapping Testinglinux
PS C:\Users\Galapow> $nic = Get-OSCustomizationNicMapping -OSCustomizationSpec $osCust | Set-OSCustomizationNicMapping -IpAddress 172.25.10.15 -Confirm:$false
Get-OSCustomizationNicMapping : Cannot bind parameter 'OSCustomizationSpec'. Cannot convert the "UseStaticIP:127.0.0.1" value of type "VMware.VimAutomation.ViCore.Impl.V1.OSCustomization.OSCustomizationNicMappingImpl" to type "VMware.VimAutomation.ViCore.Types.V1.OSCust
omization.OSCustomizationSpec".
At line:1 char:59
The testinglinux xml which is for custom setting for ip4
<ConfigRoot>
<_type>vim.CustomizationSpecItem</_type>
<info>
<_type>vim.CustomizationSpecInfo</_type>
<changeVersion>1576429981</changeVersion>
<description/>
<lastUpdateTime>2019-12-15T17:13:01Z</lastUpdateTime>
<name>Testinglinux</name>
<type>Linux</type>
</info>
<spec>
<_type>vim.vm.customization.Specification</_type>
<globalIPSettings>
<_type>vim.vm.customization.GlobalIPSettings</_type>
</globalIPSettings>
<identity>
<_type>vim.vm.customization.LinuxPrep</_type>
<domain>test.local</domain>
<hostName>
<_type>vim.vm.customization.VirtualMachineNameGenerator</_type>
</hostName>
<hwClockUTC>false</hwClockUTC>
<timeZone>Europe/Budapest</timeZone>
</identity>
<nicSettingMap>
<_length>1</_length>
<_type>vim.vm.customization.AdapterMapping[]</_type>
<e id="0">
<_type>vim.vm.customization.AdapterMapping</_type>
<adapter>
<_type>vim.vm.customization.IPSettings</_type>
<gateway>
<_length>1</_length>
<_type>string[]</_type>
<e id="0">172.25.8.1</e>
</gateway>
<ip>
<_type>vim.vm.customization.FixedIp</_type>
<ipAddress>127.0.0.1</ipAddress>
</ip>
<subnetMask>255.255.248.0</subnetMask>
</adapter>
</e>
</nicSettingMap>
<options>
<_type>vim.vm.customization.LinuxOptions</_type>
</options>
</spec>
</ConfigRoot>
The Centos xml which currently set to "Prompt the user for an IPv4 address when the specification is used"
<ConfigRoot>
<_type>vim.CustomizationSpecItem</_type>
<info>
<_type>vim.CustomizationSpecInfo</_type>
<changeVersion>1576430632</changeVersion>
<description>CentOS network cutomizations for deployment</description>
<lastUpdateTime>2019-12-15T17:23:52Z</lastUpdateTime>
<name>CentOS</name>
<type>Linux</type>
</info>
<spec>
<_type>vim.vm.customization.Specification</_type>
<globalIPSettings>
<_type>vim.vm.customization.GlobalIPSettings</_type>
</globalIPSettings>
<identity>
<_type>vim.vm.customization.LinuxPrep</_type>
<domain>test.local</domain>
<hostName>
<_type>vim.vm.customization.VirtualMachineNameGenerator</_type>
</hostName>
<hwClockUTC>false</hwClockUTC>
<timeZone>Europe/Budapest</timeZone>
</identity>
<nicSettingMap>
<_length>1</_length>
<_type>vim.vm.customization.AdapterMapping[]</_type>
<e id="0">
<_type>vim.vm.customization.AdapterMapping</_type>
<adapter>
<_type>vim.vm.customization.IPSettings</_type>
<gateway>
<_length>1</_length>
<_type>string[]</_type>
<e id="0">172.25.8.1</e>
</gateway>
<ip>
<_type>vim.vm.customization.UnknownIpGenerator</_type>
</ip>
<subnetMask>255.255.248.0</subnetMask>
</adapter>
</e>
</nicSettingMap>
<options>
<_type>vim.vm.customization.LinuxOptions</_type>
</options>
</spec>
</ConfigRoot>
Probably I can generate xmls which I import and use it then delete and so on but it is very nasty.
Maybe my approach is not the best and there is another way to do this from cli ?
That is my bad, that first line should be
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The final commands
$osCust = Get-OSCustomizationSpec Centos
$nic = Get-OSCustomizationNicMapping -OSCustomizationSpec $osCust | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 172.25.10.15 -SubnetMask 255.255.248.0 -DefaultGateway 172.25.8.1 -Confirm:$false
New-VM -Name deploy-infra -Host 172.25.2.2 -Datastore ESXI21_RAID5_3_27_TB -Template centos7.7-rootandvar -DiskStorageFormat Thick -OSCustomizationSpec $osCust
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
deploy-infra PoweredOff 2 8,000
Even in the customization the default gw and subnet is provided I have to provide again in the cli
Where, when and how are you prompted?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I mean in the command I have to provide again
"-SubnetMask 255.255.248.0 -DefaultGateway 172.25.8.1"
Can you show what you are getting on the console?
A screenshot is fine
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think I'm explaining it wrong
On the UI I already configured subnet mask and GW for the customization
In the command line I provide them again
I dont get any popups if you asking that.
Ok, I get it.
That is no problem, the values on the Set-OSCustomizationNicMapping will overwrite what you already have.
In the GUI you can't get past that page without providing a Netmask.
The Default Gateway can be left blank.
On the Set-OSCustomizationNicMapping cmdlet, you have to provide, when IPMode is set to UseStaticIP, the IPAddress, the SubnetMask and the DefaultGateway.
That is who the Web CLient and the cmdlet have been written I'm afraid
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference