Source code for saltext.vcf.states.vcf_esxi_auth_proxy
"""Idempotent state module for the ESXi vSphere Authentication Proxy (CAM).
Fulfils 912-controls ``ESXi.enable-auth-proxy`` — configure the auth proxy
address and (optionally) join AD through it so credentials never leave the
CAM appliance.
"""
from saltext.vcf.clients import esxi_auth_proxy as c
__virtualname__ = "vcf_esxi_auth_proxy"
def __virtual__():
return __virtualname__
def _ret(name):
return {"name": name, "changes": {}, "result": True, "comment": ""}
[docs]
def joined(name, domain, cam_server, host=None, profile=None):
"""Ensure *host* is AD-joined to *domain* via the CAM at *cam_server*.
No-op if the host is already joined to the same domain. Different
domain -> error (caller must first :func:`left` to move between domains
intentionally).
"""
target = host or name
ret = _ret(name)
current = c.get_config(__opts__, target, profile=profile)
if current.get("joined") and (current.get("domain") or "").lower() == domain.lower():
ret["comment"] = f"already joined to {domain}"
return ret
if current.get("joined") and current.get("domain"):
ret["result"] = False
ret["comment"] = (
f"joined to {current['domain']!r}, refusing to switch to {domain!r};"
" use vcf_esxi_auth_proxy.left first"
)
return ret
if __opts__.get("test"):
ret["result"] = None
ret["comment"] = f"would join {domain} via CAM {cam_server}"
return ret
task_id = c.join_domain_via_cam(__opts__, target, domain, cam_server, profile=profile)
ret["changes"] = {"joined": {"old": current.get("domain"), "new": domain}, "task": task_id}
ret["comment"] = f"joined {domain} via CAM {cam_server}"
return ret
[docs]
def left(name, force=False, host=None, profile=None):
"""Ensure the host is not joined to any AD domain."""
target = host or name
ret = _ret(name)
current = c.get_config(__opts__, target, profile=profile)
if not current.get("joined"):
ret["comment"] = "not joined to any AD domain"
return ret
if __opts__.get("test"):
ret["result"] = None
ret["comment"] = f"would leave domain {current.get('domain')}"
return ret
task_id = c.leave_domain(__opts__, target, force=force, profile=profile)
ret["changes"] = {"joined": {"old": current.get("domain"), "new": None}, "task": task_id}
ret["comment"] = f"left domain {current.get('domain')}"
return ret