Class: PoolParty::Plugin::Chef
- Inherits:
-
Plugin
show all
- Defined in:
- lib/poolparty/plugins/chef/chef.rb
Instance Attribute Summary
#init_opts, #ordered_resources
Instance Method Summary
collapse
Methods inherited from Plugin
#after_create, #bootstrap_commands, #bootstrap_gems, #calls, #cloud, #configure_commands, #enable, inherited, #initialize, #is_plugin?
Methods included from Callbacks
included
#to_properties_hash
#dependency_resolver, #instances, #plugin_directory, #run_stored_block, #store_block, #stored_block, #using
Methods inherited from Service
add_has_and_does_not_have_methods_for, #cloud, #to_properties_hash
add_has_and_does_not_have_methods_for, #add_resource, add_resource_lookup_method, #add_service, #add_to_parent_if_parent_exists_and_is_a_service, #get_local_resource, #get_name_from_options_and_extra_options, #get_resource, #handle_option_values, #in_local_resources?, #initialize, #inspect, #is_a_resource?, #is_plugin?, #plugin_store, #resource, #resources, #run_in_context, #run_with_callbacks, #search_in_known_locations, #store_in_local_resources, #to_hash, #to_json
included
Instance Method Details
#added_recipes ⇒ Object
127
128
129
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 127
def added_recipes
@added_recipes ||= []
end
|
24
25
26
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 24
def basedir
@basedir ||= "#{cloud.tmp_path}/dr_configure/chef/cookbooks/main"
end
|
#before_bootstrap ⇒ Object
131
132
133
134
135
136
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 131
def before_bootstrap
bootstrap_gems "chef", "ohai"
bootstrap_commands [
"mkdir -p /etc/chef/cookbooks /etc/chef/cache"
]
end
|
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 137
def before_configure
config
json
included_recipes.each do |f|
::Suitcase::Zipper.add(f, "chef/cookbooks")
end
if ::File.directory?("/etc/chef")
::Suitcase::Zipper.add("/etc/chef/cookbooks/*", "chef/cookbooks")
::Suitcase::Zipper.add("/etc/chef/dna.json", "chef/json")
::Suitcase::Zipper.add("/etc/chef/solo.rb", "chef/")
end
end
|
#before_load(o, &block) ⇒ Object
14
15
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 14
def before_load(o, &block)
end
|
#config(file = "") ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 107
def config file=""
if ::File.file? file
::Suitcase::Zipper.add_content_as(open(file).read, "solo.rb", "chef")
else
conf_string = if file.empty?
"cookbook_path \"/etc/chef/cookbooks\"\nnode_path \"/etc/chef/nodes\"\nlog_level :info\nfile_store_path \"/etc/chef\"\nfile_cache_path \"/etc/chef\"\n EOE\n else\n open(file).read\n end\n ::Suitcase::Zipper.add_content_as(conf_string, \"solo.rb\", \"chef\")\n end\nend\n"
|
#include_recipes(*recps) ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 93
def include_recipes *recps
unless recps.empty?
recps.each do |rcp|
Dir[::File.expand_path(rcp)].each do |f|
included_recipes << f
end
end
end
end
|
#included_recipes ⇒ Object
103
104
105
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 103
def included_recipes
@included_recipes ||= []
end
|
#json(file = nil, &block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 69
def json file=nil, &block
if file
if ::File.file? file
::Suitcase::Zipper.add_content_as(open(file).read, "dna.json", "chef")
elsif file.is_a?(String)
::Suitcase::Zipper.add_content_as(file, "dna.json", "chef")
else
raise " Your json must either point to a file that exists or a string. Please check your configuration and try again\n EOM\n end\n else\n unless @recipe\n # @recipe = has_chef_recipe \"poolparty\", &block\n # @recipe.instance_eval(&block) if block\n # @recipe.recipes(recipe_files.empty? ? [\"poolparty\"] : [\"poolparty\", \"main\"])\n dna_content = recipe_files.empty? ? [\"poolparty\"] : [\"poolparty\", \"main\"]\n ::Suitcase::Zipper.add_content_as({:recipes => dna_content}.to_json, \"dna.json\", \"chef\")\n \n configure_commands [\"cp -f /var/poolparty/dr_configure/chef/dna.json /etc/chef/dna.json\"]\n end\n end\nend\n"
|
#loaded(o = {}, &block) ⇒ Object
17
18
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 17
def loaded o={}, &block
end
|
#recipe(file = nil, o = {}, &block) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 28
def recipe(file=nil, o={}, &block)
if file
file = search_in_known_locations(file)
raise RecipeNotFoundError.new(file) unless file
::FileUtils.mkdir_p "#{basedir}/recipes" unless ::File.directory?("#{basedir}/recipes")
::FileUtils.rm "#{basedir}/recipes/default.rb" if ::File.file?("#{basedir}/recipes/default.rb")
::File.open("#{basedir}/recipes/default.rb", "w") {|f| f << open(file).read }
templates o[:templates] if o[:templates]
recipe_files << basedir
else
raise " PoolParty currently only supports passing recipes as files. Please specify a file in your chef block and try again\"\n EOR\n end\nend\n"
|
#recipe_files ⇒ Object
20
21
22
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 20
def recipe_files
@recipe_files ||= []
end
|
#templates(templates = []) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/poolparty/plugins/chef/chef.rb', line 51
def templates(templates=[])
if templates
::FileUtils.mkdir_p "#{basedir}/templates/default/"
templates.each do |f|
f = ::File.expand_path(f)
if ::File.file?(f)
::FileUtils.cp f, "#{basedir}/templates/default/#{::File.basename(f)}"
elsif ::File.directory?(f)
Dir["#{f}/**"].each {|f| ::FileUtils.cp f, "#{basedir}/templates/default/#{::File.basename(f)}" }
else
tfile = Tempfile.new("main-poolparty-recipe")
tfile << f
::FileUtils.cp tfile.path, "#{basedir}/templates/default/#{::File.basename(f)}"
end
end
end
end
|