~ubuntu-branches/ubuntu/lucid/puppet/lucid-security

« back to all changes in this revision

Viewing changes to lib/puppet/node.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        end
38
38
        @name = name
39
39
 
40
 
        # Provide a default value.
41
 
        if names = options[:names]
42
 
            if names.is_a?(String)
43
 
                @names = [names]
44
 
            else
45
 
                @names = names
46
 
            end
47
 
        else
48
 
            @names = [name]
49
 
        end
50
 
 
51
40
        if classes = options[:classes]
52
41
            if classes.is_a?(String)
53
42
                @classes = [classes]
67
56
 
68
57
    # Merge the node facts with parameters from the node source.
69
58
    def fact_merge
70
 
        if facts = Puppet::Node::Facts.find(name)
71
 
            merge(facts.values)
72
 
        else
73
 
            Puppet.warning "Could not find facts for %s; you probably have a discrepancy between the node and fact names" % name
 
59
        begin
 
60
            if facts = Puppet::Node::Facts.find(name)
 
61
                merge(facts.values)
 
62
            end
 
63
        rescue => detail
 
64
            error = Puppet::Error.new("Could not retrieve facts for %s: %s" % [name, detail])
 
65
            error.set_backtrace(detail.backtrace)
 
66
            raise error
74
67
        end
75
68
    end
76
69
 
79
72
        params.each do |name, value|
80
73
            @parameters[name] = value unless @parameters.include?(name)
81
74
        end
 
75
 
 
76
        @parameters["environment"] ||= self.environment if self.environment
82
77
    end
83
78
 
84
79
    # Calculate the list of names we might use for looking
85
80
    # up our node.  This is only used for AST nodes.
86
81
    def names
 
82
        if Puppet.settings[:strict_hostname_checking]
 
83
            return [name]
 
84
        end
 
85
 
87
86
        names = []
88
87
 
 
88
        if name.include?(".")
 
89
            names += split_name(name)
 
90
        end
 
91
 
89
92
        # First, get the fqdn
90
93
        unless fqdn = parameters["fqdn"]
91
94
            if parameters["hostname"] and parameters["domain"]
98
101
        # Now that we (might) have the fqdn, add each piece to the name
99
102
        # list to search, in order of longest to shortest.
100
103
        if fqdn
101
 
            list = fqdn.split(".")
102
 
            tmp = []
103
 
            list.each_with_index do |short, i|
104
 
                tmp << list[0..i].join(".")
105
 
            end
106
 
            names += tmp.reverse
 
104
            names += split_name(fqdn)
107
105
        end
108
106
 
109
107
        # And make sure the node name is first, since that's the most
117
115
        end
118
116
        names.uniq
119
117
    end
 
118
 
 
119
    def split_name(name)
 
120
        list = name.split(".")
 
121
        tmp = []
 
122
        list.each_with_index do |short, i|
 
123
            tmp << list[0..i].join(".")
 
124
        end
 
125
        tmp.reverse
 
126
    end
120
127
end