Skip to content

Commit

Permalink
Fix DNS TXT records for virtual server (#2675)
Browse files Browse the repository at this point in the history
Call parent.last_descendant instead of parent to get proper instance type.
  • Loading branch information
mkurek authored and ar4s committed Aug 4, 2016
1 parent 1916009 commit 7a1373f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/ralph/dns/tests.py
Expand Up @@ -13,6 +13,7 @@
DNSaaSIntegrationNotEnabledError,
DNSView
)
from ralph.virtual.models import VirtualServer
from ralph.virtual.tests.factories import VirtualServerFactory


Expand Down Expand Up @@ -137,6 +138,11 @@ def setUp(self):
slot_no='1',
),
)
# refresh virtual server to get parent as BaseObject, not
# DataCenterAsset
self.virtual_server = VirtualServer.objects.get(
pk=self.virtual_server.id
)

cluster = ClusterFactory(
hostname='',
Expand Down
22 changes: 14 additions & 8 deletions src/ralph/virtual/models.py
Expand Up @@ -264,18 +264,24 @@ class VirtualServer(
# TODO: remove this field
cluster = models.ForeignKey(Cluster, blank=True, null=True)

@cached_property
def polymorphic_parent(self):
return self.parent.last_descendant if self.parent_id else None

def get_location(self):
if self.parent:
location = self.parent.get_location()
if self.parent.hostname:
location.append(self.parent.hostname)
if self.polymorphic_parent:
location = self.polymorphic_parent.get_location()
if self.polymorphic_parent.hostname:
location.append(self.polymorphic_parent.hostname)
else:
location = None
return location

@property
def model(self):
return self.parent.model if self.parent else None
return (
self.polymorphic_parent.model if self.polymorphic_parent else None
)

@cached_property
def rack_id(self):
Expand All @@ -284,9 +290,9 @@ def rack_id(self):
@cached_property
def rack(self):
if self.parent_id:
parent = self.parent.last_descendant
if isinstance(parent, DataCenterAsset):
return parent.rack
polymorphic_parent = self.polymorphic_parent.last_descendant
if isinstance(polymorphic_parent, DataCenterAsset):
return polymorphic_parent.rack
return None

class Meta:
Expand Down

0 comments on commit 7a1373f

Please sign in to comment.