1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 23:55:24 +00:00

fix uuid and name changes and update them on db correctly. (#404)

This commit is contained in:
catborise 2020-12-31 11:30:33 +03:00 committed by GitHub
parent 0a8beacf29
commit 596d55d481
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -4,8 +4,10 @@ from instances.models import Instance
def refresh_instance_database(compute): def refresh_instance_database(compute):
domains = compute.proxy.wvm.listAllDomains() domains = compute.proxy.wvm.listAllDomains()
domain_names = [d.name() for d in domains] domain_names = [d.name() for d in domains]
domain_uuids = [d.UUIDString() for d in domains]
# Delete instances that're not on host from DB # Delete instances that're not on host from DB
Instance.objects.filter(compute=compute).exclude(name__in=domain_names).delete() Instance.objects.filter(compute=compute).exclude(name__in=domain_names).delete()
Instance.objects.filter(compute=compute).exclude(uuid__in=domain_uuids).delete()
# Create instances that're on host but not in DB # Create instances that're on host but not in DB
names = Instance.objects.filter(compute=compute).values_list('name', flat=True) names = Instance.objects.filter(compute=compute).values_list('name', flat=True)
for domain in domains: for domain in domains:

View file

@ -169,17 +169,15 @@ def refr(compute):
if compute.status is True: if compute.status is True:
domains = compute.proxy.wvm.listAllDomains() domains = compute.proxy.wvm.listAllDomains()
domain_names = [d.name() for d in domains] domain_names = [d.name() for d in domains]
domain_uuids = [d.UUIDString() for d in domains]
# Delete instances that're not on host # Delete instances that're not on host
Instance.objects.filter(compute=compute).exclude(name__in=domain_names).delete() Instance.objects.filter(compute=compute).exclude(name__in=domain_names).delete()
Instance.objects.filter(compute=compute).exclude(uuid__in=domain_uuids).delete()
# Create instances that're not in DB # Create instances that're not in DB
names = Instance.objects.filter(compute=compute).values_list('name', flat=True) names = Instance.objects.filter(compute=compute).values_list('name', flat=True)
uuids = Instance.objects.filter(compute=compute).values_list('uuid', flat=True)
for domain in domains: for domain in domains:
if domain.name() not in names: if domain.name() not in names:
Instance(compute=compute, name=domain.name(), uuid=domain.UUIDString()).save() Instance(compute=compute, name=domain.name(), uuid=domain.UUIDString()).save()
continue
if domain.UUIDString() not in uuids:
Instance(compute=compute, name=domain.name(), uuid=domain.UUIDString()).save()
def get_dhcp_mac_address(vname): def get_dhcp_mac_address(vname):