class Chef::Knife::Depgraph
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/depgraph.rb, line 33 def run unless name_args.size == 1 ui.err(opt_parser) exit 1 end node_name = name_args.first node = Chef::Node.load(node_name) environment ||= node.chef_environment cookbooks = node.run_list.run_list_items 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.err("Solving [#{cookbooks.join(', ')}] in #{environment} environment") solution = solve_cookbooks(environment, cookbooks) dep_graph = {} solution.sort.each do |name, cb| dep_graph[name] = { "version" => cb.version, "deps" => cb.metadata.dependencies } end ui.msg( Chef::JSONCompat.to_json_pretty(dep_graph) ) end
solve_cookbooks(environment, cookbooks)
click to toggle source
# File lib/chef/knife/depgraph.rb, line 76 def solve_cookbooks(environment, cookbooks) rest.post_rest("/environments/#{environment}/cookbook_versions", 'run_list' => cookbooks) end