class Kitchen::Provisioner::Nodes
Nodes
provisioner for Kitchen
.
@author Matt Wrock <matt@mattwrock.com>
Public Instance Methods
active_ips(transport, state)
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 152 def active_ips(transport, state) # inject creds into state for legacy drivers [:username, :password].each do |prop| state[prop] = instance.driver[prop] if instance.driver[prop] end ips = Finder.for_transport(transport, state).find_ips raise 'Unable to retrieve IPs' if ips.empty? ips end
chef_environment()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 104 def chef_environment env = '_default' if config[:client_rb] && config[:client_rb][:environment] env = config[:client_rb][:environment] end env end
create_node()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 39 def create_node FileUtils.mkdir_p(node_dir) unless Dir.exist?(node_dir) node_def = if File.exist?(node_file) updated_node_def else node_template end return unless node_def File.open(node_file, 'w') do |out| out << JSON.pretty_generate(node_def) end end
create_sandbox()
click to toggle source
Calls superclass method
# File lib/kitchen/provisioner/nodes.rb, line 33 def create_sandbox create_node ensure super end
fqdn()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 78 def fqdn state = state_file begin [:username, :password].each do |prop| state[prop] = instance.driver[prop] if instance.driver[prop] end Finder.for_transport(instance.transport, state).find_fqdn rescue nil end end
get_reachable_guest_address(state)
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 138 def get_reachable_guest_address(state) active_ips(instance.transport, state).each do |address| next if address == '127.0.0.1' return address if reachable?(address) end end
ipaddress()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 69 def ipaddress state = state_file if %w(127.0.0.1 localhost).include?(state[:hostname]) return get_reachable_guest_address(state) end state[:hostname] end
node_dir()
click to toggle source
rubocop:enable Metrics/AbcSize
# File lib/kitchen/provisioner/nodes.rb, line 130 def node_dir config[:nodes_path] || File.join(config[:test_base_path], 'nodes') end
node_file()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 134 def node_file File.join(node_dir, "#{instance.name}.json") end
node_template()
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/kitchen/provisioner/nodes.rb, line 113 def node_template { id: instance.name, chef_environment: chef_environment, automatic: { ipaddress: ipaddress, platform: instance.platform.name.split('-')[0].downcase, fqdn: fqdn, recipes: recipes }, normal: config[:attributes], run_list: config[:run_list], named_run_list: config[:named_run_list] } end
reachable?(address)
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 145 def reachable?(address) Net::Ping::External.new.ping(address) || Net::Ping::TCP.new(address, 5985).ping || Net::Ping::TCP.new(address, 5986).ping || Net::Ping::TCP.new(address, 22).ping end
recipes()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 90 def recipes rl = config[:run_list].map do |item| ::Chef::RunList::RunListItem.new item end rle = RunListExpansionFromKitchen.new( chef_environment, rl, nil, config[:roles_path] ) rle.expand rle.recipes end
state_file()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 62 def state_file @state_file ||= Kitchen::StateFile.new( config[:kitchen_root], instance.name ).read end
updated_node_def()
click to toggle source
# File lib/kitchen/provisioner/nodes.rb, line 54 def updated_node_def if config[:reset_node_files] node_template else nil end end