1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Smarter removal of host/group associations means running the inventory script won't pad database

rows when not needed.  Similar to last change made for groups.
This commit is contained in:
Michael DeHaan 2013-07-15 17:54:36 -04:00
parent bea844ff51
commit 82a9572df8

View File

@ -521,9 +521,23 @@ class Command(BaseCommand):
if overwrite: if overwrite:
LOGGER.info("purging host group memberships") LOGGER.info("purging host group memberships")
db_groups = Group.objects.filter(inventory=inventory) db_groups = Group.objects.filter(inventory=inventory)
for g in db_groups: #for g in db_groups:
g.hosts.clear() # g.hosts.clear()
g.save() # g.save()
for db_group in db_groups:
db_hosts = db_group.hosts.all()
mem_hosts = group_names[db_group.name].hosts
mem_host_names = [ h.name for h in mem_hosts ]
removed = False
for db_host in db_hosts:
if db_host.name not in mem_host_names:
removed = True
print "DEBUG: removing non-DB host: %s" % (db_host.name)
db_group.hosts.remove(db_host)
if removed:
db_group.save()
# for each host in a mem group, add it to the parents to which it belongs # for each host in a mem group, add it to the parents to which it belongs
# FIXME: where it does not already exist # FIXME: where it does not already exist