Skip to content

Instantly share code, notes, and snippets.

@lucadentella
Created March 22, 2022 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucadentella/60034a775b820c20f925b642c5dc6299 to your computer and use it in GitHub Desktop.
Save lucadentella/60034a775b820c20f925b642c5dc6299 to your computer and use it in GitHub Desktop.
# You need Python Openshift Client (https://github.com/openshift/openshift-client-python)
import openshift as oc
akoAnnotation = "ako.vmware.com/host-fqdn-vs-uuid-map"
outputFile = "vs_mapping.csv"
vsMapping = {}
print("Get AVI Virtual Services\n")
# Get all the routes in the cluster
routeSelector = oc.selector("routes", all_namespaces=True)
routes = routeSelector.objects()
print("Number of routes found: ", len(routes), "\n")
for route in routes:
print("----- Route: ", route.name(), " -----")
# Check if AKO annotated this route
if akoAnnotation in route.model.metadata.annotations:
annotation = route.model.metadata.annotations[akoAnnotation]
print("Found AKO annotation: ", annotation)
# Parse the annotation to get FQDN and VS
annotationElements = annotation.replace("{", "").replace("}", "").replace("\"", "").split(":")
fqdn = annotationElements[0]
vs = annotationElements[1]
print("FQDN:\t", fqdn)
print("VS:\t", vs)
# Add the new mapping if not already present
if fqdn in vsMapping:
print("FQDN already in dictionary")
else:
vsMapping[fqdn] = vs
print("Mapping added to dictonary")
print()
# Write output file
print("Writing output file... ", end='')
f = open(outputFile, "w")
for fqdn in vsMapping:
f.write(fqdn + "," + vsMapping[fqdn] + "\n")
f.close
print("done!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment