~rvb/maas/bug-1070765-hostname2

« back to all changes in this revision

Viewing changes to src/maasserver/models/node.py

  • Committer: Tarmac
  • Author(s): Raphael Badin
  • Date: 2012-10-30 10:44:28 UTC
  • mfrom: (1296.2.7 add-fqdn)
  • Revision ID: tarmac-20121030104428-7gi7qyqwet7mc5b2
[r=jtv][bug=][author=rvb] Add a fqdn property on nodes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
from maasserver.models.dhcplease import DHCPLease
64
64
from maasserver.models.tag import Tag
65
65
from maasserver.models.timestampedmodel import TimestampedModel
66
 
from maasserver.utils import get_db_state
 
66
from maasserver.utils import (
 
67
    get_db_state,
 
68
    strip_domain,
 
69
    )
67
70
from maasserver.utils.orm import get_first
68
71
from piston.models import Token
69
72
from provisioningserver.enum import (
491
494
        else:
492
495
            return self.system_id
493
496
 
 
497
    @property
 
498
    def fqdn(self):
 
499
        """Fully qualified domain name for this node.
 
500
 
 
501
        If MAAS manages DNS for this node, the domain part of the
 
502
        hostname (if present), is replaced by the domain configured
 
503
        on the cluster controller.
 
504
        If not, simply return the node's hostname.
 
505
        """
 
506
        # Avoid circular imports.
 
507
        from maasserver.dns import is_dns_managed
 
508
        if is_dns_managed(self.nodegroup):
 
509
            # If the hostname field contains a domain, strip it.
 
510
            hostname = strip_domain(self.hostname)
 
511
            # Build the FQDN by using the hostname and nodegroup.name
 
512
            # as the domain name.
 
513
            return '%s.%s' % (hostname, self.nodegroup.name)
 
514
        else:
 
515
            return self.hostname
 
516
 
494
517
    def tag_names(self):
495
518
        # We don't use self.tags.values_list here because this does not
496
519
        # take advantage of the cache.