chef 0.7.10 → 0.7.12
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of chef might be problematic. Click here for more details.
- data/distro/debian/etc/init.d/chef-client +175 -0
- data/distro/debian/etc/init.d/chef-indexer +175 -0
- data/distro/debian/etc/init.d/chef-server +120 -0
- data/distro/debian/man/man1/chef-indexer.1 +42 -0
- data/distro/debian/man/man1/chef-server.1 +108 -0
- data/distro/debian/man/man8/chef-client.8 +61 -0
- data/distro/debian/man/man8/chef-solo.8 +58 -0
- data/distro/redhat/etc/chef/client.rb +16 -0
- data/distro/redhat/etc/chef/indexer.rb +10 -0
- data/distro/redhat/etc/chef/server.rb +22 -0
- data/distro/redhat/etc/init.d/chef-client +74 -0
- data/distro/redhat/etc/init.d/chef-indexer +76 -0
- data/distro/redhat/etc/init.d/chef-server +77 -0
- data/lib/chef.rb +1 -1
- data/lib/chef/client.rb +33 -8
- data/lib/chef/compile.rb +34 -2
- data/lib/chef/cookbook.rb +29 -2
- data/lib/chef/cookbook_loader.rb +61 -49
- data/lib/chef/couchdb.rb +7 -3
- data/lib/chef/mixin/command.rb +67 -32
- data/lib/chef/mixin/convert_to_class_name.rb +48 -0
- data/lib/chef/mixin/find_preferred_file.rb +5 -14
- data/lib/chef/mixin/from_file.rb +14 -0
- data/lib/chef/mixin/generate_url.rb +2 -1
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -0
- data/lib/chef/platform.rb +1 -1
- data/lib/chef/provider.rb +63 -2
- data/lib/chef/provider/cron.rb +75 -25
- data/lib/chef/provider/deploy.rb +281 -0
- data/lib/chef/provider/deploy/revision.rb +70 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/git.rb +194 -0
- data/lib/chef/provider/group.rb +2 -2
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +2 -16
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/ifconfig.rb +3 -3
- data/lib/chef/provider/mount.rb +0 -4
- data/lib/chef/provider/mount/mount.rb +2 -2
- data/lib/chef/provider/package.rb +2 -2
- data/lib/chef/provider/package/apt.rb +4 -4
- data/lib/chef/provider/package/dpkg.rb +9 -13
- data/lib/chef/provider/package/freebsd.rb +6 -6
- data/lib/chef/provider/package/macports.rb +4 -4
- data/lib/chef/provider/package/portage.rb +3 -3
- data/lib/chef/provider/package/rpm.rb +4 -4
- data/lib/chef/provider/package/rubygems.rb +10 -4
- data/lib/chef/provider/package/yum.rb +6 -6
- data/lib/chef/provider/remote_file.rb +14 -7
- data/lib/chef/provider/service.rb +8 -2
- data/lib/chef/provider/service/freebsd.rb +1 -1
- data/lib/chef/provider/service/init.rb +8 -63
- data/lib/chef/provider/service/redhat.rb +2 -2
- data/lib/chef/provider/service/simple.rb +115 -0
- data/lib/chef/provider/subversion.rb +145 -0
- data/lib/chef/provider/template.rb +2 -0
- data/lib/chef/provider/user.rb +2 -2
- data/lib/chef/recipe.rb +9 -75
- data/lib/chef/resource.rb +131 -7
- data/lib/chef/resource/cron.rb +36 -0
- data/lib/chef/resource/deploy.rb +360 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +2 -0
- data/lib/chef/resource/scm.rb +129 -0
- data/lib/chef/resource/subversion.rb +33 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource_collection.rb +32 -4
- data/lib/chef/runner.rb +35 -28
- metadata +40 -11
@@ -70,7 +70,7 @@ class Chef
|
|
70
70
|
end
|
71
71
|
|
72
72
|
status = popen4(@node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
73
|
-
stdin.close
|
73
|
+
stdin.close rescue nil
|
74
74
|
r = Regexp.new(@new_resource.pattern)
|
75
75
|
Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
|
76
76
|
stdout.each_line do |line|
|
@@ -17,76 +17,22 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require 'chef/provider/service'
|
20
|
+
require 'chef/provider/service/simple'
|
20
21
|
require 'chef/mixin/command'
|
21
22
|
|
22
23
|
class Chef
|
23
24
|
class Provider
|
24
25
|
class Service
|
25
|
-
class Init < Chef::Provider::Service
|
26
|
+
class Init < Chef::Provider::Service::Simple
|
26
27
|
|
27
|
-
def initialize(node, new_resource)
|
28
|
-
super(node, new_resource)
|
28
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
29
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
29
30
|
@init_command = "/etc/init.d/#{@new_resource.service_name}"
|
30
31
|
end
|
31
32
|
|
32
|
-
def load_current_resource
|
33
|
-
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
34
|
-
@current_resource.service_name(@new_resource.service_name)
|
35
|
-
if @new_resource.status_command
|
36
|
-
Chef::Log.debug("#{@new_resource} you have specified a status command, running..")
|
37
|
-
|
38
|
-
begin
|
39
|
-
if run_command(:command => @new_resource.status_command) == 0
|
40
|
-
@current_resource.running true
|
41
|
-
end
|
42
|
-
rescue Chef::Exceptions::Exec
|
43
|
-
@current_resource.running false
|
44
|
-
nil
|
45
|
-
end
|
46
|
-
|
47
|
-
elsif @new_resource.supports[:status]
|
48
|
-
Chef::Log.debug("#{@new_resource} supports status, running")
|
49
|
-
|
50
|
-
begin
|
51
|
-
if run_command(:command => "#{@init_command} status") == 0
|
52
|
-
@current_resource.running true
|
53
|
-
end
|
54
|
-
rescue Chef::Exceptions::Exec
|
55
|
-
@current_resource.running false
|
56
|
-
nil
|
57
|
-
end
|
58
|
-
|
59
|
-
else
|
60
|
-
Chef::Log.debug("#{@new_resource} does not support status and you have not specified a status command, falling back to process table inspection")
|
61
|
-
|
62
|
-
if @node[:command][:ps].nil? or @node[:command][:ps].empty?
|
63
|
-
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'ps' attribute"
|
64
|
-
end
|
65
|
-
|
66
|
-
status = popen4(@node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
67
|
-
r = Regexp.new(@new_resource.pattern)
|
68
|
-
Chef::Log.debug("#{@new_resource}: attempting to match #{@new_resource.pattern} (#{r}) against process table")
|
69
|
-
stdout.each_line do |line|
|
70
|
-
if r.match(line)
|
71
|
-
@current_resource.running true
|
72
|
-
break
|
73
|
-
end
|
74
|
-
end
|
75
|
-
@current_resource.running false unless @current_resource.running
|
76
|
-
end
|
77
|
-
unless status.exitstatus == 0
|
78
|
-
raise Chef::Exceptions::Service, "Command #{@node[:command][:ps]} failed"
|
79
|
-
else
|
80
|
-
Chef::Log.debug("#{@new_resource}: #{@node[:command][:ps]} exited and parsed successfully, process running: #{@current_resource.running}")
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
@current_resource
|
85
|
-
end
|
86
|
-
|
87
33
|
def start_service
|
88
34
|
if @new_resource.start_command
|
89
|
-
|
35
|
+
super
|
90
36
|
else
|
91
37
|
run_command(:command => "#{@init_command} start")
|
92
38
|
end
|
@@ -94,7 +40,7 @@ class Chef
|
|
94
40
|
|
95
41
|
def stop_service
|
96
42
|
if @new_resource.stop_command
|
97
|
-
|
43
|
+
super
|
98
44
|
else
|
99
45
|
run_command(:command => "#{@init_command} stop")
|
100
46
|
end
|
@@ -102,7 +48,7 @@ class Chef
|
|
102
48
|
|
103
49
|
def restart_service
|
104
50
|
if @new_resource.restart_command
|
105
|
-
|
51
|
+
super
|
106
52
|
elsif @new_resource.supports[:restart]
|
107
53
|
run_command(:command => "#{@init_command} restart")
|
108
54
|
else
|
@@ -114,12 +60,11 @@ class Chef
|
|
114
60
|
|
115
61
|
def reload_service
|
116
62
|
if @new_resource.reload_command
|
117
|
-
|
63
|
+
super
|
118
64
|
elsif @new_resource.supports[:reload]
|
119
65
|
run_command(:command => "#{@init_command} reload")
|
120
66
|
end
|
121
67
|
end
|
122
|
-
|
123
68
|
end
|
124
69
|
end
|
125
70
|
end
|
@@ -25,8 +25,8 @@ class Chef
|
|
25
25
|
class Service
|
26
26
|
class Redhat < Chef::Provider::Service::Init
|
27
27
|
|
28
|
-
def initialize(node, new_resource)
|
29
|
-
|
28
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
29
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
30
30
|
@init_command = "/sbin/service #{@new_resource.service_name}"
|
31
31
|
end
|
32
32
|
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Mathieu Sauve-Frankel <msf@kisoku.net>
|
3
|
+
# Copyright:: Copyright (c) 2009 Mathieu Sauve-Frankel
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider/service'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Service
|
25
|
+
class Simple < Chef::Provider::Service
|
26
|
+
def load_current_resource
|
27
|
+
@current_resource = Chef::Resource::Service.new(@new_resource.name)
|
28
|
+
@current_resource.service_name(@new_resource.service_name)
|
29
|
+
if @new_resource.status_command
|
30
|
+
Chef::Log.debug("#{@new_resource} you have specified a status command, running..")
|
31
|
+
|
32
|
+
begin
|
33
|
+
if run_command(:command => @new_resource.status_command) == 0
|
34
|
+
@current_resource.running true
|
35
|
+
end
|
36
|
+
rescue Chef::Exceptions::Exec
|
37
|
+
@current_resource.running false
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
elsif @new_resource.supports[:status]
|
42
|
+
Chef::Log.debug("#{@new_resource} supports status, running")
|
43
|
+
|
44
|
+
begin
|
45
|
+
if run_command(:command => "#{@init_command} status") == 0
|
46
|
+
@current_resource.running true
|
47
|
+
end
|
48
|
+
rescue Chef::Exceptions::Exec
|
49
|
+
@current_resource.running false
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
elsif
|
53
|
+
Chef::Log.warn "#{@new_resource}: falling back to process table inspection"
|
54
|
+
if @node[:command][:ps].nil? or @node[:command][:ps].empty?
|
55
|
+
raise Chef::Exceptions::Service, "#{@new_resource}: could not determine how to inspect the process table, please set this nodes 'command.ps' attribute"
|
56
|
+
end
|
57
|
+
status = popen4(@node[:command][:ps]) do |pid, stdin, stdout, stderr|
|
58
|
+
stdin.close rescue nil
|
59
|
+
r = Regexp.new(@new_resource.pattern)
|
60
|
+
Chef::Log.warn "#{@new_resource}: attempting to match '#{@new_resource.pattern}' (#{r}) against process list"
|
61
|
+
stdout.each_line do |line|
|
62
|
+
if r.match(line)
|
63
|
+
@current_resource.running true
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
@current_resource.running false unless @current_resource.running
|
68
|
+
end
|
69
|
+
unless status.exitstatus == 0
|
70
|
+
raise Chef::Exceptions::Service, "Command #{@node[:command][:ps]} failed"
|
71
|
+
else
|
72
|
+
Chef::Log.debug "#{@new_resource}: running: #{@current_resource.running}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
@current_resource
|
77
|
+
end
|
78
|
+
|
79
|
+
def start_service
|
80
|
+
if @new_resource.start_command
|
81
|
+
run_command(:command => @new_resource.start_command)
|
82
|
+
else
|
83
|
+
raise Chef::Exceptions::Service, "#{self.to_s} requires that start_command to be set"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def stop_service
|
88
|
+
if @new_resource.stop_command
|
89
|
+
run_command(:command => @new_resource.stop_command)
|
90
|
+
else
|
91
|
+
raise Chef::Exceptions::Service, "#{self.to_s} requires that stop_command to be set"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def restart_service
|
96
|
+
if @new_resource.restart_command
|
97
|
+
run_command(:command => @new_resource.restart_command)
|
98
|
+
else
|
99
|
+
stop_service
|
100
|
+
sleep 1
|
101
|
+
start_service
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def reload_service
|
106
|
+
if @new_resource.reload_command
|
107
|
+
run_command(:command => @new_resource.reload_command)
|
108
|
+
else
|
109
|
+
raise Chef::Exceptions::Service, "#{self.to_s} requires that reload_command to be set"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
require 'chef/log'
|
21
|
+
require 'chef/provider'
|
22
|
+
require 'chef/mixin/command'
|
23
|
+
require 'fileutils'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Provider
|
27
|
+
class Subversion < Chef::Provider
|
28
|
+
|
29
|
+
include Chef::Mixin::Command
|
30
|
+
|
31
|
+
def load_current_resource
|
32
|
+
@current_resource = Chef::Resource::Subversion.new(@new_resource.name)
|
33
|
+
if current_revision = find_current_revision
|
34
|
+
@current_resource.revision current_revision
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def action_checkout
|
39
|
+
run_command(run_options(:command => checkout_command))
|
40
|
+
end
|
41
|
+
|
42
|
+
def action_export
|
43
|
+
run_command(run_options(:command => export_command))
|
44
|
+
end
|
45
|
+
|
46
|
+
def action_sync
|
47
|
+
if !::File.exist?(@new_resource.destination + "/.svn") || ::Dir.entries(@new_resource.destination) == ['.','..']
|
48
|
+
action_checkout
|
49
|
+
else
|
50
|
+
run_command(run_options(:command => sync_command))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sync_command
|
55
|
+
Chef::Log.info "Updating working copy #{@new_resource.destination} to revision #{@new_resource.revision}"
|
56
|
+
scm :update, @new_resource.svn_arguments, verbose, authentication, "-r#{revision_int}", @new_resource.destination
|
57
|
+
end
|
58
|
+
|
59
|
+
def checkout_command
|
60
|
+
Chef::Log.info "checking out #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
61
|
+
scm :checkout, @new_resource.svn_arguments, verbose, authentication,
|
62
|
+
"-r#{revision_int}", @new_resource.repository, @new_resource.destination
|
63
|
+
end
|
64
|
+
|
65
|
+
def export_command
|
66
|
+
Chef::Log.info "exporting #{@new_resource.repository} at revision #{@new_resource.revision} to #{@new_resource.destination}"
|
67
|
+
scm :export, @new_resource.svn_arguments, verbose, authentication,
|
68
|
+
"-r#{revision_int}", @new_resource.repository, @new_resource.destination
|
69
|
+
end
|
70
|
+
|
71
|
+
# If the specified revision isn't an integer ("HEAD" for example), look
|
72
|
+
# up the revision id by asking the server
|
73
|
+
# If the specified revision is an integer, trust it.
|
74
|
+
def revision_int
|
75
|
+
@revision_int ||= begin
|
76
|
+
if @new_resource.revision =~ /^\d+$/
|
77
|
+
@new_resource.revision
|
78
|
+
else
|
79
|
+
command = scm(:info, @new_resource.repository, authentication, "-r#{@new_resource.revision}")
|
80
|
+
status, svn_info, error_message = output_of_command(command, run_options)
|
81
|
+
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
82
|
+
extract_revision_info(svn_info)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
alias :revision_slug :revision_int
|
88
|
+
|
89
|
+
def find_current_revision
|
90
|
+
return nil unless ::File.exist?(@new_resource.destination)
|
91
|
+
command = scm(:info)
|
92
|
+
status, svn_info, error_message = output_of_command(command, run_options(:cwd => cwd))
|
93
|
+
|
94
|
+
unless [0,1].include?(status.exitstatus)
|
95
|
+
handle_command_failures(status, "STDOUT: #{svn_info}\nSTDERR: #{error_message}")
|
96
|
+
end
|
97
|
+
extract_revision_info(svn_info)
|
98
|
+
end
|
99
|
+
|
100
|
+
def run_options(run_opts={})
|
101
|
+
run_opts[:user] = @new_resource.user if @new_resource.user
|
102
|
+
run_opts
|
103
|
+
end
|
104
|
+
|
105
|
+
private
|
106
|
+
|
107
|
+
def cwd
|
108
|
+
@new_resource.destination
|
109
|
+
end
|
110
|
+
|
111
|
+
def verbose
|
112
|
+
"-q"
|
113
|
+
end
|
114
|
+
|
115
|
+
def extract_revision_info(svn_info)
|
116
|
+
begin
|
117
|
+
repo_attrs = YAML.load(svn_info)
|
118
|
+
rescue ArgumentError
|
119
|
+
# YAML doesn't appreciate input like "svn: '/tmp/deploydir' is not a working copy\n"
|
120
|
+
return nil
|
121
|
+
end
|
122
|
+
raise "tried to run `#{command}' and got unexpected result #{result.inspect}" unless repo_attrs.kind_of?(Hash)
|
123
|
+
rev = (repo_attrs['Last Changed Rev'] || repo_attrs['Revision']).to_s
|
124
|
+
Chef::Log.debug "Resolved revision #{@new_resource.revision} to #{rev}"
|
125
|
+
rev
|
126
|
+
end
|
127
|
+
|
128
|
+
# If a username is configured for the SCM, return the command-line
|
129
|
+
# switches for that. Note that we don't need to return the password
|
130
|
+
# switch, since Capistrano will check for that prompt in the output
|
131
|
+
# and will respond appropriately.
|
132
|
+
def authentication
|
133
|
+
return "" unless @new_resource.svn_username
|
134
|
+
result = "--username #{@new_resource.svn_username} "
|
135
|
+
result << "--password #{@new_resource.svn_password} "
|
136
|
+
result
|
137
|
+
end
|
138
|
+
|
139
|
+
def scm(*args)
|
140
|
+
['svn', *args].compact.join(" ")
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -39,6 +39,8 @@ class Chef
|
|
39
39
|
|
40
40
|
cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
|
41
41
|
|
42
|
+
Chef::Log.debug("looking for template #{@new_resource.source} in cookbook #{cookbook_name.inspect}")
|
43
|
+
|
42
44
|
cache_file_name = "cookbooks/#{cookbook_name}/templates/default/#{@new_resource.source}"
|
43
45
|
template_cache_name = "#{cookbook_name}_#{@new_resource.source}"
|
44
46
|
|
data/lib/chef/provider/user.rb
CHANGED
@@ -29,8 +29,8 @@ class Chef
|
|
29
29
|
|
30
30
|
attr_accessor :user_exists, :locked
|
31
31
|
|
32
|
-
def initialize(node, new_resource)
|
33
|
-
super(node, new_resource)
|
32
|
+
def initialize(node, new_resource, collection=nil, definitions=nil, cookbook_loader=nil)
|
33
|
+
super(node, new_resource, collection, definitions, cookbook_loader)
|
34
34
|
@user_exists = true
|
35
35
|
@locked = nil
|
36
36
|
end
|
data/lib/chef/recipe.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
#
|
3
|
+
# Author:: Christopher Walters (<cw@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -20,6 +21,7 @@ require 'chef/resource'
|
|
20
21
|
Dir[File.join(File.dirname(__FILE__), 'resource/**/*.rb')].sort.each { |lib| require lib }
|
21
22
|
require 'chef/mixin/from_file'
|
22
23
|
require 'chef/mixin/language'
|
24
|
+
require 'chef/mixin/recipe_definition_dsl_core'
|
23
25
|
require 'chef/resource_collection'
|
24
26
|
require 'chef/cookbook_loader'
|
25
27
|
require 'chef/rest'
|
@@ -30,7 +32,8 @@ class Chef
|
|
30
32
|
|
31
33
|
include Chef::Mixin::FromFile
|
32
34
|
include Chef::Mixin::Language
|
33
|
-
|
35
|
+
include Chef::Mixin::RecipeDefinitionDSLCore
|
36
|
+
|
34
37
|
attr_accessor :cookbook_name, :recipe_name, :recipe, :node, :collection,
|
35
38
|
:definitions, :params, :cookbook_loader
|
36
39
|
|
@@ -38,25 +41,9 @@ class Chef
|
|
38
41
|
@cookbook_name = cookbook_name
|
39
42
|
@recipe_name = recipe_name
|
40
43
|
@node = node
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
else
|
45
|
-
@collection = Chef::ResourceCollection.new()
|
46
|
-
end
|
47
|
-
|
48
|
-
if definitions
|
49
|
-
@definitions = definitions
|
50
|
-
else
|
51
|
-
@definitions = Hash.new
|
52
|
-
end
|
53
|
-
|
54
|
-
if cookbook_loader
|
55
|
-
@cookbook_loader = cookbook_loader
|
56
|
-
else
|
57
|
-
@cookbook_loader = Chef::CookbookLoader.new()
|
58
|
-
end
|
59
|
-
|
44
|
+
@collection = collection || Chef::ResourceCollection.new
|
45
|
+
@definitions = definitions || Hash.new
|
46
|
+
@cookbook_loader = cookbook_loader || Chef::CookbookLoader.new
|
60
47
|
@params = Hash.new
|
61
48
|
end
|
62
49
|
|
@@ -152,59 +139,6 @@ class Chef
|
|
152
139
|
@node[:tags].delete(tag)
|
153
140
|
end
|
154
141
|
end
|
155
|
-
|
156
|
-
def method_missing(method_symbol, *args, &block)
|
157
|
-
resource = nil
|
158
|
-
# If we have a definition that matches, we want to use that instead. This should
|
159
|
-
# let you do some really crazy over-riding of "native" types, if you really want
|
160
|
-
# to.
|
161
|
-
if @definitions.has_key?(method_symbol)
|
162
|
-
# This dupes the high level object, but we still need to dup the params
|
163
|
-
new_def = @definitions[method_symbol].dup
|
164
|
-
new_def.params = new_def.params.dup
|
165
|
-
new_def.node = @node
|
166
|
-
# This sets up the parameter overrides
|
167
|
-
new_def.instance_eval(&block) if block
|
168
|
-
new_recipe = Chef::Recipe.new(@cookbook_name, @recipe_name, @node, @collection, @definitions, @cookbook_loader)
|
169
|
-
new_recipe.params = new_def.params
|
170
|
-
new_recipe.params[:name] = args[0]
|
171
|
-
new_recipe.instance_eval(&new_def.recipe)
|
172
|
-
else
|
173
|
-
method_name = method_symbol.to_s
|
174
|
-
# Otherwise, we're rocking the regular resource call route.
|
175
|
-
rname = nil
|
176
|
-
regexp = %r{^(.+?)(_(.+))?$}
|
177
|
-
|
178
|
-
mn = method_name.match(regexp)
|
179
|
-
if mn
|
180
|
-
rname = "Chef::Resource::#{mn[1].capitalize}"
|
181
|
-
|
182
|
-
while mn && mn[3]
|
183
|
-
mn = mn[3].match(regexp)
|
184
|
-
rname << mn[1].capitalize if mn
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
begin
|
189
|
-
args << @collection
|
190
|
-
args << @node
|
191
|
-
resource = eval(rname).new(*args)
|
192
|
-
# If we have a resource like this one, we want to steal it's state
|
193
|
-
resource.load_prior_resource
|
194
|
-
resource.cookbook_name = @cookbook_name
|
195
|
-
resource.recipe_name = @recipe_name
|
196
|
-
resource.params = @params
|
197
|
-
resource.instance_eval(&block) if block
|
198
|
-
rescue Exception => e
|
199
|
-
if e.kind_of?(NameError) && e.to_s =~ /Chef::Resource/
|
200
|
-
raise NameError, "Cannot find #{rname} for #{method_name}\nOriginal: #{e.to_s}"
|
201
|
-
else
|
202
|
-
raise e
|
203
|
-
end
|
204
|
-
end
|
205
|
-
@collection << resource
|
206
|
-
resource
|
207
|
-
end
|
208
|
-
end
|
142
|
+
|
209
143
|
end
|
210
144
|
end
|