2020-07-13 09:33:09 +00:00
|
|
|
from instances.models import Instance
|
|
|
|
|
|
|
|
|
|
|
|
def refresh_instance_database(compute):
|
|
|
|
domains = compute.proxy.wvm.listAllDomains()
|
|
|
|
domain_names = [d.name() for d in domains]
|
2020-12-31 08:30:33 +00:00
|
|
|
domain_uuids = [d.UUIDString() for d in domains]
|
2020-07-13 09:33:09 +00:00
|
|
|
# Delete instances that're not on host from DB
|
|
|
|
Instance.objects.filter(compute=compute).exclude(name__in=domain_names).delete()
|
2020-12-31 08:30:33 +00:00
|
|
|
Instance.objects.filter(compute=compute).exclude(uuid__in=domain_uuids).delete()
|
2020-07-13 09:33:09 +00:00
|
|
|
# Create instances that're on host but not in DB
|
2022-11-02 05:54:35 +00:00
|
|
|
names = Instance.objects.filter(compute=compute).values_list("name", flat=True)
|
2020-07-13 09:33:09 +00:00
|
|
|
for domain in domains:
|
|
|
|
if domain.name() not in names:
|
2022-11-02 13:05:41 +00:00
|
|
|
Instance(
|
|
|
|
compute=compute, name=domain.name(), uuid=domain.UUIDString()
|
|
|
|
).save()
|