~lutostag/ubuntu/trusty/maas/1.5.4+keystone

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-03-04 11:49:44 UTC
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20130304114944-azcvu9anlf8mizpa
Tags: upstream-1.3+bzr1452+dfsg
ImportĀ upstreamĀ versionĀ 1.3+bzr1452+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    repeat,
25
25
    )
26
26
import math
27
 
import os
28
27
import random
29
28
from string import whitespace
30
29
from uuid import uuid1
31
30
 
32
 
from django.conf import settings
33
31
from django.contrib.auth.models import User
34
32
from django.core.exceptions import (
35
33
    PermissionDenied,
73
71
    get_db_state,
74
72
    strip_domain,
75
73
    )
76
 
from maasserver.utils.orm import get_first
 
74
from maasserver.utils.orm import (
 
75
    get_first,
 
76
    get_one,
 
77
    )
77
78
from piston.models import Token
78
79
from provisioningserver.enum import (
79
80
    POWER_TYPE,
631
632
    def start_commissioning(self, user):
632
633
        """Install OS and self-test a new node."""
633
634
        # Avoid circular imports.
 
635
        from metadataserver.commissioning.user_data import generate_user_data
634
636
        from metadataserver.models import NodeCommissionResult
635
637
 
636
 
        path = settings.COMMISSIONING_SCRIPT
637
 
        if not os.path.exists(path):
638
 
            raise ValidationError(
639
 
                "Commissioning script is missing: %s" % path)
640
 
        with open(path, 'r') as f:
641
 
            commissioning_user_data = f.read()
642
 
 
 
638
        commissioning_user_data = generate_user_data(nodegroup=self.nodegroup)
643
639
        NodeCommissionResult.objects.clear_results(self)
644
640
        self.status = NODE_STATUS.COMMISSIONING
645
641
        self.owner = user
722
718
        else:
723
719
            return None
724
720
 
 
721
    def get_effective_kernel_options(self):
 
722
        """Determine any special kernel parameters for this node.
 
723
 
 
724
        :return: (tag, kernel_options)
 
725
            tag is a Tag object or None. If None, the kernel_options came from
 
726
            the global setting.
 
727
            kernel_options, a string indicating extra kernel_options that
 
728
            should be used when booting this node. May be None if no tags match
 
729
            and no global setting has been configured.
 
730
        """
 
731
        # First, see if there are any tags associated with this node that has a
 
732
        # custom kernel parameter
 
733
        tags = self.tags.filter(kernel_opts__isnull=False)
 
734
        tags = tags.order_by('name')[:1]
 
735
        tag = get_one(tags)
 
736
        if tag is not None:
 
737
            return tag, tag.kernel_opts
 
738
        global_value = Config.objects.get_config('kernel_opts')
 
739
        return None, global_value
 
740
 
725
741
    @property
726
742
    def work_queue(self):
727
743
        """The name of the queue for tasks specific to this node."""
796
812
    def set_hardware_details(self, xmlbytes):
797
813
        """Set the `lshw -xml` output"""
798
814
        update_hardware_details(self, xmlbytes, Tag.objects)
 
815
 
 
816
    def should_use_traditional_installer(self):
 
817
        """Should this node be installed with the traditional installer?
 
818
 
 
819
        By default, nodes should be installed with the default installer, so
 
820
        this returns `False`.
 
821
        """
 
822
        return self.tags.filter(name="use-traditional-installer").exists()
 
823
 
 
824
    def should_use_default_installer(self):
 
825
        """Should this node be installed with the default installer?
 
826
 
 
827
        By default, nodes should be installed with the default installer, the
 
828
        Fast Path installer, so this returns `True`.
 
829
        """
 
830
        return not self.should_use_traditional_installer()
 
831
 
 
832
    def use_traditional_installer(self):
 
833
        """Set this node to be installed with the traditional installer.
 
834
 
 
835
        By default, nodes should be installed with the Fast Path installer.
 
836
 
 
837
        :raises: :class:`RuntimeError` when the `use-traditional-installer`
 
838
            tag is defined *with* an expression. The reason is that the tag
 
839
            evaluation machinery will eventually ignore whatever changes you
 
840
            make with this method.
 
841
        """
 
842
        uti_tag, _ = Tag.objects.get_or_create(
 
843
            name="use-traditional-installer")
 
844
        if uti_tag.definition != "":
 
845
            raise RuntimeError(
 
846
                "The use-traditional-installer tag is defined with an "
 
847
                "expression. This expression much be updated to make this "
 
848
                "node boot with the traditional installer.")
 
849
        self.tags.add(uti_tag)
 
850
 
 
851
    def use_default_installer(self):
 
852
        """Set this node to be installed with the default installer.
 
853
 
 
854
        By default, nodes should be installed with the Fast Path installer.
 
855
 
 
856
        :raises: :class:`RuntimeError` when the `use-traditional-installer`
 
857
            tag is defined *with* an expression. The reason is that the tag
 
858
            evaluation machinery will eventually ignore whatever changes you
 
859
            make with this method.
 
860
        """
 
861
        uti_tag, _ = Tag.objects.get_or_create(
 
862
            name="use-traditional-installer")
 
863
        if uti_tag.definition != "":
 
864
            raise RuntimeError(
 
865
                "The use-traditional-installer tag is defined with an "
 
866
                "expression. This expression much be updated to prevent "
 
867
                "this node from booting with the traditional installer.")
 
868
        self.tags.remove(uti_tag)