Files
deployment-portal-be/scripts/rds_version_migration.py

39 lines
1.5 KiB
Python
Raw Permalink Normal View History

import requests
import time
import boto3
url = "https://navi-pay-deployment-portal.cmd.navi-tech.in"
aws_profile = "navi-pay-nonprod"
cookie = "paste your cookie here"
x_xrf_token = 'paste xsrf_token here'
s = requests.Session()
s.headers.update({"cookie": cookie, 'x-xsrf-token': x_xrf_token})
instance_version_map = {}
rds_client = boto3.session.Session(profile_name=aws_profile).client("rds", region_name="ap-south-1")
for instance in rds_client.get_paginator('describe_db_instances').paginate().build_full_result()['DBInstances']:
instance_version_map[instance['DBInstanceIdentifier']] = instance['EngineVersion']
print(instance_version_map)
print("\n")
list_manifest_path = "/api/manifest/list"
r = s.get(url + list_manifest_path)
manifest_list = r.json()
for i in manifest_list:
2023-04-07 14:29:52 +05:30
perform_post = False
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 instance_version_map:
continue
database = manifest['extraResources']['database']
database['PsqlEngineVersion'] = instance_version_map[instance_name]
2023-04-07 14:29:52 +05:30
perform_post = True
print("\n")
if perform_post:
response = s.post(url + "/api/manifest", json=manifest)
print(response.json())
time.sleep(2)