def is_active_north(): try: account_data = Account.objects.all() for account in account_data: ecs_active_n = EcsApi(account.tokencn_north_1,'cn-north-1',account.pidcn_north_1).get_active_ecs() #add ecs_is_active Ecs.objects.filter(account_name=account.account_name,region='cn-north-1').update(ecs_is_active=0) for v in ecs_active_n.values(): Ecs.objects.filter(ecs_id=v).update(ecs_is_active=1) except Exception as e: log.logging.error(e)
def sync_ecs_east(): try: account_data = Account.objects.all() for account in account_data: ecs_all_e = EcsApi(account.tokencn_east_2,'cn-east-2',account.pidcn_east_2).get_ecs() #add ecs,update ecs_name for k,v in ecs_all_e.items(): Ecs.objects.get_or_create(ecs_id=v,region='cn-east-2',account_name=account.account_name,account_id=account.id) Ecs.objects.filter(ecs_id=v).update(ecs_name=k) #delete mysql_ecs ecs_id_all_e = set(ecs_all_e.values()) ecs_id_all_mysql_e = set(list(map(lambda x: x.ecs_id,Ecs.objects.filter(account_name=account.account_name,region='cn-east-2')))) delete_ecs_mysql_e = list(ecs_id_all_mysql_e - ecs_id_all_e) for i in delete_ecs_mysql_e: Ecs.objects.filter(ecs_id=i).delete() except Exception as e: log.logging.error(e)