INFRA-1768 | Abhishek | Add script to migrate PsqlEngineVersion to exact value

This commit is contained in:
Abhishek Katiyar
2023-04-06 21:22:24 +05:30
parent 890484c72d
commit f0c9947bc0

View File

@@ -0,0 +1,43 @@
import requests
import time
import boto3
url = "http://localhost:3000"
aws_profile = "nonprod"
cookie = "paste cookie"
x_xrf_token = 'xsrf_token here'
s = requests.Session()
s.headers.update({"cookie": cookie, 'x-xsrf-token': x_xrf_token})
dict = {}
rds_client = boto3.session.Session(profile_name=aws_profile).client("rds", region_name="ap-south-1")
engine_versions = {"test"}
for instance in rds_client.describe_db_instances()['DBInstances']:
dict[instance['DBInstanceIdentifier']] = instance['EngineVersion']
engine_versions.add(instance['EngineVersion'])
print(dict)
print("\n")
list_manifest_path = "/api/manifest/list"
r = s.get(url + list_manifest_path)
manifest_list = r.json()
dbs_not_updated = []
for i in manifest_list:
perform_post = True
r = s.get(url + "/api/manifest/" + str(i['id']))
manifest = r.json()
if ('extraResources' in manifest) and ('database' in manifest['extraResources']):
instance_name = manifest['extraResources']['database']['instanceName']
print("manifest name is", manifest['name'], "instance name is", instance_name)
if instance_name not in dict:
continue
database = manifest['extraResources']['database']
database['PsqlEngineVersion'] = dict[instance_name]
print("\n")
if perform_post:
response = s.post(url + "/api/manifest", json=manifest)
print(response.json)
time.sleep(2)