class Chef::Topo::TopoV1Converter
Convert V1 topology JSON to V2
Constants
- PRIORITIES
Public Instance Methods
cleanup_output()
click to toggle source
# File lib/chef/topo/converter/topo_v1.rb, line 120 def cleanup_output @output.delete('cookbook_attributes') @output end
convert(data = nil)
click to toggle source
# File lib/chef/topo/converter/topo_v1.rb, line 35 def convert(data = nil) @input = data if data @output = @input.dup determine_strategy @output['nodes'] = [] @input['nodes'].each do |n| @output['nodes'] << convert_node(n) end cleanup_output end
convert_node(n)
click to toggle source
# File lib/chef/topo/converter/topo_v1.rb, line 46 def convert_node(n) combined = merge_cookbook_attrs(n) type = node_type(n) combined['node_type'] ||= type if type combined end
determine_strategy()
click to toggle source
# File lib/chef/topo/converter/topo_v1.rb, line 53 def determine_strategy @output['strategy'] = 'direct_to_node' cookbooks = @input['cookbook_attributes'] return unless cookbooks && !cookbooks.empty? cookbooks.each do |cb| cond = cb['conditional'] || [] next unless !cond.empty? || PRIORITIES.any? { |k| cb.key?(k) } via_cookbook_strategy(cb) break end end
merge_cookbook_attrs(node)
click to toggle source
Combine cookbook attributes into node
# File lib/chef/topo/converter/topo_v1.rb, line 85 def merge_cookbook_attrs(node) cb_attr_array = @input['cookbook_attributes'] combined = node.dup return combined unless cb_attr_array # merge unqualified attributes into node cb_attr_array.each do |cb_attrs| merge_copy(combined, cb_attrs) # find qualified attributes for node cond = cb_attrs['conditional'] next unless cond merge_copy_cond_attrs(combined, cond) end combined end
merge_copy(dest, source)
click to toggle source
merge_copy_cond_attrs(combined, cond)
click to toggle source
# File lib/chef/topo/converter/topo_v1.rb, line 104 def merge_copy_cond_attrs(combined, cond) topo = (combined['normal'] || {})['topo'] || {} cond.each do |cond_attrs| if topo[cond_attrs['qualifier']] == cond_attrs['value'] merge_copy(combined, cond_attrs) end end combined end
node_type(node)
click to toggle source
# File lib/chef/topo/converter/topo_v1.rb, line 114 def node_type(node) return node['node_type'] if node['node_type'] return nil unless node['normal'] && node['normal']['topo'] node['normal']['topo']['node_type'] end
via_cookbook_strategy(cb)
click to toggle source
# File lib/chef/topo/converter/topo_v1.rb, line 66 def via_cookbook_strategy(cb) @output['strategy'] = 'via_cookbook' @output['strategy_data'] = { 'cookbook' => cb['cookbook'] || @output['name'], 'filename' => cb['filename'] || 'attributes' } end