Chef Import

<% $session = session if !$session['gen.available_recipes'] $session['gen.available_recipes'] = {} end if !$session['gen.available_cookbook_versions'] $session['gen.available_cookbook_versions'] = {} end if !$session['gen.available_cookbooks'] $session['gen.available_cookbooks'] = [] end available_cookbooks = $session['gen.available_cookbooks'] available_cookbook_versions = $session['gen.available_cookbook_versions'] available_recipes = $session['gen.available_recipes'] message = "" # retrieve list of available cookbooks from opscode if param("loadOpsCode") != "" books = ChefUtil.available_cookbooks_from_opscode() if books books.each do |b| available_cookbooks << b["cookbook_name"] end $session['gen.available_cookbooks'] = Toaster::MarkupUtil.to_json(available_cookbooks) end message += "Loaded #{books.size} cookbooks from opscode. Try auto-completion in textfield." if !books.empty? end # retrieve list of available cookbooks from opscode if param("cookbook") != "" cb_name = param("cookbook") if !available_cookbook_versions[cb_name] || available_cookbook_versions[cb_name].empty? begin available_cookbook_versions[cb_name] = ChefUtil.available_cookbook_versions(cb_name) rescue => ex flash[:warn] = ex end end end # retrieve list of available recipes for a specific cookbook if param("loadOpsCodeRecipes") != "" recipes = ChefUtil.available_recipes_from_opscode(param('cookbook'), param('cookbook_version')) if recipes available_recipes[param('cookbook')] = [] recipes.each do |r| available_recipes[param('cookbook')] << r["recipe_name"] end #available_recipes[param('cookbook')] = Toaster::MarkupUtil.to_json(available_recipes) end message += "Loaded #{recipes.size} recipes for cookbook '#{param('cookbook')}' version '#{param('cookbook_version')}' from opscode. Try auto-completion in textfield." if !recipes.empty? end %> <% puts params if message && message.to_s != "" %>
<%= message %>
<% end %> <%= form_tag do %>
Automation Name: <%= text_field_tag :auto_name, param('auto_name', '') %>
Chef Cookbook: <%= text_field_tag :cookbook, param("cookbook", 'tomcat6'), :id => "cookbook" %> <% if available_cookbooks.empty? %>
<% else %> <% end %>
Version: <%= select_tag(:cookbook_version, options_for_select(["latest"].concat( available_cookbook_versions[param('cookbook')] || []))) %>
Recipe Name(s): <%= text_field_tag :recipes, param('recipes', 'default'), :id => "recipes" %>
(Use space or comma as separator.)

<% if available_recipes[param('cookbook')] && !available_recipes[param('cookbook')].empty? %> <% end %>
<%= submit_tag("Import Chef Script", :name => "submitImport") %>
<% end %>