summaryrefslogtreecommitdiffstats
path: root/tools/scripts/ig-hotfix/test.py
blob: c4791314e64d42605b6f857a119bdbfdff3efbc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from django.db import connection
from awx.main.models import InstanceGroup

InstanceGroup.objects.filter(name__in=('green', 'yellow', 'red')).delete()

green = InstanceGroup.objects.create(name='green')
red = InstanceGroup.objects.create(name='red')
yellow = InstanceGroup.objects.create(name='yellow')

for ig in InstanceGroup.objects.all():
    print((ig.id, ig.name, ig.use_role_id))

with connection.cursor() as cursor:
    cursor.execute("UPDATE main_instancegroup SET use_role_id = NULL WHERE name = 'red'")
    cursor.execute(f"UPDATE main_instancegroup SET use_role_id = {green.use_role_id} WHERE name = 'yellow'")

print("=====================================")
for ig in InstanceGroup.objects.all():
    print((ig.id, ig.name, ig.use_role_id))