@@ -2413,3 +2413,103 @@ def exit_maintenance_mode(host, timeout=0, catch_task_error=True, service_instan
24132413 mode = in_maintenance_mode (host_ref , service_instance )
24142414 mode ["changes" ] = mode ["maintenanceMode" ] == "normal"
24152415 return mode
2416+
2417+
2418+ def in_lockdown_mode (host , service_instance = None ):
2419+ """
2420+ Check if host is in lockdown mode.
2421+
2422+ host
2423+ Host IP or HostSystem/ManagedObjectReference (required).
2424+
2425+ service_instance
2426+ Use this vCenter service connection instance instead of creating a new one (optional).
2427+
2428+ .. code-block:: bash
2429+
2430+ salt '*' vmware_esxi.in_lockdown_mode '10.288.6.117'
2431+ """
2432+ if isinstance (host , vim .HostSystem ):
2433+ host_ref = host
2434+ else :
2435+ if service_instance is None :
2436+ service_instance = get_service_instance (opts = __opts__ , pillar = __pillar__ )
2437+ host_ref = utils_esxi .get_host (host , service_instance )
2438+ mode = "normal"
2439+ if host_ref .config .adminDisabled :
2440+ mode = "inLockdown"
2441+ return {"lockdownMode" : mode }
2442+
2443+
2444+ def lockdown_mode (host , catch_task_error = True , service_instance = None ):
2445+ """
2446+ Put host into lockdown mode.
2447+
2448+ host
2449+ Host IP or HostSystem/ManagedObjectReference (required).
2450+
2451+ catch_task_error
2452+ If False and task failed then a salt exception will be thrown (optional).
2453+
2454+ service_instance
2455+ Use this vCenter service connection instance instead of creating a new one (optional).
2456+
2457+ .. code-block:: bash
2458+
2459+ salt '*' vmware_esxi.lockdown_mode '10.288.6.117'
2460+ """
2461+ if isinstance (host , vim .HostSystem ):
2462+ host_ref = host
2463+ else :
2464+ if service_instance is None :
2465+ service_instance = get_service_instance (opts = __opts__ , pillar = __pillar__ )
2466+ host_ref = utils_esxi .get_host (host , service_instance )
2467+ mode = in_lockdown_mode (host_ref )
2468+ if mode ["lockdownMode" ] == "inLockdown" :
2469+ mode ["changes" ] = False
2470+ return mode
2471+ try :
2472+ host_ref .EnterLockdownMode ()
2473+ except salt .exceptions .SaltException as exc :
2474+ if not catch_task_error :
2475+ raise exc
2476+ mode = in_lockdown_mode (host_ref , service_instance )
2477+ mode ["changes" ] = mode ["lockdownMode" ] == "inLockdown"
2478+ return mode
2479+
2480+
2481+ def exit_lockdown_mode (host , catch_task_error = True , service_instance = None ):
2482+ """
2483+ Put host out of lockdown mode.
2484+
2485+ host
2486+ Host IP or HostSystem/ManagedObjectReference (required).
2487+
2488+ catch_task_error
2489+ If False and task failed then a salt exception will be thrown (optional).
2490+
2491+ service_instance
2492+ Use this vCenter service connection instance instead of creating a new one (optional).
2493+
2494+ .. code-block:: bash
2495+
2496+ salt '*' vmware_esxi.exit_lockdown_mode '10.288.6.117'
2497+ """
2498+ if isinstance (host , vim .HostSystem ):
2499+ host_ref = host
2500+ else :
2501+ if service_instance is None :
2502+ service_instance = get_service_instance (opts = __opts__ , pillar = __pillar__ )
2503+ host_ref = utils_esxi .get_host (host , service_instance )
2504+ mode = in_lockdown_mode (host_ref )
2505+ if mode ["lockdownMode" ] == "normal" :
2506+ mode ["changes" ] = False
2507+ return mode
2508+ try :
2509+ host_ref .ExitLockdownMode ()
2510+ except salt .exceptions .SaltException as exc :
2511+ if not catch_task_error :
2512+ raise exc
2513+ mode = in_lockdown_mode (host_ref , service_instance )
2514+ mode ["changes" ] = mode ["lockdownMode" ] == "normal"
2515+ return mode
0 commit comments