summaryrefslogtreecommitdiffstats
path: root/lib/puppet.rb
blob: 09ae531aa7606f3d359afc53b43278fd6670b594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Try to load rubygems.  Hey rubygems, I hate you.
begin
    require 'rubygems'
rescue LoadError
end

# see the bottom of the file for further inclusions
require 'singleton'
require 'facter'
require 'puppet/error'
require 'puppet/util'
require 'puppet/util/autoload'
require 'puppet/util/settings'
require 'puppet/util/feature'
require 'puppet/util/suidmanager'

#------------------------------------------------------------
# the top-level module
#
# all this really does is dictate how the whole system behaves, through
# preferences for things like debugging
#
# it's also a place to find top-level commands like 'debug'

module Puppet
    PUPPETVERSION = '0.25.4'

    def Puppet.version
        return PUPPETVERSION
    end

    class << self
        include Puppet::Util
        attr_reader :features
        attr_writer :name
    end

    # the hash that determines how our system behaves
    @@settings = Puppet::Util::Settings.new

    # The services running in this process.
    @services ||= []

    require 'puppet/util/logging'

    extend Puppet::Util::Logging

    # The feature collection
    @features = Puppet::Util::Feature.new('puppet/feature')

    # Load the base features.
    require 'puppet/feature/base'

    # Store a new default value.
    def self.setdefaults(section, hash)
        @@settings.setdefaults(section, hash)
    end

    # configuration parameter access and stuff
    def self.[](param)
        case param
        when :debug
            if Puppet::Util::Log.level == :debug
                return true
            else
                return false
            end
        else
            return @@settings[param]
        end
    end

    # configuration parameter access and stuff
    def self.[]=(param,value)
        @@settings[param] = value
    end

    def self.clear
        @@settings.clear
    end

    def self.debug=(value)
        if value
            Puppet::Util::Log.level=(:debug)
        else
            Puppet::Util::Log.level=(:notice)
        end
    end

    def self.settings
        @@settings
    end

    # Load all of the configuration parameters.
    require 'puppet/defaults'

    def self.genmanifest
        if Puppet[:genmanifest]
            puts Puppet.settings.to_manifest
            exit(0)
        end
    end

    # Parse the config file for this process.
    def self.parse_config
        Puppet.settings.parse
    end

    # XXX this should all be done using puppet objects, not using
    # normal mkdir
    def self.recmkdir(dir,mode = 0755)
        if FileTest.exist?(dir)
            return false
        else
            tmp = dir.sub(/^\//,'')
            path = [File::SEPARATOR]
            tmp.split(File::SEPARATOR).each { |dir|
                path.push dir
                if ! FileTest.exist?(File.join(path))
                    begin
                        Dir.mkdir(File.join(path), mode)
                    rescue Errno::EACCES => detail
                        Puppet.err detail.to_s
                        return false
                    rescue => detail
                        Puppet.err "Could not create %s: %s" % [path, detail.to_s]
                        return false
                    end
                elsif FileTest.directory?(File.join(path))
                    next
                else FileTest.exist?(File.join(path))
                    raise Puppet::Error, "Cannot create %s: basedir %s is a file" %
                        [dir, File.join(path)]
                end
            }
            return true
        end
    end

    # Create a new type.  Just proxy to the Type class.
    def self.newtype(name, options = {}, &block)
        Puppet::Type.newtype(name, options, &block)
    end

    # Retrieve a type by name.  Just proxy to the Type class.
    def self.type(name)
        # LAK:DEP Deprecation notice added 12/17/2008
        Puppet.warning "Puppet.type is deprecated; use Puppet::Type.type"
        Puppet::Type.type(name)
    end
end

require 'puppet/type'
require 'puppet/parser'
require 'puppet/resource'
require 'puppet/network'
require 'puppet/ssl'
require 'puppet/module'
require 'puppet/util/storage'
require 'puppet/status'
require 'puppet/file_bucket/file'

if Puppet[:storeconfigs]
    require 'puppet/rails'
end