52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
def print_plan(plan):
|
|
if not plan:
|
|
print("Desired state contains no records.")
|
|
return
|
|
|
|
for item in plan:
|
|
h = item.desired.hostname
|
|
if item.action == "ADD":
|
|
print(f"{'ADD':<10} {h:<45} -> {item.desired.ip}")
|
|
elif item.action == "UPDATE":
|
|
print(f"{'UPDATE':<10} {h:<45} {item.current.ip} -> {item.desired.ip}")
|
|
elif item.action == "SKIP":
|
|
print(f"{'SKIP':<10} {h:<45} {item.reason}")
|
|
else:
|
|
print(f"{'UNCHANGED':<10} {h:<45} {item.desired.ip}")
|
|
|
|
|
|
def print_endpoint_plans(plans):
|
|
if not plans:
|
|
print("No apply-capable endpoints have planned actions.")
|
|
return
|
|
|
|
for plan in plans:
|
|
print(f"Endpoint: {plan.endpoint_id}")
|
|
if not plan.actions:
|
|
print(" No desired objects for this endpoint.")
|
|
continue
|
|
|
|
for action in plan.actions:
|
|
desired = action.desired
|
|
if desired is None:
|
|
identity = "(no desired object)"
|
|
else:
|
|
identity = (
|
|
f"{desired.object_type} "
|
|
f"{desired.logical_key}"
|
|
)
|
|
|
|
suffix = ""
|
|
if (
|
|
desired is not None
|
|
and desired.object_type == "dns_records"
|
|
):
|
|
target_ip = desired.payload.get("ip")
|
|
if target_ip:
|
|
suffix = f" -> {target_ip}"
|
|
|
|
print(
|
|
f" {action.operation.value.upper():<8} "
|
|
f"{identity}{suffix}"
|
|
)
|