lib/kuzushi.rb in kuzushi-0.0.7 vs lib/kuzushi.rb in kuzushi-0.0.8

- old
+ new

@@ -1,28 +1,32 @@ require 'rubygems' require 'json' require 'restclient' require 'ostruct' require 'rush' +require 'ohai' class Kuzushi def initialize(url) @base_url = File.dirname(url) @name = File.basename(url) @config_names = [] - @config = [] + @configs = [] @packages = [] @tasks = [] load_config_stack(@name) - @merge = @config.reverse.inject({}) { |i,c| i.merge(c) } + @config = @configs.reverse.inject({}) { |i,c| i.merge(c) } + ohai = Ohai::System.new + ohai.all_plugins + @system = ohai.data process_stack end def load_config_stack(name) @config_names << name - @config << JSON.parse(RestClient.get("#{@base_url}/#{name}")) - if import = @config.last["import"] + @configs << JSON.parse(RestClient.get("#{@base_url}/#{name}")) + if import = @configs.last["import"] load_config_stack(import) end end def process_stack @@ -82,25 +86,28 @@ def process_volumes(v) task "wait for volume #{v.device}" do wait_for_volume v.device end - set_scheduler(v) - check_format(v) + set_readahead v + set_scheduler v + check_format v end def process_raids(r) task "assemble raid #{r.device}" do begin shell "mdadm --assemble #{r.device} #{r.drives.join(" ")}" rescue Object => o + ## sometimes the disks come back with odd error messages - retry seems to be the best option puts "error: #{o.message}" retry end end + set_readahead r set_scheduler r - check_format r + check_format r add_package "mdadm" end def process_mounts(m) task "mount #{m.label}" do @@ -109,11 +116,12 @@ end def process_files(f) fetch("/templates/#{f.template}") do |file| task "setting up #{f.file}" do - shell "erb #{f.template} > #{f.file}" ## FIXME + t = ERB.new File.read(file), 0, '<>' + File.open(f.file,"w") { |f| f.write(t.render) } end end end def process_users(user) @@ -122,10 +130,18 @@ shell "su - #{user.name} -c 'mkdir -p .ssh; echo \"#{key}\" >> .ssh/authorized_keys; chmod -R 0600 .ssh'" end end end + def set_readahead(v) + if v.readahead + task "set readahead for #{v.device}" do + shell "blockdev --setra #{v.readahead} #{v.device}" + end + end + end + def set_scheduler(v) if v.scheduler task "set scheduler for #{v.device}" do shell "echo #{v.scheduler} > /sys/block/#{File.basename(v.device)}/queue/scheduler" end @@ -195,10 +211,10 @@ def error(message, exception = nil) puts "ERROR :#{message}" end def get(key) - @merge[key.to_s] + @config[key.to_s] end def get_array(key) [ get(key) || [] ].flatten end