puppet 3.1.0.rc1 → 3.1.0.rc2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (127) hide show
  1. data/COMMITTERS.md +185 -0
  2. data/ext/debian/changelog.erb +6 -0
  3. data/ext/debian/puppet-common.manpages +1 -0
  4. data/ext/debian/puppet.default +3 -1
  5. data/ext/debian/puppetmaster.default +6 -3
  6. data/ext/redhat/puppet.spec.erb +16 -5
  7. data/lib/puppet.rb +3 -5
  8. data/lib/puppet/defaults.rb +6 -5
  9. data/lib/puppet/dsl.rb +3 -7
  10. data/lib/puppet/dsl/resource_api.rb +120 -0
  11. data/lib/puppet/dsl/resource_type_api.rb +34 -0
  12. data/lib/puppet/module_tool.rb +23 -11
  13. data/lib/puppet/network/formats.rb +1 -1
  14. data/lib/puppet/node/environment.rb +1 -3
  15. data/lib/puppet/parser/ast/definition.rb +5 -2
  16. data/lib/puppet/parser/ast/hostclass.rb +3 -2
  17. data/lib/puppet/parser/ast/node.rb +5 -2
  18. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  19. data/lib/puppet/parser/compiler.rb +0 -10
  20. data/lib/puppet/parser/lexer.rb +50 -39
  21. data/lib/puppet/parser/parser_support.rb +29 -11
  22. data/lib/puppet/parser/scope.rb +2 -2
  23. data/lib/puppet/parser/type_loader.rb +7 -31
  24. data/lib/puppet/provider/package/openbsd.rb +16 -2
  25. data/lib/puppet/provider/package/pip.rb +11 -2
  26. data/lib/puppet/provider/package/portage.rb +29 -12
  27. data/lib/puppet/provider/service/launchd.rb +19 -14
  28. data/lib/puppet/provider/service/upstart.rb +1 -1
  29. data/lib/puppet/provider/user/hpux.rb +37 -2
  30. data/lib/puppet/resource.rb +25 -38
  31. data/lib/puppet/resource/type.rb +6 -14
  32. data/lib/puppet/settings.rb +1 -1
  33. data/lib/puppet/ssl/certificate_authority.rb +4 -1
  34. data/lib/puppet/ssl/certificate_request.rb +3 -1
  35. data/lib/puppet/ssl/certificate_signer.rb +22 -0
  36. data/lib/puppet/type.rb +4 -4
  37. data/lib/puppet/util/methodhelper.rb +0 -19
  38. data/lib/puppet/util/rubygems.rb +3 -1
  39. data/lib/puppet/util/selinux.rb +1 -6
  40. data/lib/puppet/version.rb +1 -1
  41. data/man/man5/puppet.conf.5 +81 -95
  42. data/man/man8/extlookup2hiera.8 +23 -0
  43. data/man/man8/puppet-agent.8 +3 -3
  44. data/man/man8/puppet-apply.8 +2 -6
  45. data/man/man8/puppet-ca.8 +6 -7
  46. data/man/man8/puppet-catalog.8 +6 -7
  47. data/man/man8/puppet-cert.8 +4 -4
  48. data/man/man8/puppet-certificate.8 +6 -7
  49. data/man/man8/puppet-certificate_request.8 +6 -7
  50. data/man/man8/puppet-certificate_revocation_list.8 +6 -7
  51. data/man/man8/puppet-config.8 +4 -8
  52. data/man/man8/puppet-describe.8 +1 -1
  53. data/man/man8/puppet-device.8 +1 -1
  54. data/man/man8/puppet-doc.8 +3 -3
  55. data/man/man8/puppet-facts.8 +4 -8
  56. data/man/man8/puppet-file.8 +6 -7
  57. data/man/man8/puppet-filebucket.8 +1 -1
  58. data/man/man8/puppet-help.8 +2 -6
  59. data/man/man8/puppet-inspect.8 +1 -1
  60. data/man/man8/puppet-instrumentation_data.8 +3 -7
  61. data/man/man8/puppet-instrumentation_listener.8 +3 -7
  62. data/man/man8/puppet-instrumentation_probe.8 +3 -7
  63. data/man/man8/puppet-key.8 +6 -7
  64. data/man/man8/puppet-kick.8 +5 -1
  65. data/man/man8/puppet-man.8 +2 -6
  66. data/man/man8/puppet-master.8 +2 -2
  67. data/man/man8/puppet-module.8 +11 -9
  68. data/man/man8/puppet-node.8 +38 -37
  69. data/man/man8/puppet-parser.8 +2 -6
  70. data/man/man8/puppet-plugin.8 +2 -6
  71. data/man/man8/puppet-queue.8 +1 -1
  72. data/man/man8/puppet-report.8 +3 -7
  73. data/man/man8/puppet-resource.8 +1 -1
  74. data/man/man8/puppet-resource_type.8 +3 -7
  75. data/man/man8/puppet-secret_agent.8 +2 -6
  76. data/man/man8/puppet-status.8 +3 -7
  77. data/man/man8/puppet.8 +1 -1
  78. data/spec/integration/parser/ruby_manifest_spec.rb +128 -0
  79. data/spec/lib/puppet_spec/compiler.rb +0 -11
  80. data/spec/spec_helper.rb +3 -4
  81. data/spec/unit/dsl/resource_api_spec.rb +180 -0
  82. data/spec/unit/dsl/resource_type_api_spec.rb +53 -0
  83. data/spec/unit/module_tool_spec.rb +79 -46
  84. data/spec/unit/network/formats_spec.rb +4 -0
  85. data/spec/unit/node/environment_spec.rb +0 -13
  86. data/spec/unit/parser/compiler_spec.rb +0 -26
  87. data/spec/unit/parser/parser_spec.rb +14 -0
  88. data/spec/unit/parser/type_loader_spec.rb +4 -15
  89. data/spec/unit/provider/package/openbsd_spec.rb +148 -35
  90. data/spec/unit/provider/package/pip_spec.rb +49 -25
  91. data/spec/unit/provider/package/portage_spec.rb +65 -0
  92. data/spec/unit/provider/service/launchd_spec.rb +6 -5
  93. data/spec/unit/provider/user/hpux_spec.rb +39 -11
  94. data/spec/unit/provider/user/useradd_spec.rb +14 -14
  95. data/spec/unit/resource/type_spec.rb +7 -49
  96. data/spec/unit/resource_spec.rb +0 -32
  97. data/spec/unit/ssl/certificate_request_spec.rb +18 -0
  98. data/spec/unit/util/rubygems_spec.rb +1 -1
  99. data/spec/unit/util/selinux_spec.rb +0 -2
  100. metadata +17 -50
  101. data/lib/puppet/dsl/actions.rb +0 -283
  102. data/lib/puppet/dsl/blank_slate.rb +0 -55
  103. data/lib/puppet/dsl/context.rb +0 -393
  104. data/lib/puppet/dsl/parser.rb +0 -57
  105. data/lib/puppet/dsl/resource_decorator.rb +0 -56
  106. data/lib/puppet/dsl/resource_reference.rb +0 -95
  107. data/lib/puppet/dsl/type_reference.rb +0 -102
  108. data/lib/puppet/util/manifest_filetype_helper.rb +0 -22
  109. data/spec/integration/dsl/classes_spec.rb +0 -191
  110. data/spec/integration/dsl/defaults_spec.rb +0 -38
  111. data/spec/integration/dsl/definitions_spec.rb +0 -73
  112. data/spec/integration/dsl/functions_spec.rb +0 -95
  113. data/spec/integration/dsl/nodes_spec.rb +0 -96
  114. data/spec/integration/dsl/params_spec.rb +0 -146
  115. data/spec/integration/dsl/relationships_spec.rb +0 -46
  116. data/spec/integration/dsl/resources_spec.rb +0 -202
  117. data/spec/integration/dsl/type_loading_spec.rb +0 -64
  118. data/spec/lib/matchers/catalog.rb +0 -50
  119. data/spec/lib/puppet_spec/dsl.rb +0 -29
  120. data/spec/unit/dsl/actions_spec.rb +0 -402
  121. data/spec/unit/dsl/blank_slate_spec.rb +0 -27
  122. data/spec/unit/dsl/context_spec.rb +0 -678
  123. data/spec/unit/dsl/parser_spec.rb +0 -56
  124. data/spec/unit/dsl/resource_decorator_spec.rb +0 -94
  125. data/spec/unit/dsl/resource_reference_spec.rb +0 -150
  126. data/spec/unit/dsl/type_reference_spec.rb +0 -164
  127. data/spec/unit/util/manifest_filetype_helper_spec.rb +0 -29
@@ -0,0 +1,185 @@
1
+ Committing changes to Puppet
2
+ ====
3
+
4
+ We would like to make it easier for community members to contribute to Puppet
5
+ using pull requests, even if it makes the task of reviewing and committing
6
+ these changes a little harder. Pull requests are only ever based on a single
7
+ branch, however, we maintain more than one active branch. As a result
8
+ contributors should target their changes at the master branch. This makes the
9
+ process of contributing a little easier for the contributor since they don't
10
+ need to concern themselves with the question, "What branch do I base my changes
11
+ on?" This is already called out in the [CONTRIBUTING.md](http://goo.gl/XRH2J).
12
+
13
+ Therefore, it is the responsibility of the committer to re-base the change set
14
+ on the appropriate branch which should receive the contribution.
15
+
16
+ The rest of this document addresses the concerns of the committer. This
17
+ document will help guide the committer decide which branch to base, or re-base
18
+ a contribution on top of. This document also describes our branch management
19
+ strategy, which is closely related to the decision of what branch to commit
20
+ changes into.
21
+
22
+ Terminology
23
+ ====
24
+
25
+ Many of these terms have more than one meaning. For the purposes of this
26
+ document, the following terms refer to specific things.
27
+
28
+ **contributor** - A person who makes a change to Puppet and submits a change
29
+ set in the form of a pull request.
30
+
31
+ **change set** - A set of discrete patches which combined together form a
32
+ contribution. A change set takes the form of Git commits and is submitted to
33
+ Puppet in the form of a pull request.
34
+
35
+ **committer** - A person responsible for reviewing a pull request and then
36
+ making the decision what base branch to merge the change set into.
37
+
38
+ **base branch** - A branch in Git that contains an active history of changes
39
+ and will eventually be released using semantic version guidelines. The branch
40
+ named master will always exist as a base branch. All other base branches will
41
+ be associated with a specific released version of Puppet, e.g. 2.7.x and 3.0.x.
42
+
43
+ Committer Guide
44
+ ====
45
+
46
+ This section provides a guide to follow while committing change sets to Puppet
47
+ base branches.
48
+
49
+ How to decide what release(s) should be patched
50
+ ---
51
+
52
+ This section provides a guide to help a committer decide the specific base
53
+ branch that a change set should be merged into.
54
+
55
+ The latest minor release of a major release is the only base branch that should
56
+ be patched. Older minor releases in a major release do not get patched. Before
57
+ the switch to [semantic versions](http://semver.org/) committers did not have
58
+ to think about the difference between minor and major releases. Committing to
59
+ the latest minor release of a major release is a policy intended to limit the
60
+ number of active base branches that must be managed.
61
+
62
+ Security patches are handled as a special case. Security patches may be
63
+ applied to earlier minor releases of a major release.
64
+
65
+ How to commit a change set to multiple base branches
66
+ ---
67
+
68
+ A change set may apply to multiple releases. In this situation the change set
69
+ needs to be committed to multiple base branches. This section provides a guide
70
+ for how to merge patches across releases, e.g. 2.7 is patched, how should the
71
+ changes be applied to 3.0?
72
+
73
+ First, merge the change set into the lowest numbered base branch, e.g. 2.7.
74
+ Next, merge the changed base branch up through all later base branches by using
75
+ the `--no-ff --log` git merge options. We commonly refer to this as our "merge
76
+ up process" because we merge in once, then merge up multiple times.
77
+
78
+ When a new minor release branch is created (e.g. 3.1.x) then the previous one
79
+ is deleted (e.g. 3.0.x). Any security or urgent fixes that might have to be
80
+ applied to the older code line is done by creating an ad-hoc branch from the
81
+ tag of the last patch release of the old minor line.
82
+
83
+ Code review checklist
84
+ ---
85
+
86
+ This section aims to provide a checklist of things to look for when reviewing a
87
+ pull request and determining if the change set should be merged into a base
88
+ branch:
89
+
90
+ * All tests pass
91
+ * Are there any platform gotchas? (Does a change make an assumption about
92
+ platform specific behavior that is incompatible with other platforms? e.g.
93
+ Windows paths vs. POSIX paths.)
94
+ * Is the change backwards compatible? (It should be)
95
+ * Are there YARD docs for API changes?
96
+ * Does the change set also require documentation changes? If so is the
97
+ documentation being kept up to date?
98
+ * Does the change set include clean code? (software code that is formatted
99
+ correctly and in an organized manner so that another coder can easily read
100
+ or modify it.) HINT: `git diff master --check`
101
+ * Does the change set conform to the contributing guide?
102
+
103
+
104
+ Commit citizen guidelines:
105
+ ---
106
+
107
+ This section aims to provide guidelines for being a good commit citizen by
108
+ paying attention to our automated build tools.
109
+
110
+ * Don’t push on a broken build. (A broken build is defined as a failing job
111
+ in the [Puppet FOSS](https://jenkins.puppetlabs.com/view/Puppet%20FOSS/)
112
+ page.)
113
+ * Watch the build until your changes have gone through green
114
+ * Update the ticket status and target version. The target version field in
115
+ our issue tracker should be updated to be the next release of Puppet. For
116
+ example, if the most recent release of Puppet is 3.1.1 and you merge a
117
+ backwards compatible change set into master, then the target version should
118
+ be 3.2.0 in the issue tracker.)
119
+ * Ensure the pull request is closed (Hint: amend your merge commit to contain
120
+ the string `closes: #123` where 123 is the pull request number.
121
+
122
+ Example Procedure
123
+ ====
124
+
125
+ This section helps a committer rebase a contribution onto an earlier base
126
+ branch, then merge into the base branch and up through all active base
127
+ branches.
128
+
129
+ Suppose a contributor submits a pull request based on master. The change set
130
+ fixes a bug reported against Puppet 3.1.1 which is the most recently released
131
+ version of Puppet.
132
+
133
+ In this example the committer should rebase the change set onto the 3.1.x
134
+ branch since this is a bug rather than new functionality.
135
+
136
+ First, the committer pulls down the branch using the `hub` gem. This tool
137
+ automates the process of adding the remote repository and creating a local
138
+ branch to track the remote branch.
139
+
140
+ $ hub checkout https://github.com/puppetlabs/puppet/pull/1234
141
+ Branch jeffmccune-fix_foo_error set up to track remote branch fix_foo_error from jeffmccune.
142
+ Switched to a new branch 'jeffmccune-fix_foo_error'
143
+
144
+ At this point the topic branch is a descendant of master, but we want it to
145
+ descend from 3.1.x. The committer creates a new branch then re-bases the
146
+ change set:
147
+
148
+ $ git branch bug/3.1.x/fix_foo_error
149
+ $ git rebase --onto 3.1.x master bug/3.1.x/fix_foo_error
150
+ First, rewinding head to replay your work on top of it...
151
+ Applying: (#23456) Fix FooError that always bites users in 3.1.1
152
+
153
+ The `git rebase` command may be interpreted as, "First, check out the branch
154
+ named `bug/3.1.x/fix_foo_error`, then take the changes that were previously
155
+ based on `master` and re-base them onto `3.1.x`.
156
+
157
+ Now that we have a topic branch containing the change set based on the correct
158
+ release branch, the committer merges in:
159
+
160
+ $ git checkout 3.1.x
161
+ Switched to branch '3.1.x'
162
+ $ git merge --no-ff --log bug/3.1.x/fix_foo_error
163
+ Merge made by the 'recursive' strategy.
164
+ foo | 0
165
+ 1 file changed, 0 insertions(+), 0 deletions(-)
166
+ create mode 100644 foo
167
+
168
+ Once merged into the first base branch, the committer merges up:
169
+
170
+ $ git checkout master
171
+ Switched to branch 'master'
172
+ $ git merge --no-ff --log 3.1.x
173
+ Merge made by the 'recursive' strategy.
174
+ foo | 0
175
+ 1 file changed, 0 insertions(+), 0 deletions(-)
176
+ create mode 100644 foo
177
+
178
+ Once the change set has been merged "in and up." the committer pushes. (Note,
179
+ the checklist should be complete at this point.) Note that both the 3.1.x and
180
+ master branches are being pushed at the same time.
181
+
182
+ $ git push puppetlabs master:master 3.1.x:3.1.x
183
+
184
+ That's it! The committer then updates the pull request, updates the issue in
185
+ our issue tracker, and keeps an eye on the build status.
@@ -4,6 +4,12 @@ puppet (<%= @debversion %>) hardy lucid natty oneiric unstable sid squeeze wheez
4
4
 
5
5
  -- Puppet Labs Release <info@puppetlabs.com> <%= Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")%>
6
6
 
7
+ puppet (3.1.0-0.1rc1puppetlabs1) lucid natty oneiric precise unstable sid squeeze wheezy precise; urgency=low
8
+
9
+ * Add extlookup2hiera manpage to puppet-common.manpages
10
+
11
+ -- Matthaus Owens <matthaus@puppetlabs.com> Fri, 25 Jan 2013 14:45:14 +0000
12
+
7
13
  puppet (2.7.19-1puppetlabs2) hardy jaunty karmic lucid maverick natty oneiric unstable lenny sid squeeze wheezy precise; urgency=low
8
14
 
9
15
  * (#16086) Add version parameter to rm_conffile call in puppetmaster preinst and postinst
@@ -1,2 +1,3 @@
1
1
  man/man5/puppet.conf.5
2
2
  man/man8/puppet.8
3
+ man/man8/extlookup2hiera.8
@@ -1,6 +1,8 @@
1
1
  # Defaults for puppet - sourced by /etc/init.d/puppet
2
2
 
3
- # Start puppet on boot?
3
+ # Enable puppet agent service?
4
+ # Setting this to "yes" allows the puppet agent service to run.
5
+ # Setting this to "no" keeps the puppet agent service from running.
4
6
  START=no
5
7
 
6
8
  # Startup options
@@ -1,11 +1,14 @@
1
1
  # Defaults for puppetmaster - sourced by /etc/init.d/puppetmaster
2
2
 
3
- # Start puppetmaster on boot? If you are using passenger, you should
4
- # have this set to "no"
3
+ # Enable puppetmaster service?
4
+ # Setting this to "yes" allows the puppet master service to run.
5
+ # Setting this to "no" keeps the puppet master service from running.
6
+ #
7
+ # If you are using Passenger, you should have this set to "no."
5
8
  START=yes
6
9
 
7
10
  # Startup options
8
11
  DAEMON_OPTS=""
9
12
 
10
- # What port should the puppetmaster listen on (default: 8140).
13
+ # On what port should the puppet master listen? (default: 8140)
11
14
  PORT=8140
@@ -192,11 +192,7 @@ mkdir -p %{buildroot}%{_sysconfdir}/%{name}/modules
192
192
  %{_datadir}/emacs
193
193
  %{_datadir}/vim
194
194
  %{_datadir}/%{name}
195
- # These need to be owned by puppet so the server can
196
- # write to them
197
- %attr(-, puppet, puppet) %{_localstatedir}/run/puppet
198
- %attr(0750, puppet, puppet) %{_localstatedir}/log/puppet
199
- %attr(-, puppet, puppet) %{_localstatedir}/lib/puppet
195
+ # man pages
200
196
  %{_mandir}/man5/puppet.conf.5.gz
201
197
  %{_mandir}/man8/puppet.8.gz
202
198
  %{_mandir}/man8/puppet-agent.8.gz
@@ -232,6 +228,15 @@ mkdir -p %{buildroot}%{_sysconfdir}/%{name}/modules
232
228
  %{_mandir}/man8/puppet-resource_type.8.gz
233
229
  %{_mandir}/man8/puppet-secret_agent.8.gz
234
230
  %{_mandir}/man8/puppet-status.8.gz
231
+ %{_mandir}/man8/extlookup2hiera.8.gz
232
+ # These need to be owned by puppet so the server can
233
+ # write to them. The separate %defattr's are required
234
+ # to work around RH Bugzilla 681540
235
+ %defattr(-, puppet, puppet, 0755)
236
+ %{_localstatedir}/run/puppet
237
+ %defattr(-, puppet, puppet, 0750)
238
+ %{_localstatedir}/log/puppet
239
+ %{_localstatedir}/lib/puppet
235
240
 
236
241
  %files server
237
242
  %defattr(-, root, root, 0755)
@@ -375,6 +380,12 @@ rm -rf %{buildroot}
375
380
  * <%= Time.now.strftime("%a %b %d %Y") %> Puppet Labs Release <info@puppetlabs.com> - <%= @rpmversion %>-<%= @rpmrelease %>
376
381
  - Build for <%= @version %>
377
382
 
383
+ * Fri Jan 25 2013 Matthaus Owens <matthaus@puppetlabs.com> - 3.1.0-0.1rc1
384
+ - Add extlookup2hiera.8.gz to the files list
385
+
386
+ * Wed Jan 9 2013 Ryan Uber <ru@ryanuber.com> - 3.1.0-0.1rc1
387
+ - Work-around for RH Bugzilla 681540
388
+
378
389
  * Tue Dec 18 2012 Matthaus Owens <matthaus@puppetlabs.com>
379
390
  - Remove for loop on examples/ code which no longer exists. Add --no-run-if-empty to xargs invocations.
380
391
 
@@ -155,11 +155,9 @@ module Puppet
155
155
  end
156
156
  end
157
157
 
158
- # This feels weird to me; I would really like for us to get to a state where
159
- # there is never a "require" statement anywhere besides the very top of a
160
- # file. That would not be possible at the moment without a great deal of
161
- # effort, but I think we should strive for it and revisit this at some point.
162
- # --cprice 2012-03-16
158
+ # This feels weird to me; I would really like for us to get to a state where there is never a "require" statement
159
+ # anywhere besides the very top of a file. That would not be possible at the moment without a great deal of
160
+ # effort, but I think we should strive for it and revisit this at some point. --cprice 2012-03-16
163
161
 
164
162
  require 'puppet/type'
165
163
  require 'puppet/parser'
@@ -682,10 +682,6 @@ EOT
682
682
  :desc => "The default TTL for new certificates. If this setting is set, ca_days is ignored.
683
683
  Can be specified as a duration."
684
684
  },
685
- :ca_md => {
686
- :default => "md5",
687
- :desc => "The type of hash used in certificates.",
688
- },
689
685
  :req_bits => {
690
686
  :default => 4096,
691
687
  :desc => "The bit length of the certificates.",
@@ -1089,9 +1085,14 @@ EOT
1089
1085
  },
1090
1086
  :dynamicfacts => {
1091
1087
  :default => "memorysize,memoryfree,swapsize,swapfree",
1092
- :desc => "Facts that are dynamic; these facts will be ignored when deciding whether
1088
+ :desc => "(Deprecated) Facts that are dynamic; these facts will be ignored when deciding whether
1093
1089
  changed facts should result in a recompile. Multiple facts should be
1094
1090
  comma-separated.",
1091
+ :hook => proc { |value|
1092
+ if value
1093
+ Puppet.deprecation_warning "The dynamicfacts setting is deprecated and will be ignored."
1094
+ end
1095
+ }
1095
1096
  },
1096
1097
  :splaylimit => {
1097
1098
  :default => "$runinterval",
@@ -1,11 +1,7 @@
1
1
  require 'puppet'
2
- require 'puppet/dsl/parser'
3
- require 'puppet/dsl/context'
4
2
 
5
- module Puppet
6
- # @since 3.1
7
- # @status EXPERIMENTALx
8
- module DSL
9
- end
3
+ module Puppet::DSL
10
4
  end
11
5
 
6
+ require 'puppet/dsl/resource_type_api'
7
+ require 'puppet/dsl/resource_api'
@@ -0,0 +1,120 @@
1
+ # This module adds functionality to a resource to make it
2
+ # capable of evaluating the DSL resource type block and also
3
+ # hooking into the scope system.
4
+ require 'puppet/resource/type_collection_helper'
5
+
6
+ class Puppet::DSL::ResourceAPI
7
+ include Puppet::Resource::TypeCollectionHelper
8
+
9
+ FUNCTION_MAP = {:acquire => :include}
10
+
11
+ attr_reader :scope, :resource, :block
12
+
13
+ def environment
14
+ scope.environment
15
+ end
16
+
17
+ def evaluate
18
+ set_instance_variables
19
+ instance_eval(&block)
20
+ end
21
+
22
+ def initialize(resource, scope, block)
23
+ @scope = scope
24
+ @resource = resource
25
+ @block = block
26
+ end
27
+
28
+ # Try to convert a missing method into a resource type or a function.
29
+ def method_missing(name, *args)
30
+ raise "MethodMissing loop when searching for #{name} with #{args.inspect}" if searching_for_method?
31
+ @searching_for_method = true
32
+ return create_resource(name, args[0], args[1]) if valid_type?(name)
33
+
34
+ name = map_function(name)
35
+
36
+ return call_function(name, args) if Puppet::Parser::Functions.function(name)
37
+
38
+ super
39
+ ensure
40
+ @searching_for_method = false
41
+ end
42
+
43
+ def set_instance_variables
44
+ resource.eachparam do |param|
45
+ instance_variable_set("@#{param.name}", param.value)
46
+ end
47
+ @title = resource.title
48
+ @name ||= resource.title
49
+ end
50
+
51
+ def create_resource(type, names, arguments = nil)
52
+ names = [names] unless names.is_a?(Array)
53
+
54
+ arguments ||= {}
55
+ raise ArgumentError, "Resource arguments must be provided as a hash" unless arguments.is_a?(Hash)
56
+
57
+ names.collect do |name|
58
+ resource = Puppet::Parser::Resource.new(type, name, :scope => scope)
59
+ arguments.each do |param, value|
60
+ resource[param] = value
61
+ end
62
+
63
+ resource.exported = true if exporting?
64
+ resource.virtual = true if virtualizing?
65
+ scope.compiler.add_resource(scope, resource)
66
+ resource
67
+ end
68
+ end
69
+
70
+ def call_function(name, args)
71
+ return false unless method = Puppet::Parser::Functions.function(name)
72
+ scope.send(method, *args)
73
+ end
74
+
75
+ def export(resources = nil, &block)
76
+ if resources
77
+ resources.each { |resource| resource.exported = true }
78
+ return resources
79
+ end
80
+ @exporting = true
81
+ instance_eval(&block)
82
+ ensure
83
+ @exporting = false
84
+ end
85
+
86
+ def virtual(resources = nil, &block)
87
+ if resources
88
+ resources.each { |resource| resource.virtual = true }
89
+ return resources
90
+ end
91
+ @virtualizing = true
92
+ instance_eval(&block)
93
+ ensure
94
+ @virtualizing = false
95
+ end
96
+
97
+ def valid_type?(name)
98
+ return true if [:class, :node].include?(name)
99
+ return true if Puppet::Type.type(name)
100
+ return(known_resource_types.definition(name) ? true : false)
101
+ end
102
+
103
+ private
104
+
105
+ def exporting?
106
+ @exporting
107
+ end
108
+
109
+ def map_function(name)
110
+ FUNCTION_MAP[name] || name
111
+ end
112
+
113
+ def searching_for_method?
114
+ @searching_for_method
115
+ end
116
+
117
+ def virtualizing?
118
+ @virtualizing
119
+ end
120
+ end