summaryrefslogtreecommitdiff
path: root/tools/get-ss-kubeconfig.py
diff options
context:
space:
mode:
authorckonstanski <kostcarl@isu.edu>2026-07-30 18:17:14 -0600
committerckonstanski <kostcarl@isu.edu>2026-07-30 18:17:14 -0600
commit640ff61422bc0ee3966941b93d9889ddbbd38d77 (patch)
treeabf1c08f5d38ee53ec8b29dc4f425722517505e6 /tools/get-ss-kubeconfig.py
parent22dae02a86c1fce71091bfa5289cf99abba1b217 (diff)
more filesHEADmaster
Diffstat (limited to 'tools/get-ss-kubeconfig.py')
-rw-r--r--tools/get-ss-kubeconfig.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/tools/get-ss-kubeconfig.py b/tools/get-ss-kubeconfig.py
new file mode 100644
index 0000000..b04db8a
--- /dev/null
+++ b/tools/get-ss-kubeconfig.py
@@ -0,0 +1,92 @@
+import json
+import requests
+import os
+import os.path
+import sys
+import time
+import psycopg2
+
+class KubeconfigGetter():
+
+ def _get_db_connection(self):
+ conn = None
+ try:
+ conn = psycopg2.connect(
+ host='xxxxx',
+ port='5432',
+ database="xxxxx",
+ user="xxxxx",
+ password='xxxxx')
+ except Exception as e:
+ print(e)
+ return conn
+
+ def get_cluster_name(self, fuze_spm_site_id):
+ cluster_name = ''
+ try:
+ conn = self._get_db_connection()
+
+ # create a cursor
+ cur = conn.cursor()
+
+ # execute a statement
+ #print('select cluster_name, fuze_spm_site_id, fuze_spm_site_name, oam_vip_address from caas_cluster join caas_location on caas_cluster.location_id=caas_location.id where fuze_spm_site_id = ' + fuze_spm_site_id)
+ sql = 'select cluster_name from caas_cluster join caas_location on caas_cluster.location_id=caas_location.id where fuze_spm_site_id=' + '\'' + fuze_spm_site_id + '\''
+ cur.execute(sql)
+
+ # display the PostgreSQL database server version
+ cluster_name = cur.fetchone()[0]
+ #print(cluster_name)
+
+ # close the communication with the PostgreSQL
+ cur.close()
+ except (Exception, psycopg2.DatabaseError) as error:
+ print(error)
+ if conn is not None:
+ conn.close()
+ print('Database connection closed.')
+ return str(cluster_name)
+
+ def get_kubeconfig(self, site_name):
+ #url = "http://192.168.31.20/orchestration/remote-regions/" + site_name + "/kubeconfig/vendor/samsung"
+ url = "https://middleware.vcpfe.vzwops.com/orchestration/remote-regions/" + site_name + "/connection-details?team=samsung"
+ url1 = "https://middleware.vcpfe.vzwops.com/orchestration/remote-regions/" + site_name + "/connection-details"
+ resp = requests.get(url, verify=False)
+ #print(resp.json())
+ transaction_id = resp.json()['transaction_id']
+ #print(transaction_id)
+ url2 = url1 + "/" + transaction_id
+ #print(url2)
+ time.sleep(10)
+ resp1 = requests.get(url2, verify=False)
+ #print(resp1.json())
+ kubeconfig = resp1.json()['remote_region_setup'][0]["kube_config"]
+ #print(kubeconfig)
+ if not os.path.exists("samsung-kubeconfigs"):
+ os.makedirs("samsung-kubeconfigs")
+ fp = open("samsung-kubeconfigs/" + site_name + ".conf", "w")
+ fp.write(kubeconfig)
+ fp.close()
+
+if __name__ == '__main__':
+
+ if len(sys.argv) < 2:
+ print("python get-ss-kubeconfig.py <site-list-file>")
+ print(" Make sure to populate database creds in this file.")
+ print(" Use it from a server from which database is accessible (e.g.: app1 or app2)")
+ exit(0)
+
+ site_list_file = sys.argv[1]
+ fp = open(site_list_file, "r")
+ lines = fp.read()
+ kubeconfigGetter = KubeconfigGetter()
+ for fuze_site_id in lines.split("\n"):
+ fuze_site_id = fuze_site_id.lstrip().rstrip()
+ if fuze_site_id != '':
+ #print(fuze_site_id)
+ cluster_name = kubeconfigGetter.get_cluster_name(fuze_site_id)
+ kubeconfigGetter.get_kubeconfig(cluster_name)
+ #fuze_site_id = sys.argv[1]
+ #print(lines)
+ #print(fuze_site_id + " " + cluster_name)
+ print("Done")