1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #1699: Correct nested representation in the API of primary IPs for virtual machines and add missing primary_ip property

This commit is contained in:
Jeremy Stretch
2017-11-09 09:33:40 -05:00
parent 9d50b78b69
commit a1b1e261de
2 changed files with 27 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import unicode_literals
from django.conf import settings
from django.contrib.contenttypes.fields import GenericRelation
from django.core.exceptions import ValidationError
from django.db import models
@@ -255,3 +256,14 @@ class VirtualMachine(CreatedUpdatedModel, CustomFieldModel):
def get_status_class(self):
return VM_STATUS_CLASSES[self.status]
@property
def primary_ip(self):
if settings.PREFER_IPV4 and self.primary_ip4:
return self.primary_ip4
elif self.primary_ip6:
return self.primary_ip6
elif self.primary_ip4:
return self.primary_ip4
else:
return None