giraffesoft-chef 0.7.15
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -0
- 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 +49 -0
- data/lib/chef/application.rb +98 -0
- data/lib/chef/application/agent.rb +18 -0
- data/lib/chef/application/client.rb +209 -0
- data/lib/chef/application/indexer.rb +141 -0
- data/lib/chef/application/server.rb +18 -0
- data/lib/chef/application/solo.rb +214 -0
- data/lib/chef/client.rb +421 -0
- data/lib/chef/compile.rb +170 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +171 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +180 -0
- data/lib/chef/couchdb.rb +176 -0
- data/lib/chef/daemon.rb +170 -0
- data/lib/chef/exceptions.rb +36 -0
- data/lib/chef/file_cache.rb +205 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +37 -0
- data/lib/chef/mixin/command.rb +386 -0
- data/lib/chef/mixin/convert_to_class_name.rb +48 -0
- data/lib/chef/mixin/create_path.rb +56 -0
- data/lib/chef/mixin/deep_merge.rb +36 -0
- data/lib/chef/mixin/find_preferred_file.rb +92 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/generate_url.rb +49 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +77 -0
- data/lib/chef/mixin/template.rb +84 -0
- data/lib/chef/node.rb +406 -0
- data/lib/chef/node/attribute.rb +412 -0
- data/lib/chef/openid_registration.rb +181 -0
- data/lib/chef/platform.rb +254 -0
- data/lib/chef/provider.rb +101 -0
- data/lib/chef/provider/cron.rb +187 -0
- 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/directory.rb +72 -0
- data/lib/chef/provider/execute.rb +58 -0
- data/lib/chef/provider/file.rb +191 -0
- data/lib/chef/provider/git.rb +198 -0
- data/lib/chef/provider/group.rb +120 -0
- data/lib/chef/provider/group/gpasswd.rb +50 -0
- data/lib/chef/provider/group/groupadd.rb +78 -0
- data/lib/chef/provider/group/pw.rb +88 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/http_request.rb +102 -0
- data/lib/chef/provider/ifconfig.rb +131 -0
- data/lib/chef/provider/link.rb +157 -0
- data/lib/chef/provider/mount.rb +117 -0
- data/lib/chef/provider/mount/mount.rb +208 -0
- data/lib/chef/provider/package.rb +160 -0
- data/lib/chef/provider/package/apt.rb +110 -0
- data/lib/chef/provider/package/dpkg.rb +109 -0
- data/lib/chef/provider/package/freebsd.rb +153 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/portage.rb +124 -0
- data/lib/chef/provider/package/rpm.rb +99 -0
- data/lib/chef/provider/package/rubygems.rb +136 -0
- data/lib/chef/provider/package/yum-dump.py +106 -0
- data/lib/chef/provider/package/yum.rb +175 -0
- data/lib/chef/provider/remote_directory.rb +126 -0
- data/lib/chef/provider/remote_file.rb +141 -0
- data/lib/chef/provider/route.rb +118 -0
- data/lib/chef/provider/ruby_block.rb +15 -0
- data/lib/chef/provider/script.rb +42 -0
- data/lib/chef/provider/service.rb +135 -0
- data/lib/chef/provider/service/debian.rb +64 -0
- data/lib/chef/provider/service/freebsd.rb +157 -0
- data/lib/chef/provider/service/gentoo.rb +54 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/service/simple.rb +115 -0
- data/lib/chef/provider/subversion.rb +148 -0
- data/lib/chef/provider/template.rb +143 -0
- data/lib/chef/provider/user.rb +170 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +107 -0
- data/lib/chef/queue.rb +145 -0
- data/lib/chef/recipe.rb +144 -0
- data/lib/chef/resource.rb +380 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +179 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +350 -0
- data/lib/chef/resource/deploy_revision.rb +35 -0
- data/lib/chef/resource/directory.rb +76 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +84 -0
- data/lib/chef/resource/gem_package.rb +41 -0
- data/lib/chef/resource/git.rb +36 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/http_request.rb +52 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +78 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mount.rb +135 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/perl.rb +33 -0
- data/lib/chef/resource/portage_package.rb +33 -0
- data/lib/chef/resource/python.rb +33 -0
- data/lib/chef/resource/remote_directory.rb +91 -0
- data/lib/chef/resource/remote_file.rb +60 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +20 -0
- data/lib/chef/resource/scm.rb +129 -0
- data/lib/chef/resource/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/subversion.rb +33 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +204 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/rest.rb +238 -0
- data/lib/chef/role.rb +231 -0
- data/lib/chef/run_list.rb +156 -0
- data/lib/chef/runner.rb +130 -0
- data/lib/chef/search.rb +88 -0
- data/lib/chef/search/result.rb +64 -0
- data/lib/chef/search_index.rb +77 -0
- data/lib/chef/tasks/chef_repo.rake +347 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +293 -0
data/lib/chef/compile.rb
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Christopher Walters (<cw@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require 'chef/cookbook_loader'
|
20
|
+
require 'chef/resource_collection'
|
21
|
+
require 'chef/node'
|
22
|
+
require 'chef/role'
|
23
|
+
require 'chef/log'
|
24
|
+
require 'chef/mixin/deep_merge'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Compile
|
28
|
+
|
29
|
+
attr_accessor :node, :cookbook_loader, :collection, :definitions
|
30
|
+
|
31
|
+
# Creates a new Chef::Compile object and populates its fields. This object gets
|
32
|
+
# used by the Chef Server to generate a fully compiled recipe list for a node.
|
33
|
+
#
|
34
|
+
# === Returns
|
35
|
+
# object<Chef::Compile>:: Duh. :)
|
36
|
+
def initialize(node=nil)
|
37
|
+
@node = node
|
38
|
+
@cookbook_loader = Chef::CookbookLoader.new
|
39
|
+
@collection = Chef::ResourceCollection.new
|
40
|
+
@definitions = Hash.new
|
41
|
+
@recipes = Array.new
|
42
|
+
@default_attributes = Array.new
|
43
|
+
@override_attributes = Array.new
|
44
|
+
|
45
|
+
load_libraries
|
46
|
+
load_providers
|
47
|
+
load_resources
|
48
|
+
load_attributes
|
49
|
+
load_definitions
|
50
|
+
load_recipes
|
51
|
+
end
|
52
|
+
|
53
|
+
# Looks up the node via the "name" argument, first from CouchDB, then by calling
|
54
|
+
# Chef::Node.find_file(name)
|
55
|
+
#
|
56
|
+
# The first step in compiling the catalog. Results available via the node accessor.
|
57
|
+
#
|
58
|
+
# === Returns
|
59
|
+
# node<Chef::Node>:: The loaded Chef Node
|
60
|
+
def load_node(name)
|
61
|
+
Chef::Log.debug("Loading Chef Node #{name} from CouchDB")
|
62
|
+
@node = Chef::Node.load(name)
|
63
|
+
Chef::Log.debug("Loading Recipe for Chef Node #{name}")
|
64
|
+
@node.find_file(name)
|
65
|
+
@node
|
66
|
+
end
|
67
|
+
|
68
|
+
# Load all the attributes, from every cookbook
|
69
|
+
#
|
70
|
+
# === Returns
|
71
|
+
# true:: Always returns true
|
72
|
+
def load_attributes()
|
73
|
+
recipes, default_attrs, override_attrs = expand_node
|
74
|
+
|
75
|
+
@cookbook_loader.each do |cookbook|
|
76
|
+
cookbook.load_attributes(@node)
|
77
|
+
end
|
78
|
+
|
79
|
+
true
|
80
|
+
end
|
81
|
+
|
82
|
+
# Load all the definitions, from every cookbook, so they are available when we process
|
83
|
+
# the recipes.
|
84
|
+
#
|
85
|
+
# Results available via the definitions accessor.
|
86
|
+
#
|
87
|
+
# === Returns
|
88
|
+
# true:: Always returns true
|
89
|
+
def load_definitions()
|
90
|
+
@cookbook_loader.each do |cookbook|
|
91
|
+
hash = cookbook.load_definitions
|
92
|
+
@definitions.merge!(hash)
|
93
|
+
end
|
94
|
+
true
|
95
|
+
end
|
96
|
+
|
97
|
+
# Load all the libraries, from every cookbook, so they are available when we process
|
98
|
+
# the recipes.
|
99
|
+
#
|
100
|
+
# === Returns
|
101
|
+
# true:: Always returns true
|
102
|
+
def load_libraries()
|
103
|
+
@cookbook_loader.each do |cookbook|
|
104
|
+
cookbook.load_libraries
|
105
|
+
end
|
106
|
+
true
|
107
|
+
end
|
108
|
+
|
109
|
+
# Load all the providers, from every cookbook, so they are available when we process
|
110
|
+
# the recipes.
|
111
|
+
#
|
112
|
+
# === Returns
|
113
|
+
# true:: Always returns true
|
114
|
+
def load_providers()
|
115
|
+
@cookbook_loader.each do |cookbook|
|
116
|
+
cookbook.load_providers
|
117
|
+
end
|
118
|
+
true
|
119
|
+
end
|
120
|
+
|
121
|
+
# Load all the resources, from every cookbook, so they are available when we process
|
122
|
+
# the recipes.
|
123
|
+
#
|
124
|
+
# === Returns
|
125
|
+
# true:: Always returns true
|
126
|
+
def load_resources()
|
127
|
+
@cookbook_loader.each do |cookbook|
|
128
|
+
cookbook.load_resources
|
129
|
+
end
|
130
|
+
true
|
131
|
+
end
|
132
|
+
|
133
|
+
# Load all the recipes specified in the node data (loaded via load_node, above.)
|
134
|
+
#
|
135
|
+
# The results are available via the collection accessor (which returns a Chef::ResourceCollection
|
136
|
+
# object)
|
137
|
+
#
|
138
|
+
# === Returns
|
139
|
+
# true:: Always returns true
|
140
|
+
def load_recipes
|
141
|
+
expand_node
|
142
|
+
@recipes.each do |recipe|
|
143
|
+
if @node.run_state[:seen_recipes].has_key?(recipe)
|
144
|
+
Chef::Log.debug("I am not loading #{recipe}, because I have already seen it.")
|
145
|
+
next
|
146
|
+
end
|
147
|
+
Chef::Log.debug("Loading Recipe #{recipe}")
|
148
|
+
@node.run_state[:seen_recipes][recipe] = true
|
149
|
+
|
150
|
+
rmatch = recipe.match(/(.+?)::(.+)/)
|
151
|
+
if rmatch
|
152
|
+
cookbook = @cookbook_loader[rmatch[1]]
|
153
|
+
cookbook.load_recipe(rmatch[2], @node, @collection, @definitions, @cookbook_loader)
|
154
|
+
else
|
155
|
+
cookbook = @cookbook_loader[recipe]
|
156
|
+
cookbook.load_recipe("default", @node, @collection, @definitions, @cookbook_loader)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
true
|
160
|
+
end
|
161
|
+
|
162
|
+
def expand_node
|
163
|
+
@recipes, @default_attributes, @override_attributes = @node.run_list.expand
|
164
|
+
@node.default = @default_attributes
|
165
|
+
@node.override = @override_attributes
|
166
|
+
return @recipes, @default_attributes, @override_attributes
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
data/lib/chef/config.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Christopher Brown (<cb@opscode.com>)
|
4
|
+
# Author:: AJ Christensen (<aj@opscode.com>)
|
5
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
6
|
+
# License:: Apache License, Version 2.0
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
|
20
|
+
require 'mixlib/config'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Config
|
24
|
+
|
25
|
+
extend Mixlib::Config
|
26
|
+
|
27
|
+
# Manages the chef secret session key
|
28
|
+
# === Returns
|
29
|
+
# <newkey>:: A new or retrieved session key
|
30
|
+
#
|
31
|
+
def self.manage_secret_key
|
32
|
+
newkey = nil
|
33
|
+
if Chef::FileCache.has_key?("chef_server_cookie_id")
|
34
|
+
newkey = Chef::FileCache.load("chef_server_cookie_id")
|
35
|
+
else
|
36
|
+
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
|
37
|
+
newkey = ""
|
38
|
+
40.times { |i| newkey << chars[rand(chars.size-1)] }
|
39
|
+
Chef::FileCache.store("chef_server_cookie_id", newkey)
|
40
|
+
end
|
41
|
+
newkey
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# Override the config dispatch to set the value of multiple server options simultaneously
|
46
|
+
#
|
47
|
+
# === Parameters
|
48
|
+
# url<String>:: String to be set for all of the chef-server-api URL's
|
49
|
+
#
|
50
|
+
config_attr_writer :chef_server_url do |url|
|
51
|
+
configure do |c|
|
52
|
+
[ :registration_url,
|
53
|
+
:openid_url,
|
54
|
+
:template_url,
|
55
|
+
:remotefile_url,
|
56
|
+
:search_url,
|
57
|
+
:role_url ].each do |u|
|
58
|
+
c[u] = url
|
59
|
+
end
|
60
|
+
end
|
61
|
+
url
|
62
|
+
end
|
63
|
+
|
64
|
+
# Override the config dispatch to set the value of log_location configuration option
|
65
|
+
#
|
66
|
+
# === Parameters
|
67
|
+
# location<IO||String>:: Logging location as either an IO stream or string representing log file path
|
68
|
+
#
|
69
|
+
config_attr_writer :log_location do |location|
|
70
|
+
if location.respond_to? :sync=
|
71
|
+
location
|
72
|
+
elsif location.respond_to? :to_str
|
73
|
+
File.new(location.to_str, "a")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Override the config dispatch to set the value of authorized_openid_providers when openid_providers (deprecated) is used
|
78
|
+
#
|
79
|
+
# === Parameters
|
80
|
+
# providers<Array>:: An array of openid providers that are authorized to login to the chef server
|
81
|
+
#
|
82
|
+
config_attr_writer :openid_providers do |providers|
|
83
|
+
configure { |c| c[:authorized_openid_providers] = providers }
|
84
|
+
providers
|
85
|
+
end
|
86
|
+
|
87
|
+
authorized_openid_identifiers nil
|
88
|
+
authorized_openid_providers nil
|
89
|
+
chef_server_url nil
|
90
|
+
cookbook_path [ "/var/chef/site-cookbooks", "/var/chef/cookbooks" ]
|
91
|
+
couchdb_database "chef"
|
92
|
+
couchdb_url "http://localhost:5984"
|
93
|
+
couchdb_version nil
|
94
|
+
daemonize nil
|
95
|
+
delay 0
|
96
|
+
executable_path ENV['PATH'] ? ENV['PATH'].split(File::PATH_SEPARATOR) : []
|
97
|
+
file_cache_path "/var/chef/cache"
|
98
|
+
file_store_path "/var/chef/store"
|
99
|
+
group nil
|
100
|
+
http_retry_count 5
|
101
|
+
http_retry_delay 5
|
102
|
+
interval nil
|
103
|
+
json_attribs nil
|
104
|
+
log_level :info
|
105
|
+
log_location STDOUT
|
106
|
+
node_name nil
|
107
|
+
node_path "/var/chef/node"
|
108
|
+
openid_cstore_couchdb false
|
109
|
+
openid_cstore_path "/var/chef/openid/cstore"
|
110
|
+
openid_providers nil
|
111
|
+
openid_store_couchdb false
|
112
|
+
openid_store_path "/var/chef/openid/db"
|
113
|
+
openid_url "http://localhost:4001"
|
114
|
+
pid_file nil
|
115
|
+
queue_host "localhost"
|
116
|
+
queue_password ""
|
117
|
+
queue_port 61613
|
118
|
+
queue_retry_count 5
|
119
|
+
queue_retry_delay 5
|
120
|
+
queue_user ""
|
121
|
+
queue_prefix nil
|
122
|
+
registration_url "http://localhost:4000"
|
123
|
+
remotefile_url "http://localhost:4000"
|
124
|
+
rest_timeout 60
|
125
|
+
run_command_stderr_timeout 120
|
126
|
+
run_command_stdout_timeout 120
|
127
|
+
search_index_path "/var/chef/search_index"
|
128
|
+
search_url "http://localhost:4000"
|
129
|
+
solo false
|
130
|
+
splay nil
|
131
|
+
ssl_client_cert ""
|
132
|
+
ssl_client_key ""
|
133
|
+
ssl_verify_mode :verify_none
|
134
|
+
template_url "http://localhost:4000"
|
135
|
+
user nil
|
136
|
+
validation_token nil
|
137
|
+
role_path "/var/chef/roles"
|
138
|
+
role_url "http://localhost:4000"
|
139
|
+
recipe_url nil
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
+
# Author:: Christopher Walters (<cw@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require 'chef/log'
|
20
|
+
require 'chef/node'
|
21
|
+
require 'chef/resource_definition'
|
22
|
+
require 'chef/recipe'
|
23
|
+
require 'chef/mixin/convert_to_class_name'
|
24
|
+
|
25
|
+
class Chef
|
26
|
+
class Cookbook
|
27
|
+
include Chef::Mixin::ConvertToClassName
|
28
|
+
|
29
|
+
attr_accessor :attribute_files, :definition_files, :template_files, :remote_files,
|
30
|
+
:lib_files, :resource_files, :provider_files, :name
|
31
|
+
attr_reader :recipe_files
|
32
|
+
|
33
|
+
# Creates a new Chef::Cookbook object.
|
34
|
+
#
|
35
|
+
# === Returns
|
36
|
+
# object<Chef::Cookbook>:: Duh. :)
|
37
|
+
def initialize(name)
|
38
|
+
@name = name
|
39
|
+
@attribute_files = Array.new
|
40
|
+
@definition_files = Array.new
|
41
|
+
@template_files = Array.new
|
42
|
+
@remote_files = Array.new
|
43
|
+
@recipe_files = Array.new
|
44
|
+
@recipe_names = Hash.new
|
45
|
+
@lib_files = Array.new
|
46
|
+
@resource_files = Array.new
|
47
|
+
@provider_files = Array.new
|
48
|
+
end
|
49
|
+
|
50
|
+
# Loads all the library files in this cookbook via require.
|
51
|
+
#
|
52
|
+
# === Returns
|
53
|
+
# true:: Always returns true
|
54
|
+
def load_libraries
|
55
|
+
@lib_files.each do |file|
|
56
|
+
Chef::Log.debug("Loading cookbook #{name} library file: #{file}")
|
57
|
+
require file
|
58
|
+
end
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
# Loads all the attribute files in this cookbook within a particular <Chef::Node>.
|
63
|
+
#
|
64
|
+
# === Parameters
|
65
|
+
# node<Chef::Node>:: The Chef::Node to apply the attributes to
|
66
|
+
#
|
67
|
+
# === Returns
|
68
|
+
# node<Chef::Node>:: The updated Chef::Node object
|
69
|
+
#
|
70
|
+
# === Raises
|
71
|
+
# <ArgumentError>:: If the argument is not a kind_of? <Chef::Node>
|
72
|
+
def load_attributes(node)
|
73
|
+
unless node.kind_of?(Chef::Node)
|
74
|
+
raise ArgumentError, "You must pass a Chef::Node to load_attributes!"
|
75
|
+
end
|
76
|
+
@attribute_files.each do |file|
|
77
|
+
Chef::Log.debug("Loading attributes from #{file}")
|
78
|
+
node.from_file(file)
|
79
|
+
end
|
80
|
+
node
|
81
|
+
end
|
82
|
+
|
83
|
+
# Loads all the resource definitions in this cookbook.
|
84
|
+
#
|
85
|
+
# === Returns
|
86
|
+
# definitions<Hash>: A hash of <Chef::ResourceDefinition> objects, keyed by name.
|
87
|
+
def load_definitions
|
88
|
+
results = Hash.new
|
89
|
+
@definition_files.each do |file|
|
90
|
+
Chef::Log.debug("Loading cookbook #{name}'s definitions from #{file}")
|
91
|
+
resourcedef = Chef::ResourceDefinition.new
|
92
|
+
resourcedef.from_file(file)
|
93
|
+
results[resourcedef.name] = resourcedef
|
94
|
+
end
|
95
|
+
results
|
96
|
+
end
|
97
|
+
|
98
|
+
# Loads all the resources in this cookbook.
|
99
|
+
#
|
100
|
+
# === Returns
|
101
|
+
# true:: Always returns true
|
102
|
+
def load_resources
|
103
|
+
@resource_files.each do |file|
|
104
|
+
Chef::Log.debug("Loading cookbook #{name}'s resources from #{file}")
|
105
|
+
Chef::Resource.build_from_file(name, file)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Loads all the providers in this cookbook.
|
110
|
+
#
|
111
|
+
# === Returns
|
112
|
+
# true:: Always returns true
|
113
|
+
def load_providers
|
114
|
+
@provider_files.each do |file|
|
115
|
+
Chef::Log.debug("Loading cookbook #{name}'s providers from #{file}")
|
116
|
+
Chef::Provider.build_from_file(name, file)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def recipe_files=(*args)
|
121
|
+
@recipe_files = args.flatten
|
122
|
+
@recipe_files.each_index do |i|
|
123
|
+
file = @recipe_files[i]
|
124
|
+
case file
|
125
|
+
when /(.+\/)(.+).rb$/
|
126
|
+
@recipe_names[$2] = i
|
127
|
+
when /(.+).rb$/
|
128
|
+
@recipe_names[$1] = i
|
129
|
+
else
|
130
|
+
@recipe_names[file] = i
|
131
|
+
end
|
132
|
+
end
|
133
|
+
@recipe_files
|
134
|
+
end
|
135
|
+
|
136
|
+
def recipe?(name)
|
137
|
+
lookup_name = name
|
138
|
+
if name =~ /(.+)::(.+)/
|
139
|
+
cookbook_name = $1
|
140
|
+
lookup_name = $2
|
141
|
+
return false unless cookbook_name == @name
|
142
|
+
end
|
143
|
+
@recipe_names.has_key?(lookup_name)
|
144
|
+
end
|
145
|
+
|
146
|
+
def recipes
|
147
|
+
results = Array.new
|
148
|
+
@recipe_names.each_key do |rname|
|
149
|
+
results << "#{@name}::#{rname}"
|
150
|
+
end
|
151
|
+
results
|
152
|
+
end
|
153
|
+
|
154
|
+
def load_recipe(name, node, collection=nil, definitions=nil, cookbook_loader=nil)
|
155
|
+
cookbook_name = @name
|
156
|
+
recipe_name = nil
|
157
|
+
nmatch = name.match(/^(.+?)::(.+)$/)
|
158
|
+
recipe_name = nmatch ? nmatch[2] : name
|
159
|
+
|
160
|
+
unless @recipe_names.has_key?(recipe_name)
|
161
|
+
raise ArgumentError, "Cannot find a recipe matching #{recipe_name} in cookbook #{@name}"
|
162
|
+
end
|
163
|
+
Chef::Log.debug("Found recipe #{recipe_name} in cookbook #{cookbook_name}") if Chef::Log.debug?
|
164
|
+
recipe = Chef::Recipe.new(cookbook_name, recipe_name, node,
|
165
|
+
collection, definitions, cookbook_loader)
|
166
|
+
recipe.from_file(@recipe_files[@recipe_names[recipe_name]])
|
167
|
+
recipe
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
end
|