Python Example of Configuring the Boot Options

The following example is based on the code of the
boot.py
sample file.
For a complete and up-to-date version of the sample code, see the vSphere Automation SDK Python samples at GitHub.
... """ Demonstrates how to configure the settings used when booting a virtual machine. Sample Prerequisites: The sample needs an existing VM. """ vm = None vm_name = None stub_config = None boot_svc = None cleardata = False orig_boot_info = None ... def run(): global vm vm = get_vm(stub_config, vm_name) if not vm: exit('Sample requires an existing vm with name ({}). ' 'Please create the vm first.'.format(vm_name)) print("Using VM '{}' ({}) for Boot Sample".format(vm_name, vm)) # Create Boot stub used for making requests global boot_svc boot_svc = Boot(stub_config) print('\n# Example: Get current Boot configuration') boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) # Save current Boot info to verify that we have cleaned up properly global orig_boot_info orig_boot_info = boot_info print('\n# Example: Update firmware to EFI for Boot configuration') update_spec = Boot.UpdateSpec(type=Boot.Type.EFI) print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec)) boot_svc.update(vm, update_spec) boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) print('\n# Example: Update boot firmware to tell it to enter setup mode on ' 'next boot') update_spec = Boot.UpdateSpec(enter_setup_mode=True) print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec)) boot_svc.update(vm, update_spec) boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) print('\n# Example: Update boot firmware to introduce a delay in boot' ' process and to reboot') print('# automatically after a failure to boot. ' '(delay=10000 ms, retry=True,') print('# retry_delay=30000 ms') update_spec = Boot.UpdateSpec(delay=10000, retry=True, retry_delay=30000) print('vm.hardware.Boot.update({}, {})'.format(vm, update_spec)) boot_svc.update(vm, update_spec) boot_info = boot_svc.get(vm) print('vm.hardware.Boot.get({}) -> {}'.format(vm, pp(boot_info))) ...