chef 0.7.10
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/LICENSE +201 -0
- data/README.rdoc +135 -0
- data/bin/chef-client +26 -0
- data/bin/chef-solo +26 -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 +396 -0
- data/lib/chef/compile.rb +138 -0
- data/lib/chef/config.rb +141 -0
- data/lib/chef/cookbook.rb +144 -0
- data/lib/chef/cookbook/metadata.rb +407 -0
- data/lib/chef/cookbook/metadata/version.rb +87 -0
- data/lib/chef/cookbook_loader.rb +168 -0
- data/lib/chef/couchdb.rb +172 -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 +351 -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 +99 -0
- data/lib/chef/mixin/from_file.rb +36 -0
- data/lib/chef/mixin/generate_url.rb +48 -0
- data/lib/chef/mixin/language.rb +79 -0
- data/lib/chef/mixin/params_validate.rb +197 -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 +253 -0
- data/lib/chef/provider.rb +40 -0
- data/lib/chef/provider/cron.rb +137 -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/group.rb +120 -0
- data/lib/chef/provider/group/groupadd.rb +92 -0
- data/lib/chef/provider/group/pw.rb +88 -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 +121 -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 +113 -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 +130 -0
- data/lib/chef/provider/package/yum-dump.py +104 -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 +134 -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 +129 -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 +126 -0
- data/lib/chef/provider/service/redhat.rb +62 -0
- data/lib/chef/provider/template.rb +141 -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 +210 -0
- data/lib/chef/resource.rb +256 -0
- data/lib/chef/resource/apt_package.rb +34 -0
- data/lib/chef/resource/bash.rb +33 -0
- data/lib/chef/resource/cron.rb +143 -0
- data/lib/chef/resource/csh.rb +33 -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/group.rb +68 -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/script.rb +51 -0
- data/lib/chef/resource/service.rb +134 -0
- data/lib/chef/resource/template.rb +60 -0
- data/lib/chef/resource/user.rb +98 -0
- data/lib/chef/resource_collection.rb +176 -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 +123 -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 +345 -0
- data/lib/chef/util/file_edit.rb +125 -0
- data/lib/chef/util/fileedit.rb +121 -0
- metadata +262 -0
@@ -0,0 +1,175 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@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
|
+
|
19
|
+
require 'chef/provider/package'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/resource/package'
|
22
|
+
require 'singleton'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Provider
|
26
|
+
class Package
|
27
|
+
class Yum < Chef::Provider::Package
|
28
|
+
|
29
|
+
class YumCache
|
30
|
+
include Chef::Mixin::Command
|
31
|
+
include Singleton
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
load_data
|
35
|
+
end
|
36
|
+
|
37
|
+
def stale?
|
38
|
+
interval = Chef::Config[:interval].to_f
|
39
|
+
|
40
|
+
# run once mode
|
41
|
+
if interval == 0
|
42
|
+
return false
|
43
|
+
elsif (Time.now - @updated_at) > interval
|
44
|
+
return true
|
45
|
+
end
|
46
|
+
|
47
|
+
false
|
48
|
+
end
|
49
|
+
|
50
|
+
def refresh
|
51
|
+
if @data.empty?
|
52
|
+
reload
|
53
|
+
elsif stale?
|
54
|
+
reload
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def load_data
|
59
|
+
@data = Hash.new
|
60
|
+
error = String.new
|
61
|
+
|
62
|
+
helper = ::File.join(::File.dirname(__FILE__), 'yum-dump.py')
|
63
|
+
status = popen4("python #{helper}", :waitlast => true) do |pid, stdin, stdout, stderr|
|
64
|
+
stdout.each do |line|
|
65
|
+
line.chomp!
|
66
|
+
name, type, epoch, version, release, arch = line.split(',')
|
67
|
+
type_sym = type.to_sym
|
68
|
+
if !@data.has_key?(name)
|
69
|
+
@data[name] = Hash.new
|
70
|
+
end
|
71
|
+
@data[name][type_sym] = { :epoch => epoch, :version => version,
|
72
|
+
:release => release, :arch => arch }
|
73
|
+
end
|
74
|
+
|
75
|
+
error = stderr.readlines
|
76
|
+
end
|
77
|
+
|
78
|
+
unless status.exitstatus == 0
|
79
|
+
raise Chef::Exceptions::Package, "yum failed - #{status.inspect} - returns: #{error}"
|
80
|
+
end
|
81
|
+
|
82
|
+
@updated_at = Time.now
|
83
|
+
end
|
84
|
+
alias :reload :load_data
|
85
|
+
|
86
|
+
def version(package_name, type)
|
87
|
+
if (x = @data[package_name])
|
88
|
+
if (y = x[type])
|
89
|
+
return "#{y[:version]}-#{y[:release]}"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
nil
|
94
|
+
end
|
95
|
+
|
96
|
+
def installed_version(package_name)
|
97
|
+
version(package_name, :installed)
|
98
|
+
end
|
99
|
+
|
100
|
+
def candidate_version(package_name)
|
101
|
+
version(package_name, :available)
|
102
|
+
end
|
103
|
+
|
104
|
+
def flush
|
105
|
+
@data.clear
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def initialize(node, new_resource)
|
110
|
+
@yum = YumCache.instance
|
111
|
+
super(node, new_resource)
|
112
|
+
end
|
113
|
+
|
114
|
+
def load_current_resource
|
115
|
+
@current_resource = Chef::Resource::Package.new(@new_resource.name)
|
116
|
+
@current_resource.package_name(@new_resource.package_name)
|
117
|
+
|
118
|
+
Chef::Log.debug("Checking yum info for #{@new_resource.package_name}")
|
119
|
+
|
120
|
+
@yum.refresh
|
121
|
+
|
122
|
+
installed_version = @yum.installed_version(@new_resource.package_name)
|
123
|
+
@candidate_version = @yum.candidate_version(@new_resource.package_name)
|
124
|
+
|
125
|
+
@current_resource.version(installed_version)
|
126
|
+
if candidate_version
|
127
|
+
@candidate_version = candidate_version
|
128
|
+
else
|
129
|
+
@candidate_version = installed_version
|
130
|
+
end
|
131
|
+
|
132
|
+
@current_resource
|
133
|
+
end
|
134
|
+
|
135
|
+
def install_package(name, version)
|
136
|
+
run_command(
|
137
|
+
:command => "yum -q -y install #{name}-#{version}"
|
138
|
+
)
|
139
|
+
@yum.flush
|
140
|
+
end
|
141
|
+
|
142
|
+
def upgrade_package(name, version)
|
143
|
+
# If we have a version, we can upgrade - otherwise, install
|
144
|
+
if @current_resource.version
|
145
|
+
run_command(
|
146
|
+
:command => "yum -q -y update #{name}-#{version}"
|
147
|
+
)
|
148
|
+
@yum.flush
|
149
|
+
else
|
150
|
+
install_package(name, version)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def remove_package(name, version)
|
155
|
+
if version
|
156
|
+
run_command(
|
157
|
+
:command => "yum -q -y remove #{name}-#{version}"
|
158
|
+
)
|
159
|
+
else
|
160
|
+
run_command(
|
161
|
+
:command => "yum -q -y remove #{name}"
|
162
|
+
)
|
163
|
+
end
|
164
|
+
|
165
|
+
@yum.flush
|
166
|
+
end
|
167
|
+
|
168
|
+
def purge_package(name, version)
|
169
|
+
remove_package(name, version)
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@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
|
+
|
19
|
+
require 'chef/provider/file'
|
20
|
+
require 'chef/provider/directory'
|
21
|
+
require 'chef/rest'
|
22
|
+
require 'chef/mixin/find_preferred_file'
|
23
|
+
require 'chef/resource/directory'
|
24
|
+
require 'chef/resource/remote_file'
|
25
|
+
require 'chef/platform'
|
26
|
+
require 'uri'
|
27
|
+
require 'tempfile'
|
28
|
+
require 'net/https'
|
29
|
+
|
30
|
+
class Chef
|
31
|
+
class Provider
|
32
|
+
class RemoteDirectory < Chef::Provider::Directory
|
33
|
+
|
34
|
+
include ::Chef::Mixin::FindPreferredFile
|
35
|
+
|
36
|
+
def action_create
|
37
|
+
super
|
38
|
+
|
39
|
+
@remote_file_list = Hash.new
|
40
|
+
do_recursive
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def do_recursive
|
46
|
+
if Chef::Config[:solo]
|
47
|
+
Chef::Log.debug("Doing a local recursive directory copy for #{@new_resource}")
|
48
|
+
files_to_transfer = files_for_directory(@new_resource.source)
|
49
|
+
else
|
50
|
+
Chef::Log.debug("Doing a remote recursive directory transfer for #{@new_resource}")
|
51
|
+
r = Chef::REST.new(Chef::Config[:remotefile_url])
|
52
|
+
files_to_transfer = r.get_rest(generate_url(@new_resource.source, "files", { :recursive => "true" }))
|
53
|
+
end
|
54
|
+
|
55
|
+
files_to_transfer.each do |remote_file_source|
|
56
|
+
fetch_remote_file(remote_file_source)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def fetch_remote_file(remote_file_source)
|
61
|
+
full_path = ::File.join(@new_resource.path, remote_file_source)
|
62
|
+
full_dir = ::File.dirname(full_path)
|
63
|
+
|
64
|
+
if !::File.directory?(full_dir)
|
65
|
+
create_directory(full_dir)
|
66
|
+
end
|
67
|
+
|
68
|
+
remote_file = Chef::Resource::RemoteFile.new(full_path, nil, @node)
|
69
|
+
remote_file.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
|
70
|
+
remote_file.source(::File.join(@new_resource.source, remote_file_source))
|
71
|
+
remote_file.mode(@new_resource.files_mode) if @new_resource.files_mode
|
72
|
+
remote_file.group(@new_resource.files_group) if @new_resource.files_group
|
73
|
+
remote_file.owner(@new_resource.files_owner) if @new_resource.files_owner
|
74
|
+
remote_file.backup(@new_resource.files_backup) if @new_resource.files_backup
|
75
|
+
|
76
|
+
rf_provider = Chef::Platform.provider_for_node(@node, remote_file)
|
77
|
+
rf_provider.load_current_resource
|
78
|
+
rf_provider.action_create
|
79
|
+
@new_resource.updated = true if rf_provider.new_resource.updated
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_directory(full_dir)
|
83
|
+
new_dir = Chef::Resource::Directory.new(full_dir, nil, @node)
|
84
|
+
new_dir.cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
|
85
|
+
new_dir.mode(@new_resource.mode)
|
86
|
+
new_dir.group(@new_resource.group)
|
87
|
+
new_dir.owner(@new_resource.owner)
|
88
|
+
new_dir.recursive(true)
|
89
|
+
|
90
|
+
d_provider = Chef::Platform.provider_for_node(@node, new_dir)
|
91
|
+
d_provider.load_current_resource
|
92
|
+
d_provider.action_create
|
93
|
+
@new_resource.updated = true if d_provider.new_resource.updated
|
94
|
+
end
|
95
|
+
|
96
|
+
def action_create_if_missing
|
97
|
+
raise Chef::Exceptions::UnsupportedAction, "Remote Directories do not support create_if_missing."
|
98
|
+
end
|
99
|
+
# Pulled from chef-server-slice files controller
|
100
|
+
|
101
|
+
def files_for_directory(path)
|
102
|
+
directory = find_preferred_file(
|
103
|
+
@new_resource.cookbook_name,
|
104
|
+
:remote_file,
|
105
|
+
path,
|
106
|
+
@node[:fqdn],
|
107
|
+
@node[:platform],
|
108
|
+
@node[:platform_version]
|
109
|
+
)
|
110
|
+
|
111
|
+
unless (directory && ::File.directory?(directory))
|
112
|
+
raise NotFound, "Cannot find a suitable directory"
|
113
|
+
end
|
114
|
+
|
115
|
+
directory_listing = Array.new
|
116
|
+
Dir[::File.join(directory, '**', '*')].sort { |a,b| b <=> a }.each do |file|
|
117
|
+
next if ::File.directory?(file)
|
118
|
+
file =~ /^#{directory}\/(.+)$/
|
119
|
+
directory_listing << $1
|
120
|
+
end
|
121
|
+
directory_listing
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Adam Jacob (<adam@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
|
+
|
19
|
+
require 'chef/provider/file'
|
20
|
+
require 'chef/rest'
|
21
|
+
require 'chef/mixin/find_preferred_file'
|
22
|
+
require 'uri'
|
23
|
+
require 'tempfile'
|
24
|
+
require 'net/https'
|
25
|
+
|
26
|
+
class Chef
|
27
|
+
class Provider
|
28
|
+
class RemoteFile < Chef::Provider::File
|
29
|
+
|
30
|
+
include Chef::Mixin::FindPreferredFile
|
31
|
+
|
32
|
+
def action_create
|
33
|
+
Chef::Log.debug("Checking #{@new_resource} for changes")
|
34
|
+
do_remote_file(@new_resource.source, @current_resource.path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def action_create_if_missing
|
38
|
+
if ::File.exists?(@new_resource.path)
|
39
|
+
Chef::Log.debug("File #{@new_resource.path} exists, taking no action.")
|
40
|
+
else
|
41
|
+
action_create
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def do_remote_file(source, path)
|
46
|
+
retval = true
|
47
|
+
|
48
|
+
if(@new_resource.checksum && @current_resource.checksum && @current_resource.checksum =~ /^#{@new_resource.checksum}/)
|
49
|
+
Chef::Log.debug("File #{@new_resource} checksum matches, not updating")
|
50
|
+
else
|
51
|
+
begin
|
52
|
+
# The remote filehandle
|
53
|
+
raw_file = get_from_uri(source) ||
|
54
|
+
get_from_server(source, @current_resource.checksum) ||
|
55
|
+
get_from_local_cookbook(source)
|
56
|
+
|
57
|
+
# If the file exists
|
58
|
+
if ::File.exists?(@new_resource.path)
|
59
|
+
# And it matches the checksum of the raw file
|
60
|
+
@new_resource.checksum(self.checksum(raw_file.path))
|
61
|
+
if @new_resource.checksum != @current_resource.checksum
|
62
|
+
# Updating target file, let's perform a backup!
|
63
|
+
Chef::Log.debug("#{@new_resource} changed from #{@current_resource.checksum} to #{@new_resource.checksum}")
|
64
|
+
Chef::Log.info("Updating #{@new_resource} at #{@new_resource.path}")
|
65
|
+
backup(@new_resource.path)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
# We're creating a new file
|
69
|
+
Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
|
70
|
+
end
|
71
|
+
|
72
|
+
FileUtils.cp(raw_file.path, @new_resource.path)
|
73
|
+
@new_resource.updated = true
|
74
|
+
|
75
|
+
# We're done with the file, so make sure to close it if it was open.
|
76
|
+
raw_file.close unless raw_file.closed?
|
77
|
+
rescue Net::HTTPRetriableError => e
|
78
|
+
if e.response.kind_of?(Net::HTTPNotModified)
|
79
|
+
Chef::Log.debug("File #{path} is unchanged")
|
80
|
+
retval = false
|
81
|
+
else
|
82
|
+
raise e
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
set_owner if @new_resource.owner
|
88
|
+
set_group if @new_resource.group
|
89
|
+
set_mode if @new_resource.mode
|
90
|
+
|
91
|
+
retval
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_from_uri(source)
|
95
|
+
begin
|
96
|
+
uri = URI.parse(source)
|
97
|
+
if uri.absolute
|
98
|
+
r = Chef::REST.new(source)
|
99
|
+
Chef::Log.debug("Downloading from absolute URI: #{source}")
|
100
|
+
r.get_rest(source, true).open
|
101
|
+
end
|
102
|
+
rescue URI::InvalidURIError
|
103
|
+
nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def get_from_server(source, current_checksum)
|
108
|
+
unless Chef::Config[:solo]
|
109
|
+
r = Chef::REST.new(Chef::Config[:remotefile_url])
|
110
|
+
url = generate_url(source, "files", :checksum => current_checksum)
|
111
|
+
Chef::Log.debug("Downloading from server: #{url}")
|
112
|
+
r.get_rest(url, true).open
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def get_from_local_cookbook(source)
|
117
|
+
if Chef::Config[:solo]
|
118
|
+
cookbook_name = @new_resource.cookbook || @new_resource.cookbook_name
|
119
|
+
filename = find_preferred_file(
|
120
|
+
cookbook_name,
|
121
|
+
:remote_file,
|
122
|
+
source,
|
123
|
+
@node[:fqdn],
|
124
|
+
@node[:platform],
|
125
|
+
@node[:platform_version]
|
126
|
+
)
|
127
|
+
Chef::Log.debug("Using local file for remote_file:#{filename}")
|
128
|
+
::File.open(filename)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Bryan McLellan (btm@loftninjas.org)
|
3
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
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/log'
|
20
|
+
require 'chef/mixin/command'
|
21
|
+
require 'chef/provider'
|
22
|
+
require 'erb'
|
23
|
+
|
24
|
+
class Chef
|
25
|
+
class Provider
|
26
|
+
class Route < Chef::Provider
|
27
|
+
include Chef::Mixin::Command
|
28
|
+
|
29
|
+
def load_current_resource
|
30
|
+
@current_resource = Chef::Resource::Route.new(@new_resource.name)
|
31
|
+
|
32
|
+
Chef::Log.debug("Checking routes for #{@current_resource.target}")
|
33
|
+
status = popen4("route -n") do |pid, stdin, stdout, stderr|
|
34
|
+
stdout.each do |line|
|
35
|
+
case line
|
36
|
+
# Destination Gateway Genmask Flags Metric Ref Use Iface
|
37
|
+
when /^#{@new_resource.target}\s+([\d.]+)\s+([\d.]+)\s+(.+)\s+(\d+)\s+(.+)\s+(.+)\s+(\w+)$/
|
38
|
+
@current_resource.target(@new_resource.target)
|
39
|
+
@current_resource.gateway($1)
|
40
|
+
@current_resource.netmask($2)
|
41
|
+
@current_resource.metric($4.to_i)
|
42
|
+
@current_resource.device($7)
|
43
|
+
Chef::Log.debug("Found route ip:#{@current_resource.target} gw:#{@current_resource.gateway} nm:#{@current_resource.netmask} " +
|
44
|
+
"metric:#{@current_resource.metric} dev:#{@current_resource.device}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
unless status.exitstatus == 0
|
50
|
+
raise Chef::Exception::Route, "route failed - #{status.inspect}!"
|
51
|
+
end
|
52
|
+
|
53
|
+
@current_resource
|
54
|
+
end
|
55
|
+
|
56
|
+
def action_add
|
57
|
+
# check to see if load_current_resource found the route
|
58
|
+
unless @current_resource.gateway
|
59
|
+
if @new_resource.route_type == :net
|
60
|
+
command = "route add -net #{@new_resource.target}"
|
61
|
+
else
|
62
|
+
command = "route add #{@new_resource.target}"
|
63
|
+
end
|
64
|
+
command << " netmask #{@new_resource.netmask}" if @new_resource.netmask
|
65
|
+
command << " gw #{@new_resource.gateway}" if @new_resource.gateway
|
66
|
+
command << " metric #{@new_resource.metric}" if @new_resource.metric
|
67
|
+
command << " dev #{@new_resource.device}" if @new_resource.device
|
68
|
+
|
69
|
+
run_command(
|
70
|
+
:command => command
|
71
|
+
)
|
72
|
+
@new_resource.updated = true
|
73
|
+
else
|
74
|
+
Chef::Log.debug("Route #{@current_resource} already exists")
|
75
|
+
end
|
76
|
+
# Write out the config files
|
77
|
+
generate_config
|
78
|
+
end
|
79
|
+
|
80
|
+
def action_delete
|
81
|
+
# check to see if load_current_resource found the route
|
82
|
+
if @current_resource.gateway
|
83
|
+
command = "route del #{@new_resource.target}"
|
84
|
+
command << " netmask #{@new_resource.netmask}" if @new_resource.netmask
|
85
|
+
command << " gw #{@new_resource.gateway}" if @new_resource.gateway
|
86
|
+
command << " metric #{@new_resource.metric}" if @new_resource.metric
|
87
|
+
command << " dev #{@new_resource.device}" if @new_resource.device
|
88
|
+
|
89
|
+
run_command(
|
90
|
+
:command => command
|
91
|
+
)
|
92
|
+
@new_resource.updated = true
|
93
|
+
else
|
94
|
+
Chef::Log.debug("Route #{@current_resource} does not exist")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def generate_config
|
99
|
+
b = binding
|
100
|
+
case node[:platform]
|
101
|
+
when ("centos" || "redhat" || "fedora")
|
102
|
+
content = %{
|
103
|
+
<% if @new_resource.networking %>NETWORKING=<%= @new_resource.networking %><% end %>
|
104
|
+
<% if @new_resource.networking_ipv6 %>NETWORKING_IPV6=<%= @new_resource.networking_ipv6 %><% end %>
|
105
|
+
<% if @new_resource.hostname %>HOSTNAME=<%= @new_resource.hostname %><% end %>
|
106
|
+
<% if @new_resource.name %>GATEWAY=<%= @new_resource.name %><% end %>
|
107
|
+
<% if @new_resource.domainname %>DOMAINNAME=<%= @new_resource.domainname %><% end %>
|
108
|
+
<% if @new_resource.domainname %>DOMAIN=<%= @new_resource.domainname %><% end %>
|
109
|
+
}
|
110
|
+
template = ::ERB.new(content)
|
111
|
+
network_file = ::File.new("/etc/sysconfig/network", "w")
|
112
|
+
network_file.puts(template.result(b))
|
113
|
+
network_file.close
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|