microwave 0.1004.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +201 -0
- data/README.rdoc +102 -0
- data/bin/chef-solo +25 -0
- data/lib/chef.rb +41 -0
- data/lib/chef/application.rb +147 -0
- data/lib/chef/application/solo.rb +181 -0
- data/lib/chef/applications.rb +1 -0
- data/lib/chef/checksum.rb +83 -0
- data/lib/chef/checksum_cache.rb +189 -0
- data/lib/chef/client.rb +325 -0
- data/lib/chef/config.rb +152 -0
- data/lib/chef/cookbook/chefignore.rb +66 -0
- data/lib/chef/cookbook/cookbook_collection.rb +45 -0
- data/lib/chef/cookbook/cookbook_version_loader.rb +173 -0
- data/lib/chef/cookbook/file_system_file_vendor.rb +56 -0
- data/lib/chef/cookbook/file_vendor.rb +48 -0
- data/lib/chef/cookbook/metadata.rb +629 -0
- data/lib/chef/cookbook/syntax_check.rb +136 -0
- data/lib/chef/cookbook_loader.rb +121 -0
- data/lib/chef/cookbook_version.rb +786 -0
- data/lib/chef/cookbook_version_selector.rb +151 -0
- data/lib/chef/environment.rb +267 -0
- data/lib/chef/exceptions.rb +150 -0
- data/lib/chef/file_access_control.rb +144 -0
- data/lib/chef/file_cache.rb +218 -0
- data/lib/chef/handler.rb +206 -0
- data/lib/chef/handler/error_report.rb +33 -0
- data/lib/chef/handler/json_file.rb +58 -0
- data/lib/chef/json_compat.rb +52 -0
- data/lib/chef/log.rb +39 -0
- data/lib/chef/mash.rb +211 -0
- data/lib/chef/mixin/check_helper.rb +31 -0
- data/lib/chef/mixin/checksum.rb +32 -0
- data/lib/chef/mixin/command.rb +221 -0
- data/lib/chef/mixin/command/unix.rb +215 -0
- data/lib/chef/mixin/command/windows.rb +76 -0
- data/lib/chef/mixin/convert_to_class_name.rb +63 -0
- data/lib/chef/mixin/create_path.rb +57 -0
- data/lib/chef/mixin/deep_merge.rb +225 -0
- data/lib/chef/mixin/deprecation.rb +65 -0
- data/lib/chef/mixin/from_file.rb +50 -0
- data/lib/chef/mixin/get_source_from_package.rb +42 -0
- data/lib/chef/mixin/language.rb +125 -0
- data/lib/chef/mixin/language_include_attribute.rb +61 -0
- data/lib/chef/mixin/language_include_recipe.rb +52 -0
- data/lib/chef/mixin/params_validate.rb +225 -0
- data/lib/chef/mixin/recipe_definition_dsl_core.rb +78 -0
- data/lib/chef/mixin/shell_out.rb +41 -0
- data/lib/chef/mixin/template.rb +95 -0
- data/lib/chef/mixin/xml_escape.rb +140 -0
- data/lib/chef/mixins.rb +15 -0
- data/lib/chef/monkey_patches/dir.rb +36 -0
- data/lib/chef/monkey_patches/numeric.rb +15 -0
- data/lib/chef/monkey_patches/object.rb +9 -0
- data/lib/chef/monkey_patches/regexp.rb +34 -0
- data/lib/chef/monkey_patches/string.rb +49 -0
- data/lib/chef/monkey_patches/tempfile.rb +64 -0
- data/lib/chef/nil_argument.rb +3 -0
- data/lib/chef/node.rb +469 -0
- data/lib/chef/node/attribute.rb +487 -0
- data/lib/chef/platform.rb +409 -0
- data/lib/chef/provider.rb +124 -0
- data/lib/chef/provider/breakpoint.rb +31 -0
- data/lib/chef/provider/cookbook_file.rb +100 -0
- data/lib/chef/provider/cron.rb +186 -0
- data/lib/chef/provider/cron/solaris.rb +195 -0
- data/lib/chef/provider/deploy.rb +343 -0
- data/lib/chef/provider/deploy/revision.rb +80 -0
- data/lib/chef/provider/deploy/timestamped.rb +33 -0
- data/lib/chef/provider/directory.rb +72 -0
- data/lib/chef/provider/env.rb +152 -0
- data/lib/chef/provider/env/windows.rb +75 -0
- data/lib/chef/provider/erl_call.rb +101 -0
- data/lib/chef/provider/execute.rb +66 -0
- data/lib/chef/provider/file.rb +222 -0
- data/lib/chef/provider/git.rb +243 -0
- data/lib/chef/provider/group.rb +133 -0
- data/lib/chef/provider/group/aix.rb +70 -0
- data/lib/chef/provider/group/dscl.rb +121 -0
- data/lib/chef/provider/group/gpasswd.rb +53 -0
- data/lib/chef/provider/group/groupadd.rb +81 -0
- data/lib/chef/provider/group/pw.rb +84 -0
- data/lib/chef/provider/group/suse.rb +53 -0
- data/lib/chef/provider/group/usermod.rb +57 -0
- data/lib/chef/provider/group/windows.rb +79 -0
- data/lib/chef/provider/ifconfig.rb +134 -0
- data/lib/chef/provider/link.rb +164 -0
- data/lib/chef/provider/log.rb +54 -0
- data/lib/chef/provider/mdadm.rb +91 -0
- data/lib/chef/provider/mount.rb +114 -0
- data/lib/chef/provider/mount/mount.rb +240 -0
- data/lib/chef/provider/mount/windows.rb +81 -0
- data/lib/chef/provider/ohai.rb +42 -0
- data/lib/chef/provider/package.rb +163 -0
- data/lib/chef/provider/package/apt.rb +135 -0
- data/lib/chef/provider/package/dpkg.rb +115 -0
- data/lib/chef/provider/package/easy_install.rb +136 -0
- data/lib/chef/provider/package/freebsd.rb +125 -0
- data/lib/chef/provider/package/macports.rb +105 -0
- data/lib/chef/provider/package/pacman.rb +101 -0
- data/lib/chef/provider/package/portage.rb +135 -0
- data/lib/chef/provider/package/rpm.rb +104 -0
- data/lib/chef/provider/package/rubygems.rb +465 -0
- data/lib/chef/provider/package/solaris.rb +130 -0
- data/lib/chef/provider/package/yum-dump.py +286 -0
- data/lib/chef/provider/package/yum.rb +1128 -0
- data/lib/chef/provider/package/zypper.rb +144 -0
- data/lib/chef/provider/remote_directory.rb +137 -0
- data/lib/chef/provider/route.rb +193 -0
- data/lib/chef/provider/ruby_block.rb +34 -0
- data/lib/chef/provider/script.rb +55 -0
- data/lib/chef/provider/service.rb +122 -0
- data/lib/chef/provider/service/arch.rb +116 -0
- data/lib/chef/provider/service/debian.rb +130 -0
- data/lib/chef/provider/service/freebsd.rb +154 -0
- data/lib/chef/provider/service/gentoo.rb +53 -0
- data/lib/chef/provider/service/init.rb +71 -0
- data/lib/chef/provider/service/insserv.rb +52 -0
- data/lib/chef/provider/service/redhat.rb +60 -0
- data/lib/chef/provider/service/simple.rb +120 -0
- data/lib/chef/provider/service/solaris.rb +85 -0
- data/lib/chef/provider/service/systemd.rb +102 -0
- data/lib/chef/provider/service/upstart.rb +198 -0
- data/lib/chef/provider/service/windows.rb +146 -0
- data/lib/chef/provider/subversion.rb +197 -0
- data/lib/chef/provider/template.rb +104 -0
- data/lib/chef/provider/user.rb +186 -0
- data/lib/chef/provider/user/dscl.rb +280 -0
- data/lib/chef/provider/user/pw.rb +113 -0
- data/lib/chef/provider/user/useradd.rb +137 -0
- data/lib/chef/provider/user/windows.rb +124 -0
- data/lib/chef/providers.rb +93 -0
- data/lib/chef/recipe.rb +129 -0
- data/lib/chef/resource.rb +584 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/breakpoint.rb +35 -0
- data/lib/chef/resource/cookbook_file.rb +45 -0
- data/lib/chef/resource/cron.rb +188 -0
- data/lib/chef/resource/csh.rb +33 -0
- data/lib/chef/resource/deploy.rb +380 -0
- data/lib/chef/resource/deploy_revision.rb +40 -0
- data/lib/chef/resource/directory.rb +89 -0
- data/lib/chef/resource/dpkg_package.rb +34 -0
- data/lib/chef/resource/easy_install_package.rb +57 -0
- data/lib/chef/resource/env.rb +58 -0
- data/lib/chef/resource/erl_call.rb +83 -0
- data/lib/chef/resource/execute.rb +127 -0
- data/lib/chef/resource/file.rb +112 -0
- data/lib/chef/resource/freebsd_package.rb +35 -0
- data/lib/chef/resource/gem_package.rb +53 -0
- data/lib/chef/resource/git.rb +46 -0
- data/lib/chef/resource/group.rb +70 -0
- data/lib/chef/resource/ifconfig.rb +134 -0
- data/lib/chef/resource/link.rb +105 -0
- data/lib/chef/resource/log.rb +62 -0
- data/lib/chef/resource/macports_package.rb +29 -0
- data/lib/chef/resource/mdadm.rb +82 -0
- data/lib/chef/resource/mount.rb +134 -0
- data/lib/chef/resource/ohai.rb +40 -0
- data/lib/chef/resource/package.rb +80 -0
- data/lib/chef/resource/pacman_package.rb +33 -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 +109 -0
- data/lib/chef/resource/route.rb +135 -0
- data/lib/chef/resource/rpm_package.rb +34 -0
- data/lib/chef/resource/ruby.rb +33 -0
- data/lib/chef/resource/ruby_block.rb +40 -0
- data/lib/chef/resource/scm.rb +147 -0
- data/lib/chef/resource/script.rb +60 -0
- data/lib/chef/resource/service.rb +160 -0
- data/lib/chef/resource/solaris_package.rb +36 -0
- data/lib/chef/resource/subversion.rb +36 -0
- data/lib/chef/resource/template.rb +69 -0
- data/lib/chef/resource/timestamped_deploy.rb +31 -0
- data/lib/chef/resource/user.rb +130 -0
- data/lib/chef/resource/yum_package.rb +63 -0
- data/lib/chef/resource_collection.rb +217 -0
- data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
- data/lib/chef/resource_definition.rb +67 -0
- data/lib/chef/resource_definition_list.rb +38 -0
- data/lib/chef/resources.rb +62 -0
- data/lib/chef/role.rb +225 -0
- data/lib/chef/run_context.rb +126 -0
- data/lib/chef/run_list.rb +161 -0
- data/lib/chef/run_list/run_list_expansion.rb +159 -0
- data/lib/chef/run_list/run_list_item.rb +92 -0
- data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
- data/lib/chef/run_status.rb +121 -0
- data/lib/chef/runner.rb +105 -0
- data/lib/chef/shell_out.rb +250 -0
- data/lib/chef/shell_out/unix.rb +223 -0
- data/lib/chef/shell_out/windows.rb +98 -0
- data/lib/chef/tasks/chef_repo.rake +330 -0
- data/lib/chef/util/file_edit.rb +122 -0
- data/lib/chef/util/windows.rb +56 -0
- data/lib/chef/util/windows/net_group.rb +101 -0
- data/lib/chef/util/windows/net_use.rb +121 -0
- data/lib/chef/util/windows/net_user.rb +198 -0
- data/lib/chef/util/windows/volume.rb +59 -0
- data/lib/chef/version.rb +23 -0
- data/lib/chef/version_class.rb +70 -0
- data/lib/chef/version_constraint.rb +116 -0
- metadata +493 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: AJ Christensen (<aj@opscode.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
|
+
require 'chef'
|
|
19
|
+
require 'chef/application'
|
|
20
|
+
require 'chef/client'
|
|
21
|
+
require 'chef/config'
|
|
22
|
+
require 'chef/log'
|
|
23
|
+
require 'open-uri'
|
|
24
|
+
require 'fileutils'
|
|
25
|
+
|
|
26
|
+
class Chef::Application::Solo < Chef::Application
|
|
27
|
+
|
|
28
|
+
option :config_file,
|
|
29
|
+
:short => "-c CONFIG",
|
|
30
|
+
:long => "--config CONFIG",
|
|
31
|
+
:default => "/etc/chef/solo.rb",
|
|
32
|
+
:description => "The configuration file to use"
|
|
33
|
+
|
|
34
|
+
option :log_level,
|
|
35
|
+
:short => "-l LEVEL",
|
|
36
|
+
:long => "--log_level LEVEL",
|
|
37
|
+
:description => "Set the log level (debug, info, warn, error, fatal)",
|
|
38
|
+
:proc => lambda { |l| l.to_sym }
|
|
39
|
+
|
|
40
|
+
option :log_location,
|
|
41
|
+
:short => "-L LOGLOCATION",
|
|
42
|
+
:long => "--logfile LOGLOCATION",
|
|
43
|
+
:description => "Set the log file location, defaults to STDOUT",
|
|
44
|
+
:proc => nil
|
|
45
|
+
|
|
46
|
+
option :help,
|
|
47
|
+
:short => "-h",
|
|
48
|
+
:long => "--help",
|
|
49
|
+
:description => "Show this message",
|
|
50
|
+
:on => :tail,
|
|
51
|
+
:boolean => true,
|
|
52
|
+
:show_options => true,
|
|
53
|
+
:exit => 0
|
|
54
|
+
|
|
55
|
+
option :user,
|
|
56
|
+
:short => "-u USER",
|
|
57
|
+
:long => "--user USER",
|
|
58
|
+
:description => "User to set privilege to",
|
|
59
|
+
:proc => nil
|
|
60
|
+
|
|
61
|
+
option :group,
|
|
62
|
+
:short => "-g GROUP",
|
|
63
|
+
:long => "--group GROUP",
|
|
64
|
+
:description => "Group to set privilege to",
|
|
65
|
+
:proc => nil
|
|
66
|
+
|
|
67
|
+
option :json_attribs,
|
|
68
|
+
:short => "-j JSON_ATTRIBS",
|
|
69
|
+
:long => "--json-attributes JSON_ATTRIBS",
|
|
70
|
+
:description => "Load attributes from a JSON file or URL",
|
|
71
|
+
:proc => nil
|
|
72
|
+
|
|
73
|
+
option :node_name,
|
|
74
|
+
:short => "-N NODE_NAME",
|
|
75
|
+
:long => "--node-name NODE_NAME",
|
|
76
|
+
:description => "The node name for this client",
|
|
77
|
+
:proc => nil
|
|
78
|
+
|
|
79
|
+
option :splay,
|
|
80
|
+
:short => "-s SECONDS",
|
|
81
|
+
:long => "--splay SECONDS",
|
|
82
|
+
:description => "The splay time for running at intervals, in seconds",
|
|
83
|
+
:proc => lambda { |s| s.to_i }
|
|
84
|
+
|
|
85
|
+
option :recipe_url,
|
|
86
|
+
:short => "-r RECIPE_URL",
|
|
87
|
+
:long => "--recipe-url RECIPE_URL",
|
|
88
|
+
:description => "Pull down a remote gzipped tarball of recipes and untar it to the cookbook cache.",
|
|
89
|
+
:proc => nil
|
|
90
|
+
|
|
91
|
+
option :version,
|
|
92
|
+
:short => "-v",
|
|
93
|
+
:long => "--version",
|
|
94
|
+
:description => "Show chef version",
|
|
95
|
+
:boolean => true,
|
|
96
|
+
:proc => lambda {|v| puts "Chef: #{::Chef::VERSION}"},
|
|
97
|
+
:exit => 0
|
|
98
|
+
|
|
99
|
+
option :testrun,
|
|
100
|
+
:short => "-n",
|
|
101
|
+
:long => "--testrun",
|
|
102
|
+
:description => "Run chef in testrun mode",
|
|
103
|
+
:boolean => true,
|
|
104
|
+
:proc => lambda {|n| $testrun = true }
|
|
105
|
+
|
|
106
|
+
attr_reader :chef_solo_json
|
|
107
|
+
|
|
108
|
+
def initialize
|
|
109
|
+
super
|
|
110
|
+
@chef_solo = nil
|
|
111
|
+
@chef_solo_json = nil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def reconfigure
|
|
115
|
+
super
|
|
116
|
+
|
|
117
|
+
if Chef::Config[:json_attribs]
|
|
118
|
+
begin
|
|
119
|
+
json_io = open(Chef::Config[:json_attribs])
|
|
120
|
+
rescue SocketError => error
|
|
121
|
+
Chef::Application.fatal!("I cannot connect to #{Chef::Config[:json_attribs]}", 2)
|
|
122
|
+
rescue Errno::ENOENT => error
|
|
123
|
+
Chef::Application.fatal!("I cannot find #{Chef::Config[:json_attribs]}", 2)
|
|
124
|
+
rescue Errno::EACCES => error
|
|
125
|
+
Chef::Application.fatal!("Permissions are incorrect on #{Chef::Config[:json_attribs]}. Please chmod a+r #{Chef::Config[:json_attribs]}", 2)
|
|
126
|
+
rescue Exception => error
|
|
127
|
+
Chef::Application.fatal!("Got an unexpected error reading #{Chef::Config[:json_attribs]}: #{error.message}", 2)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
begin
|
|
131
|
+
@chef_solo_json = Chef::JSONCompat.from_json(json_io.read)
|
|
132
|
+
json_io.close unless json_io.closed?
|
|
133
|
+
rescue JSON::ParserError => error
|
|
134
|
+
Chef::Application.fatal!("Could not parse the provided JSON file (#{Chef::Config[:json_attribs]})!: " + error.message, 2)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
if Chef::Config[:recipe_url]
|
|
139
|
+
cookbooks_path = Array(Chef::Config[:cookbook_path]).detect{|e| e =~ /\/cookbooks\/*$/ }
|
|
140
|
+
recipes_path = File.expand_path(File.join(cookbooks_path, '..'))
|
|
141
|
+
target_file = File.join(recipes_path, 'recipes.tgz')
|
|
142
|
+
|
|
143
|
+
Chef::Log.debug "Creating path #{recipes_path} to extract recipes into"
|
|
144
|
+
FileUtils.mkdir_p recipes_path
|
|
145
|
+
path = File.join(recipes_path, 'recipes.tgz')
|
|
146
|
+
File.open(path, 'wb') do |f|
|
|
147
|
+
open(Chef::Config[:recipe_url]) do |r|
|
|
148
|
+
f.write(r.read)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
Chef::Mixin::Command.run_command(:command => "tar zxvfC #{path} #{recipes_path}")
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def setup_application
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def run_application
|
|
159
|
+
loop do
|
|
160
|
+
begin
|
|
161
|
+
if Chef::Config[:splay]
|
|
162
|
+
splay = rand Chef::Config[:splay]
|
|
163
|
+
Chef::Log.debug("Splay sleep #{splay} seconds")
|
|
164
|
+
sleep splay
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
@chef_solo = Chef::Client.new(@chef_solo_json)
|
|
168
|
+
@chef_solo.run
|
|
169
|
+
@chef_solo = nil
|
|
170
|
+
Chef::Application.exit! "Exiting", 0
|
|
171
|
+
rescue SystemExit => e
|
|
172
|
+
raise
|
|
173
|
+
rescue Exception => e
|
|
174
|
+
Chef::Application.debug_stacktrace(e)
|
|
175
|
+
Chef::Application.fatal!("#{e.class}: #{e.message}", 1)
|
|
176
|
+
ensure
|
|
177
|
+
GC.start
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'chef/application/solo'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Tim Hinderliter (<tim@opscode.com>)
|
|
3
|
+
# Copyright:: Copyright (c) 2010 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
|
+
require 'chef/log'
|
|
19
|
+
require 'uuidtools'
|
|
20
|
+
|
|
21
|
+
class Chef
|
|
22
|
+
# == Chef::Checksum
|
|
23
|
+
# Checksum for an individual file; e.g., used for sandbox/cookbook uploading
|
|
24
|
+
# to track which files the system already manages.
|
|
25
|
+
class Checksum
|
|
26
|
+
attr_accessor :checksum, :create_time
|
|
27
|
+
|
|
28
|
+
# Creates a new Chef::Checksum object.
|
|
29
|
+
# === Arguments
|
|
30
|
+
# checksum::: the MD5 content hash of the file
|
|
31
|
+
#
|
|
32
|
+
# === Returns
|
|
33
|
+
# object<Chef::Checksum>:: Duh. :)
|
|
34
|
+
def initialize(checksum=nil)
|
|
35
|
+
@create_time = Time.now.iso8601
|
|
36
|
+
@checksum = checksum
|
|
37
|
+
@original_committed_file_location = nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_json(*a)
|
|
41
|
+
result = {
|
|
42
|
+
:checksum => checksum,
|
|
43
|
+
:create_time => create_time,
|
|
44
|
+
:json_class => self.class.name,
|
|
45
|
+
:chef_type => 'checksum',
|
|
46
|
+
:name => checksum
|
|
47
|
+
}
|
|
48
|
+
result.to_json(*a)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def self.json_create(o)
|
|
52
|
+
checksum = new(o['checksum'])
|
|
53
|
+
checksum.create_time = o['create_time']
|
|
54
|
+
|
|
55
|
+
checksum
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
##
|
|
60
|
+
# On-Disk Checksum File Repo (Chef Server API)
|
|
61
|
+
##
|
|
62
|
+
|
|
63
|
+
def file_location
|
|
64
|
+
File.join(checksum_repo_directory, checksum)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def checksum_repo_directory
|
|
68
|
+
File.join(Chef::Config.checksum_path, checksum[0..1])
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
# Deletes the file backing this checksum from the on-disk repo.
|
|
74
|
+
# Purging the checksums is how users can get back to a valid state if
|
|
75
|
+
# they've deleted files, so we silently swallow Errno::ENOENT here.
|
|
76
|
+
def purge_file
|
|
77
|
+
FileUtils.rm(file_location)
|
|
78
|
+
rescue Errno::ENOENT
|
|
79
|
+
true
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Author:: Adam Jacob (<adam@opscode.com>)
|
|
3
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
|
4
|
+
# Copyright:: Copyright (c) 2009 Opscode, Inc.
|
|
5
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
|
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
|
+
|
|
21
|
+
require 'set'
|
|
22
|
+
require 'fileutils'
|
|
23
|
+
require 'chef/log'
|
|
24
|
+
require 'chef/config'
|
|
25
|
+
require 'chef/client'
|
|
26
|
+
require 'chef/mixin/convert_to_class_name'
|
|
27
|
+
require 'singleton'
|
|
28
|
+
require 'moneta'
|
|
29
|
+
|
|
30
|
+
class Chef
|
|
31
|
+
class ChecksumCache
|
|
32
|
+
include Chef::Mixin::ConvertToClassName
|
|
33
|
+
include ::Singleton
|
|
34
|
+
|
|
35
|
+
attr_reader :moneta
|
|
36
|
+
|
|
37
|
+
def initialize(*args)
|
|
38
|
+
self.reset!(*args)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def reset!(backend=nil, options=nil)
|
|
42
|
+
backend ||= Chef::Config[:cache_type]
|
|
43
|
+
options ||= Chef::Config[:cache_options]
|
|
44
|
+
|
|
45
|
+
begin
|
|
46
|
+
require "moneta/#{convert_to_snake_case(backend, 'Moneta')}"
|
|
47
|
+
rescue LoadError => e
|
|
48
|
+
Chef::Log.fatal("Could not load Moneta back end #{backend.inspect}")
|
|
49
|
+
raise e
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@moneta = Moneta.const_get(backend).new(options)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.reset_cache_validity
|
|
56
|
+
@valid_cached_checksums = nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
Chef::Client.when_run_starts do |run_status|
|
|
60
|
+
reset_cache_validity
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.valid_cached_checksums
|
|
64
|
+
@valid_cached_checksums ||= Set.new
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def self.validate_checksum(checksum_key)
|
|
68
|
+
valid_cached_checksums << checksum_key
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.all_cached_checksums
|
|
72
|
+
all_checksums_with_filenames = {}
|
|
73
|
+
|
|
74
|
+
Dir[File.join(Chef::Config[:cache_options][:path], '*')].each do |cksum_file|
|
|
75
|
+
all_checksums_with_filenames[File.basename(cksum_file)] = cksum_file
|
|
76
|
+
end
|
|
77
|
+
all_checksums_with_filenames
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def self.cleanup_checksum_cache
|
|
81
|
+
Chef::Log.debug("Cleaning the checksum cache")
|
|
82
|
+
if (Chef::Config[:cache_type].to_s == "BasicFile")
|
|
83
|
+
all_cached_checksums.each do |cache_key, cksum_cache_file|
|
|
84
|
+
unless valid_cached_checksums.include?(cache_key)
|
|
85
|
+
remove_unused_checksum(cksum_cache_file)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
Chef::Client.when_run_completes_successfully do |run_status|
|
|
92
|
+
cleanup_checksum_cache
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.remove_unused_checksum(checksum_file)
|
|
96
|
+
Chef::Log.debug("Removing unused checksum cache file #{checksum_file}")
|
|
97
|
+
FileUtils.rm(checksum_file)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def self.checksum_for_file(*args)
|
|
101
|
+
instance.checksum_for_file(*args)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def validate_checksum(*args)
|
|
105
|
+
self.class.validate_checksum(*args)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def checksum_for_file(file, key=nil)
|
|
109
|
+
key ||= generate_key(file)
|
|
110
|
+
fstat = File.stat(file)
|
|
111
|
+
lookup_checksum(key, fstat) || generate_checksum(key, file, fstat)
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def lookup_checksum(key, fstat)
|
|
115
|
+
cached = fetch(key)
|
|
116
|
+
if cached && file_unchanged?(cached, fstat)
|
|
117
|
+
validate_checksum(key)
|
|
118
|
+
cached["checksum"]
|
|
119
|
+
else
|
|
120
|
+
nil
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def generate_checksum(key, file, fstat)
|
|
125
|
+
checksum = checksum_file(file, Digest::SHA256.new)
|
|
126
|
+
moneta.store(key, {"mtime" => fstat.mtime.to_f, "checksum" => checksum})
|
|
127
|
+
validate_checksum(key)
|
|
128
|
+
checksum
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def generate_key(file, group="chef")
|
|
132
|
+
"#{group}-file-#{file.gsub(/(#{File::SEPARATOR}|\.)/, '-')}"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def self.generate_md5_checksum_for_file(*args)
|
|
136
|
+
instance.generate_md5_checksum_for_file(*args)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def generate_md5_checksum_for_file(file)
|
|
140
|
+
checksum_file(file, Digest::MD5.new)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def generate_md5_checksum(io)
|
|
144
|
+
checksum_io(io, Digest::MD5.new)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
def fetch(key)
|
|
150
|
+
@moneta.fetch(key)
|
|
151
|
+
rescue ArgumentError => e
|
|
152
|
+
Log.warn "Error loading cached checksum for key #{key.inspect}"
|
|
153
|
+
Log.warn(e)
|
|
154
|
+
repair_checksum_cache
|
|
155
|
+
nil
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def repair_checksum_cache
|
|
159
|
+
Chef::Log.info("Removing invalid checksum cache files")
|
|
160
|
+
Dir["#{Chef::Config[:cache_options][:path]}/*"].each do |file_path|
|
|
161
|
+
File.unlink(file_path) unless File.size?(file_path)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def file_unchanged?(cached, fstat)
|
|
166
|
+
cached["mtime"].to_f == fstat.mtime.to_f
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def checksum_file(file, digest)
|
|
170
|
+
File.open(file, 'rb') { |f| checksum_io(f, digest) }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def checksum_io(io, digest)
|
|
174
|
+
while chunk = io.read(1024 * 8)
|
|
175
|
+
digest.update(chunk)
|
|
176
|
+
end
|
|
177
|
+
digest.hexdigest
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
module Moneta
|
|
184
|
+
module Defaults
|
|
185
|
+
def default
|
|
186
|
+
nil
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|