How to use the pyvmomi.vim.fault.HostConfigFault function in pyvmomi

To help you get started, we’ve selected a few pyvmomi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / ansible / lib / ansible / modules / cloud / vmware / vmware_host_lockdown.py View on Github external
results['host_lockdown_state'][host.name]['previous_state'] = 'present'
                    if desired_state == 'absent':
                        host.ExitLockdownMode()
                        results['host_lockdown_state'][host.name]['current_state'] = 'absent'
                        changed = True
                    else:
                        results['host_lockdown_state'][host.name]['current_state'] = 'present'
                elif not host.config.adminDisabled:
                    results['host_lockdown_state'][host.name]['previous_state'] = 'absent'
                    if desired_state == 'present':
                        host.EnterLockdownMode()
                        results['host_lockdown_state'][host.name]['current_state'] = 'present'
                        changed = True
                    else:
                        results['host_lockdown_state'][host.name]['current_state'] = 'absent'
            except vim.fault.HostConfigFault as host_config_fault:
                self.module.fail_json(msg="Failed to manage lockdown mode for esxi"
                                          " hostname %s : %s" % (host.name, to_native(host_config_fault.msg)))
            except vim.fault.AdminDisabled as admin_disabled:
                self.module.fail_json(msg="Failed to manage lockdown mode as administrator "
                                          "permission has been disabled for "
                                          "esxi hostname %s : %s" % (host.name, to_native(admin_disabled.msg)))
            except Exception as generic_exception:
                self.module.fail_json(msg="Failed to manage lockdown mode due to generic exception for esxi "
                                          "hostname %s : %s" % (host.name, to_native(generic_exception)))
            change_list.append(changed)

        if any(change_list):
            results['changed'] = True

        self.module.exit_json(**results)

pyvmomi

VMware vSphere Python SDK

Apache-2.0
Latest version published 5 months ago

Package Health Score

85 / 100
Full package analysis

Similar packages