github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

lak / puppet

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 90
    • 27
  • Source
  • Commits
  • Network (27)
  • Issues (0)
  • Downloads (62)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (41)
    • 0.23.x
    • 0.24.x
    • 0.25.x
    • feature/0.24.x/json
    • feature/event_manager/resource_harness
    • feature/event_manager/rollback
    • feature/master/1481-tmp
    • feature/master/event_manager
    • feature/master/internal_dsl
    • feature/master/push_tarball
    • feature/master/single_executable
    • features/master/hash2resources
    • master ✓
    • merge
    • refactor/0.24.8/asynchronous_storeconfigs
    • refactor/0.24.8/storeconfigs_performance
    • refactor/master/graph_shadowing
    • refactor/master/no_relationship_graph
    • test_fixes
    • tickets/0.24.x/1708
    • tickets/0.24.x/1757
    • tickets/0.24.x/707
    • tickets/0.25.x/2617
    • tickets/0.25.x/2656
    • tickets/0.25.x/2689
    • tickets/0.25.x/2914
    • tickets/master/1054
    • tickets/master/1757
    • tickets/master/1943
    • tickets/master/2135
    • tickets/master/2150
    • tickets/master/2471
    • tickets/master/2479
    • tickets/master/2632
    • tickets/master/2726
    • tickets/master/2759
    • tickets/master/2892
    • tickets/master/2954
    • tickets/master/3015
    • tickets/master/rollup2
    • tmp/0.24.x/test_failures
  • Tags (62)
    • release-0.9.2
    • BetaOne
    • Beta1
    • 0.24.8rc1
    • 0.24.8
    • 0.24.7rc1
    • 0.24.7
    • 0.24.6
    • 0.24.5
    • 0.24.4
    • 0.24.3
    • 0.24.2
    • 0.24.1
    • 0.24.0
    • 0.23.2
    • 0.23.1
    • 0.23.0
    • 0.22.4
    • 0.22.3
    • 0.22.2
    • 0.22.1
    • 0.22.0
    • 0.20.1
    • 0.20.0
    • 0.19.3
    • 0.19.2
    • 0.19.1
    • 0.19.0
    • 0.18.4
    • 0.18.3
    • 0.18.2
    • 0.18.1
    • 0.18.0
    • 0.17.2
    • 0.17.1
    • 0.17.0
    • 0.16.5
    • 0.16.4
    • 0.16.3
    • 0.16.2
    • 0.16.1
    • 0.16.0
    • 0.15.3
    • 0.15.2
    • 0.15.1
    • 0.15.0
    • 0.14.1
    • 0.14.0
    • 0.13.6
    • 0.13.5
    • 0.13.4
    • 0.13.2
    • 0.13.1
    • 0.13.0
    • 0.12.0
    • 0.11.2
    • 0.11.1
    • 0.11.0
    • 0.10.2
    • 0.10.1
    • 0.10.0
    • 0.9.3
Sending Request…
Click here to lend your support to: puppet and make a donation at www.pledgie.com ! Edit Pledgie Setup

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Server automation framework and application — Read more

  cancel

http://reductivelabs.com/trac/puppet/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Merge branch '0.25.x' 
James Turnbull (author)
Tue Jan 12 13:07:30 -0800 2010
commit  b6f90dfcd96123c245b6f5fd93753790006387c0
tree    1668fd8ed480dc0d0cb49c4a3d7f8a13c77dbeb9
parent  e26e8319186c57a41ea7ca58b0e8e853e9b452e3 parent  f7e14356ad7781fafa52a459d3c24372fa6c0900
puppet / lib / puppet / dsl.rb lib/puppet/dsl.rb
100644 276 lines (240 sloc) 6.884 kb
edit raw blame history
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# Just quick mess-around to see what a DSL would look like.
#
# This is what the executable could look like:
##!/usr/bin/env ruby
#
#require 'puppet'
#require 'puppet/dsl'
#
#Puppet::DSL.import(ARGV[0])
#
#bucket = Puppet::TransBucket.new
#bucket.type = "top"
#bucket.keyword = "class"
#
#Puppet::DSL.find_all do |name, sub|
# sub.included
#end.each do |name, sub|
# bucket.push sub.export
#end
#
#puts bucket.to_manifest
#
# And here's what an example config could look like:
#
 
##!/usr/bin/env ruby
#
#
# require 'puppet'
# require 'puppet/dsl'
#
# include Puppet::DSL
# init()
#
# aspect :webserver do
# file "/tmp/testone", :content => "yaytest"
#
# exec "testing", :command => "/bin/echo this is a test"
# end
#
# aspect :other, :inherits => :webserver do
# file "/tmp/testone", :mode => "755"
# end
#
# acquire :other
#
# apply
 
require 'puppet'
 
# Provide the actual commands for acting like a language.
module Puppet::DSL
    def aspect(name, options = {}, &block)
        Puppet::DSL::Aspect.new(name, options, &block)
    end
 
    def acquire(*names)
        names.each do |name|
            if aspect = Puppet::DSL::Aspect[name]
                unless aspect.evaluated?
                    aspect.evaluate
                end
            else
                raise "Could not find aspect %s" % name
            end
        end
    end
 
    def apply
        bucket = export()
        catalog = bucket.to_catalog
        catalog.apply
    end
 
    def export
        objects = Puppet::DSL::Aspect.collect do |name, aspect|
            if aspect.evaluated?
                aspect.export
            end
        end.reject { |a| a.nil? }.flatten.collect do |obj|
            obj.to_trans
        end
        bucket = Puppet::TransBucket.new(objects)
        bucket.name = "top"
        bucket.type = "class"
 
        return bucket
    end
 
    def init
        unless Process.uid == 0
            Puppet[:confdir] = File.expand_path("~/.puppet")
            Puppet[:vardir] = File.expand_path("~/.puppet/var")
        end
        Puppet[:user] = Process.uid
        Puppet[:group] = Process.gid
        Puppet::Util::Log.newdestination(:console)
        Puppet::Util::Log.level = :info
    end
 
    class Aspect
        Resource = Puppet::Parser::Resource
 
        include Puppet::Util
        include Puppet::DSL
        extend Puppet::Util
        extend Enumerable
        attr_accessor :parent, :name, :evaluated
 
        @aspects = {}
 
        @@objects = Hash.new do |hash, key|
            hash[key] = {}
        end
 
        # Create an instance method for every type
        Puppet::Type.loadall
        Puppet::Type.eachtype do |type|
            define_method(type.name) do |*args|
                newresource(type, *args)
            end
        end
 
        def self.[]=(name, aspect)
            name = symbolize(name)
            @aspects[name] = aspect
        end
 
        def self.[](name)
            name = symbolize(name)
 
            # Make sure there's always a main. This can get deleted in testing.
            if name == :main and ! @aspects[name]
                new(:main) {}
            end
            @aspects[name]
        end
 
        def self.clear
            @aspects.clear
            @@objects.clear
        end
 
        def self.delete(name)
            name = symbolize(name)
            if @aspects.has_key?(name)
                @aspects.delete(name)
            end
        end
 
        def self.each
            @aspects.each do |name, a|
                yield name, a
            end
        end
 
        def child_of?(aspect)
            unless aspect.is_a?(self.class)
                obj = self.class[aspect]
                unless obj
                    raise "Could not find aspect %s" % aspect
                end
                aspect = obj
            end
            if self.parent
                if self.parent == aspect
                    return true
                elsif self.parent.child_of?(aspect)
                    return true
                else
                    return false
                end
            else
                return false
            end
        end
 
        def evaluate
            if self.parent and ! self.parent.evaluated?
                self.parent.evaluate
            end
 
            unless evaluated?
                if defined? @block
                    instance_eval(&@block)
                end
                @evaluated = true
            end
        end
 
        def evaluated?
            if self.evaluated
                true
            else
                false
            end
        end
 
        def export
            @resources.dup
        end
 
        def initialize(name, options = {}, &block)
            name = symbolize(name)
            @name = name
            if block
                @block = block
            end
            if pname = options[:inherits]
                if pname.is_a?(self.class)
                    @parent = pname
                elsif parent = self.class[pname]
                    @parent = parent
                else
                    raise "Could not find parent aspect %s" % pname
                end
            end
 
            @resources = []
 
            self.class[name] = self
        end
 
        def newresource(type, name, params = {})
            if self.is_a?(Puppet::DSL::Aspect)
                source = self
            else
                source = Puppet::DSL::Aspect[:main]
            end
            unless obj = @@objects[type][name]
                obj = Resource.new :title => name, :type => type.name,
                    :source => source, :scope => scope
                @@objects[type][name] = obj
 
                @resources << obj
            end
 
            params.each do |name, value|
                param = Resource::Param.new(
                    :name => name,
                    :value => value,
                    :source => source
                )
 
                obj.send(:set_parameter, param)
            end
 
            obj
        end
 
        def scope
            unless defined?(@scope)
                # Set the code to something innocuous; we just need the
                # scopes, not the interpreter. Hackish, but true.
                Puppet[:code] = " "
                @interp = Puppet::Parser::Interpreter.new
                require 'puppet/node'
                @node = Puppet::Node.new(Facter.value(:hostname))
                if env = Puppet[:environment] and env == ""
                    env = nil
                end
                @node.parameters = Facter.to_hash
                @compile = Puppet::Parser::Compiler.new(@node, @interp.send(:parser, env))
                @scope = @compile.topscope
            end
            @scope
        end
 
        def type
            self.name
        end
    end
end
 
@aspects = {}
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server