mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
Keep from unneccessary DB row additions in changing group memberships during inventory import.
This commit is contained in:
@@ -471,10 +471,24 @@ class Command(BaseCommand):
|
|||||||
# FIXME: only clear the ones that should not exist
|
# FIXME: only clear the ones that should not exist
|
||||||
if overwrite:
|
if overwrite:
|
||||||
LOGGER.info("clearing any child relationships to rebuild from remote source")
|
LOGGER.info("clearing any child relationships to rebuild from remote source")
|
||||||
groups = Group.objects.all()
|
db_groups = Group.objects.all()
|
||||||
for g in groups:
|
#for g in db_groups:
|
||||||
g.children.clear()
|
# g.children.clear()
|
||||||
g.save()
|
# g.save()
|
||||||
|
|
||||||
|
for db_group in db_groups:
|
||||||
|
db_kids = db_group.children.all()
|
||||||
|
mem_kids = group_names[db_group.name].child_groups
|
||||||
|
mem_kid_names = [ k.name for k in mem_kids ]
|
||||||
|
removed = False
|
||||||
|
for db_kid in db_kids:
|
||||||
|
if db_kid.name not in mem_kid_names:
|
||||||
|
removed = True
|
||||||
|
print "DEBUG: removing non-DB kid: %s" % (db_kid.name)
|
||||||
|
db_group.children.remove(db_kid)
|
||||||
|
if removed:
|
||||||
|
db_group.save()
|
||||||
|
|
||||||
|
|
||||||
# this will be slightly inaccurate, but attribute to first superuser.
|
# this will be slightly inaccurate, but attribute to first superuser.
|
||||||
user = User.objects.filter(is_superuser=True)[0]
|
user = User.objects.filter(is_superuser=True)[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user