Top Level Namespace
Defined Under Namespace
Modules: BluepillTestHelpers, Gem, Helpers, Opscode, ServerMaint
Classes: Chef
Instance Method Summary
collapse
-
#build_pref(package_name, pin, pin_priority) ⇒ Object
Build preferences.d file contents.
-
#build_repo(uri, distribution, components, add_deb_src) ⇒ Object
build repo file contents.
-
#can_haz(resource, attribute_name) ⇒ Object
TODO remove when provider is moved into Chef core this allows PhpPear to work with Chef::Resource::Package.
-
#candidate_version ⇒ Object
-
#current_installed_version ⇒ Object
-
#delete_chef(name) ⇒ Object
-
#etc ⇒ Object
Prerequisites and system information.
-
#expand_channel(channel) ⇒ Object
-
#expand_options(options) ⇒ Object
-
#extract_gpg_ids_from_cmd(cmd) ⇒ Object
run command and extract gpg ids.
-
#get_extension_dir ⇒ Object
-
#get_extension_files(name) ⇒ Object
-
#grep_for_version(stdout, package) ⇒ Object
-
#initialize(*args) ⇒ Object
-
#insert_chef(name) ⇒ Object
-
#install_key_from_keyserver(key, keyserver) ⇒ Object
install apt key from keyserver.
-
#install_key_from_uri(uri) ⇒ Object
install apt key from URI.
-
#install_package(name, version) ⇒ Object
-
#load_current_resource ⇒ Object
these methods are the required overrides of a provider that extends from Chef::Provider::Package so refactoring into core Chef should be easy.
-
#manage_pecl_ini(name, action, directives, zend_extensions) ⇒ Object
-
#package(*args, &blk) ⇒ Object
-
#pear_shell_out(command) ⇒ Object
-
#pecl? ⇒ Boolean
-
#prefix_channel(channel) ⇒ Object
-
#purge_package(name, version) ⇒ Object
-
#query(sql) ⇒ Object
(also: #insert, #update, #delete)
-
#remove_package(name, version) ⇒ Object
-
#removing_package? ⇒ Boolean
-
#select_tv_chefs ⇒ Object
-
#test_client_host ⇒ Object
-
#test_database ⇒ Object
-
#test_password ⇒ Object
-
#test_server_host ⇒ Object
-
#test_user ⇒ Object
-
#tv_chefs ⇒ Object
-
#update_chef_name(old_name, new_name) ⇒ Object
-
#upgrade_package(name, version) ⇒ Object
-
#whyrun_supported? ⇒ Boolean
#ec2, #find_snapshot_id, #instance_availability_zone, #instance_id
Instance Method Details
#build_pref(package_name, pin, pin_priority) ⇒ Object
Build preferences.d file contents
21
22
23
|
# File 'lib/cookbooks/apt/providers/preference.rb', line 21
def build_pref(package_name, pin, pin_priority)
preference_content = "Package: #{package_name}\nPin: #{pin}\nPin-Priority: #{pin_priority}\n"
end
|
#build_repo(uri, distribution, components, add_deb_src) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/cookbooks/apt/providers/repository.rb', line 75
def build_repo(uri, distribution, components, add_deb_src)
components = components.join(' ') if components.respond_to?(:join)
repo_info = "#{uri} #{distribution} #{components}\n"
repo = "deb #{repo_info}"
repo << "deb-src #{repo_info}" if add_deb_src
repo
end
|
#can_haz(resource, attribute_name) ⇒ Object
TODO remove when provider is moved into Chef core this allows PhpPear to work with Chef::Resource::Package
259
260
261
|
# File 'lib/cookbooks/php/providers/pear.rb', line 259
def can_haz(resource, attribute_name)
resource.respond_to?(attribute_name) ? resource.send(attribute_name) : nil
end
|
#candidate_version ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/cookbooks/php/providers/pear.rb', line 125
def candidate_version
@candidate_version ||= begin
candidate_version_cmd = "#{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} search#{expand_channel(can_haz(@new_resource, "channel"))} #{@new_resource.package_name}"
p = shell_out(candidate_version_cmd)
response = nil
if p.stdout =~ /\.?Matched packages/i
response = grep_for_version(p.stdout, @new_resource.package_name)
end
response
end
end
|
#current_installed_version ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/cookbooks/php/providers/pear.rb', line 112
def current_installed_version
@current_installed_version ||= begin
v = nil
version_check_cmd = "#{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} list#{expand_channel(can_haz(@new_resource, "channel"))}"
p = shell_out(version_check_cmd)
response = nil
if p.stdout =~ /\.?Installed packages/i
response = grep_for_version(p.stdout, @new_resource.package_name)
end
response
end
end
|
#delete_chef(name) ⇒ Object
11
12
13
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 11
def delete_chef(name)
delete("DELETE FROM tv_chef WHERE name = '#{name}'")
end
|
#etc ⇒ Object
Prerequisites and system information
29
|
# File 'lib/cookbooks/sanitize/recipes/default.rb', line 29
require 'etc'
|
#expand_channel(channel) ⇒ Object
167
168
169
|
# File 'lib/cookbooks/php/providers/pear.rb', line 167
def expand_channel(channel)
channel ? " -c #{channel}" : ""
end
|
#expand_options(options) ⇒ Object
87
88
89
|
# File 'lib/cookbooks/php/providers/pear.rb', line 87
def expand_options(options)
options ? " #{options}" : ""
end
|
run command and extract gpg ids
32
33
34
35
36
37
38
39
40
|
# File 'lib/cookbooks/apt/providers/repository.rb', line 32
def (cmd)
so = Mixlib::ShellOut.new(cmd)
so.run_command
so.stdout.split(/\n/).collect do |t|
if z = t.match(/^pub\s+\d+\w\/([0-9A-F]{8})/)
z[1]
end
end.compact
end
|
#get_extension_dir ⇒ Object
175
176
177
178
179
180
|
# File 'lib/cookbooks/php/providers/pear.rb', line 175
def get_extension_dir()
@extension_dir ||= begin
p = shell_out("php-config --extension-dir")
p.stdout.strip
end
end
|
#get_extension_files(name) ⇒ Object
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/cookbooks/php/providers/pear.rb', line 182
def get_extension_files(name)
files = []
p = shell_out("#{@bin} list-files #{name}")
p.stdout.each_line.grep(/^src\s+.*\.so$/i).each do |line|
files << line.split[1]
end
files
end
|
#grep_for_version(stdout, package) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
# File 'lib/cookbooks/php/providers/pear.rb', line 219
def grep_for_version(stdout, package)
v = nil
stdout.split(/\n/).grep(/^#{package}\s/i).each do |m|
v = m.split(/\s+/)[1].strip
if v.split(/\//)[0] =~ /.\./
v = v.split(/\//)[0]
else
v = v.split(/(.*)\/\((.*)/).last.split(/\s/)[0]
end
end
v
end
|
#initialize(*args) ⇒ Object
22
23
24
25
|
# File 'lib/cookbooks/apt/resources/preference.rb', line 22
def initialize(*args)
super
@action = :add
end
|
#insert_chef(name) ⇒ Object
15
16
17
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 15
def insert_chef(name)
insert("INSERT INTO tv_chef (name) VALUES('#{name}')")
end
|
#install_key_from_keyserver(key, keyserver) ⇒ Object
install apt key from keyserver
21
22
23
24
25
26
27
28
29
|
# File 'lib/cookbooks/apt/providers/repository.rb', line 21
def install_key_from_keyserver(key, keyserver)
unless system("apt-key list | grep #{key}")
execute "install-key #{key}" do
command "apt-key adv --keyserver #{keyserver} --recv #{key}"
action :nothing
end.run_action(:run)
new_resource.updated_by_last_action(true)
end
end
|
#install_key_from_uri(uri) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/cookbooks/apt/providers/repository.rb', line 43
def install_key_from_uri(uri)
key_name = uri.split(/\//).last
cached_keyfile = "#{Chef::Config[:file_cache_path]}/#{key_name}"
if new_resource.key =~ /http/
r = remote_file cached_keyfile do
source new_resource.key
mode "0644"
action :nothing
end
else
r = cookbook_file cached_keyfile do
source new_resource.key
cookbook new_resource.cookbook
mode "0644"
action :nothing
end
end
r.run_action(:create)
installed_ids = ("apt-key finger")
key_ids = ("gpg --with-fingerprint #{cached_keyfile}")
unless installed_ids & key_ids == key_ids
execute "install-key #{key_name}" do
command "apt-key add #{cached_keyfile}"
action :nothing
end.run_action(:run)
new_resource.updated_by_last_action(true)
end
end
|
#install_package(name, version) ⇒ Object
137
138
139
140
|
# File 'lib/cookbooks/php/providers/pear.rb', line 137
def install_package(name, version)
pear_shell_out("echo -e \"\\r\" | #{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} install -a#{expand_options(@new_resource.options)} #{prefix_channel(can_haz(@new_resource, "channel"))}#{name}-#{version}")
manage_pecl_ini(name, :create, can_haz(@new_resource, "directives"), can_haz(@new_resource, "zend_extensions")) if pecl?
end
|
#load_current_resource ⇒ Object
these methods are the required overrides of a provider that extends from Chef::Provider::Package so refactoring into core Chef should be easy
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/cookbooks/php/providers/pear.rb', line 95
def load_current_resource
@current_resource = Chef::Resource::PhpPear.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
@bin = 'pear'
if pecl?
Chef::Log.debug("#{@new_resource} smells like a pecl...installing package in Pecl mode.")
@bin = 'pecl'
end
Chef::Log.debug("#{@current_resource}: Installed version: #{current_installed_version} Candidate version: #{candidate_version}")
unless current_installed_version.nil?
@current_resource.version(current_installed_version)
Chef::Log.debug("Current version is #{@current_resource.version}") if @current_resource.version
end
@current_resource
end
|
#manage_pecl_ini(name, action, directives, zend_extensions) ⇒ Object
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/cookbooks/php/providers/pear.rb', line 193
def manage_pecl_ini(name, action, directives, zend_extensions)
ext_prefix = get_extension_dir()
ext_prefix << ::File::SEPARATOR if ext_prefix[-1].chr != ::File::SEPARATOR
files = get_extension_files(name)
extensions = Hash[ files.map { |filepath|
rel_file = filepath.clone
rel_file.slice! ext_prefix if rel_file.start_with? ext_prefix
zend = zend_extensions.include?(rel_file)
[ (zend ? filepath : rel_file) , zend ]
}]
template "#{node['php']['ext_conf_dir']}/#{name}.ini" do
source "extension.ini.erb"
cookbook "php"
owner "root"
group "root"
mode "0644"
variables(:name => name, :extensions => extensions, :directives => directives)
action action
end
end
|
#package(*args, &blk) ⇒ Object
88
89
90
|
# File 'lib/cookbooks/mysql/recipes/server.rb', line 88
def package(*args, &blk)
windows_package(*args, &blk)
end
|
#pear_shell_out(command) ⇒ Object
154
155
156
157
158
159
160
161
|
# File 'lib/cookbooks/php/providers/pear.rb', line 154
def pear_shell_out(command)
p = shell_out!(command)
if p.stdout.split("\n").last =~ /^ERROR:.+/i
p.invalid!
end
p
end
|
#pecl? ⇒ Boolean
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/cookbooks/php/providers/pear.rb', line 239
def pecl?
@pecl ||= begin
search_cmd = "pear -d preferred_state=#{can_haz(@new_resource, "preferred_state")} search#{expand_channel(can_haz(@new_resource, "channel"))} #{@new_resource.package_name}"
if shell_out(search_cmd).stdout =~ /\.?Matched packages/i
false
else
search_cmd = "pecl -d preferred_state=#{can_haz(@new_resource, "preferred_state")} search#{expand_channel(can_haz(@new_resource, "channel"))} #{@new_resource.package_name}"
if shell_out(search_cmd).stdout =~ /\.?Matched packages/i
true
else
false
end
end
end
end
|
#prefix_channel(channel) ⇒ Object
171
172
173
|
# File 'lib/cookbooks/php/providers/pear.rb', line 171
def prefix_channel(channel)
channel ? "#{channel}/" : ""
end
|
#purge_package(name, version) ⇒ Object
163
164
165
|
# File 'lib/cookbooks/php/providers/pear.rb', line 163
def purge_package(name, version)
remove_package(name, version)
end
|
#query(sql) ⇒ Object
Also known as:
insert, update, delete
1
2
3
4
5
6
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 1
def query(sql)
cmd_prefix = test_client_host ? "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@#{test_client_host}" : ''
result = %x{echo "#{sql}" | #{cmd_prefix} mysql --host=#{test_server_host} --user=#{test_user} --password=#{test_password} --skip-column-names #{test_database}}
assert $?.success?
result
end
|
#remove_package(name, version) ⇒ Object
147
148
149
150
151
152
|
# File 'lib/cookbooks/php/providers/pear.rb', line 147
def remove_package(name, version)
command = "#{@bin} uninstall #{expand_options(@new_resource.options)} #{prefix_channel(can_haz(@new_resource, "channel"))}#{name}"
command << "-#{version}" if version and !version.empty?
pear_shell_out(command)
manage_pecl_ini(name, :delete) if pecl?
end
|
#removing_package? ⇒ Boolean
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/cookbooks/php/providers/pear.rb', line 75
def removing_package?
if @current_resource.version.nil?
false elsif @new_resource.version.nil?
true elsif @new_resource.version == @current_resource.version
true else
false end
end
|
#select_tv_chefs ⇒ Object
19
20
21
22
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 19
def select_tv_chefs
@tv_chefs = query('SELECT name FROM tv_chef ORDER BY name').split("\n")
@tv_chefs
end
|
#test_client_host ⇒ Object
24
25
26
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 24
def test_client_host
ENV['TEST_CLIENT_HOST']
end
|
#test_database ⇒ Object
28
29
30
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 28
def test_database
'mysql_test'
end
|
#test_password ⇒ Object
36
37
38
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 36
def test_password
'neshFiapog'
end
|
#test_server_host ⇒ Object
32
33
34
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 32
def test_server_host
ENV['TEST_SERVER_HOST'] || 'localhost'
end
|
#test_user ⇒ Object
40
41
42
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 40
def test_user
'test_user'
end
|
#tv_chefs ⇒ Object
44
45
46
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 44
def tv_chefs
@tv_chefs
end
|
#update_chef_name(old_name, new_name) ⇒ Object
48
49
50
|
# File 'lib/cookbooks/mysql/test/features/support/mysql_helpers.rb', line 48
def update_chef_name(old_name, new_name)
update("UPDATE tv_chef SET name = '#{new_name}' WHERE name = '#{old_name}'")
end
|
#upgrade_package(name, version) ⇒ Object
142
143
144
145
|
# File 'lib/cookbooks/php/providers/pear.rb', line 142
def upgrade_package(name, version)
pear_shell_out("echo -e \"\\r\" | #{@bin} -d preferred_state=#{can_haz(@new_resource, "preferred_state")} upgrade -a#{expand_options(@new_resource.options)} #{prefix_channel(can_haz(@new_resource, "channel"))}#{name}-#{version}")
manage_pecl_ini(name, :create, can_haz(@new_resource, "directives"), can_haz(@new_resource, "zend_extensions")) if pecl?
end
|
#whyrun_supported? ⇒ Boolean
4
5
6
|
# File 'lib/cookbooks/aws/providers/ebs_volume.rb', line 4
def whyrun_supported?
true
end
|