import clusters import backups import projects import networks import tokens import vpcpeering import requests import time import json webhook= 'https://open.feishu.cn/open-apis/bot/v2/hook/144b1293-9048-4e3b-b1ae-93ef6844e829' def post_to_feishu( env , projectsDict ): if len(projectsDict.keys() ) == 0: return post_infos = [] post_infos.append( { "is_short": False, "text": { "tag": "lark_md", "content": "" } }, ) for project in projectsDict.keys(): post_infos.append( { "is_short": True, "text": { "tag": "lark_md", "content": "Project Name={} \n Project ID = {}". format( projectsDict[project], project ) } }, ) headers = { 'Content-Type': 'application/json' } payload_message = { "timestamp": str(int(time.time())), "msg_type": "interactive", "card": { "i18n_elements": { "en_us": [ { "tag": "div", "text": { "tag": "lark_md", "content": "**{} Deleting Projects**".format(env) }, "fields": post_infos, }, ] } } } response = requests.request( "POST", webhook, headers=headers, data=json.dumps(payload_message)) print(response.text) def clean_projects(env): print("process env {}".format( env ) ) theProjects, tenantProjects = projects.fetch_useless_projects(env) theBackups = backups.fetch_backups( env ) theNetworks = networks.fetch_networks( env ) cleaned_projects = {} if '1369847559691367492' in theProjects: print("find it") for projectId in theProjects.keys(): email = projects.find_project_user_emails(env, projectId) token = tokens.fetchDBaaSToken(env, email) if email is None: continue # print( theNetworks, projectId) # print( stagingClusters[projectId] ) if projectId not in set(theNetworks): # print( projectId ) continue if projectId in theBackups: for cluster in theBackups[projectId]: for backup in theBackups[projectId][cluster]: backups.delete_backups( token, env, tenantProjects[ projectId ], projectId, cluster, backup ) vpcpeering.delete_vpcpeering( token, env, tenantProjects[ projectId ], projectId ) print("delete project {}, projectName {}".format( projectId, theProjects[ projectId ] )) cleaned_projects[projectId] = theProjects[ projectId ] projects.delete_projects( token, env, tenantProjects[ projectId ], projectId ) return cleaned_projects nightlyProjects = clean_projects("nightly") stringProjects = clean_projects("staging") post_to_feishu("nightly", nightlyProjects) post_to_feishu("staging", stringProjects)