I'm using a hook script which calls a powershell script that executes
PowerCLI commands to change boot order. I also change guest os type and
set the mac address to be static this way. Its not very pretty but its
been working for a few months now.
'create' hook script:
setup boot order so NIC is first
cmd_setboot="powershell C:\scripts\changeGuestBootOrder.ps1 -newserv
${newserv} -server $vsphere_server"
ssh foreman@powercli-server $cmd_setboot
Powershell script:
param(
[string] $newserv,
[string] $server
)
Add-PSSnapin VMware.VimAutomation.Core
if ( $server -eq 'qa' ) {
connect-viserver -server 10.10.10.101 -protocol https -user "username"
-password ******
}
elseif ( $server -eq 'prod-az' ) {
connect-viserver -server 192.168.10.101 -protocol https -user "username"
-password ******
}
elseif ( $server -eq 'prod-sc' ) {
connect-viserver -server 172.16.10.101 -protocol https -user "username"
-password *******
}
the VM to configure
$strVMName = $newserv
the device name of the NIC to which to boot
$strBootNICDeviceName = "Network adapter 1"
the device name of the hard disk to which to boot
$strBootHDiskDeviceName = "Hard disk 1"
get the .NET View object for the VM, with a couple of select properties
$viewVM = Get-View -ViewType VirtualMachine -Property Name,
Config.Hardware.Device -Filter @{"Name" = "^$strVMName$"}
get the VirtualEthernetCard device, and then grab its Key (DeviceKey,
used later)
$intNICDeviceKey = ($viewVM.Config.Hardware.Device | ?{$_.DeviceInfo.Label
-eq $strBootNICDeviceName}).Key
bootable NIC BootOption device, for use in setting BootOrder (the
corresponding VirtualEthernetCard device on the VM has PXE enabled, assumed)
$oBootableNIC = New-Object -TypeName
VMware.Vim.VirtualMachineBootOptionsBootableEthernetDevice -Property
@{"DeviceKey" = $intNICDeviceKey}
get the VirtualDisk device, then grab its Key (DeviceKey, used later)
$intHDiskDeviceKey = ($viewVM.Config.Hardware.Device |
?{$_.DeviceInfo.Label -eq $strBootHDiskDeviceName}).Key
bootable Disk BootOption device, for use in setting BootOrder (the
corresponding VirtualDisk device is bootable, assumed)
$oBootableHDisk = New-Object -TypeName
VMware.Vim.VirtualMachineBootOptionsBootableDiskDevice -Property
@{"DeviceKey" = $intHDiskDeviceKey}
bootable CDROM device (per the docs, the first CDROM with bootable media
found is used)
$oBootableCDRom = New-Object -Type
VMware.Vim.VirtualMachineBootOptionsBootableCdromDevice
create the VirtualMachineConfigSpec with which to change the VM's boot
order
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec -Property @{
"BootOptions" = New-Object VMware.Vim.VirtualMachineBootOptions
-Property @{
## set the boot order in the spec as desired
BootOrder = $oBootableNIC, $oBootableHDisk
} ## end new-object
} ## end new-object
reconfig the VM to use the spec with the new BootOrder
$viewVM.ReconfigVM_Task($spec)
···
On Saturday, March 1, 2014 7:06:09 AM UTC-8, Jelle B wrote:
>
> In essence I am looking for a way to control the boot order of a VM.
> Currently a standard deployed VM always defaults to HDD first before
> Network , which is fine in normal operation, but is there a way to
> manipulate the boot order when the host is in build status to first try the
> network interfaces then CD then HDD ?
>
> Using this as reference I would guess fog would be capable but not enough
> in the content of it.
>
> http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2011654
>
> And yes I do realize I could just change the boot order of the VM but it
> defeats the reason I am asking it. I got the idea after seeing the lab0
> post , I need to give customers access to deploying hosts but I do not want
> to destroy the previous host and make a new one , but rather just re
> provision the existing one , less hassle on the MAC address security we
> run...
>
> But something like what lab0 is would be great simple authentication
> surface before it and our customers are good to go :P
>
>