class Chef::Knife::Solve

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/solve.rb, line 34
def run
  environment = config[:environment]
  cookbooks = name_args.map {|item| item.to_s.split(/,/) }.flatten.each{|item| item.strip! }
  cookbooks.delete_if {|item| item.empty? }
  if config[:node]
    node = Chef::Node.load(config[:node])
    environment ||= node.chef_environment
    cookbooks += node.run_list.run_list_items
  end
  environment ||= '_default'
  cookbooks = cookbooks.map do |arg|
    arg = arg.to_s
    if arg.include?('[')
      run_list = [Chef::RunList::RunListItem.new(arg)]
      expansion = Chef::RunList::RunListExpansionFromAPI.new(environment, run_list, rest)
      expansion.expand
      expansion.recipes
    else
      arg # Just a plain name
    end
  end.flatten.map do |arg|
    # I don't think this is strictly speaking required, but do it anyway
    arg.split('@').first.split('::').first
  end
  ui.info("Solving [#{cookbooks.join(', ')}] in #{environment} environment")
  solution = solve_cookbooks(environment, cookbooks)
  solution.sort.each do |name, cb|
    # Newer Chef doesn't auto-inflate the object.
    version = if cb.is_a?(Hash)
      cb['version']
    else
      cb.version
    end
    msg("#{name} #{version}")
  end
end
solve_cookbooks(environment, cookbooks) click to toggle source
# File lib/chef/knife/solve.rb, line 71
def solve_cookbooks(environment, cookbooks)
  rest.post_rest("/environments/#{environment}/cookbook_versions", 'run_list' => cookbooks)
end