1 Reply Latest reply on Apr 19, 2019 3:41 PM by joshames

    Cannot Set BIOS Boot Order Using VIM25 API From C#

    AndyBWL Lurker

      (I did find a reference to a similar post about this from 2013 but no answers AFAICT and no code https://code.vmware.com/forums/2416/vsphere-management-sdk#463881|2319617)

      I am using the C# (targetting 4.5 .NET) bindings for the VIM25 API and I am trying to set the boot order.

      The code snippet is:

      cfgSpec.bootOptions = new VirtualMachineBootOptions();
      cfgSpec.bootOptions.bootOrder = new VirtualMachineBootOptionsBootableDevice[1];
      cfgSpec.bootOptions.bootOrder[0] = new VirtualMachineBootOptionsBootableCdromDevice();
      tmor = Service.ReconfigVM_Task(vmRef, cfgSpec);

      The ReconfigVM_Tasl fails with an error about incorrect paramter.

      The VM in question does have a CD/DVD device attached on IDE 1:0 and the ISO image has been attached via another API call.

      Looking for any ideas why this would be the case?

      Thanks

        • 1. Re: Cannot Set BIOS Boot Order Using VIM25 API From C#
          joshames Novice

          I know this question is a little old but I'm going to reply anyway.  When I built my app to automate VM builds, I was always frustrated because I couldn't find examples in C#.  I believe your issue is one of two things:  No device key or the way you are initializing some of the objects.  I will past some of my code which works below:

           

          VirtualMachineBootOptionsBootableEthernetDevice bootEthernet = new VirtualMachineBootOptionsBootableEthernetDevice();

                      bootEthernet.DeviceKey = 0;

           

          VirtualMachineBootOptionsBootableDiskDevice bootDisk = new VirtualMachineBootOptionsBootableDiskDevice();

                      bootDisk.DeviceKey = 1;

           

                      VirtualMachineBootOptionsBootableDevice[] bootDevices = new VirtualMachineBootOptionsBootableDevice[] { bootEthernet, bootDisk };

           

                      VirtualMachineBootOptions bootOptions = new VirtualMachineBootOptions();

           

                      bootOptions.BootOrder = bootDevices;

                      bootOptions.BootDelay = 10000;

                      bootOptions.BootRetryEnabled = true;

                      bootOptions.BootRetryDelay = 5000;

                      cSpec.BootOptions = bootOptions;