Created
March 22, 2022 13:33
-
-
Save lucadentella/60034a775b820c20f925b642c5dc6299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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