Class: Kitchen::Provisioner::Nodes

Inherits:
ChefZero
  • Object
show all
Defined in:
lib/kitchen/provisioner/nodes.rb

Overview

Nodes provisioner for Kitchen.

Author:

Instance Method Summary collapse

Instance Method Details

#active_ips(transport, state) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/kitchen/provisioner/nodes.rb', line 82

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
  IpFinder.for_transport(transport, state).find_ips
end

#create_nodeObject



36
37
38
39
40
41
# File 'lib/kitchen/provisioner/nodes.rb', line 36

def create_node
  FileUtils.mkdir_p(node_dir) unless Dir.exist?(node_dir)
  File.open(node_file, 'w') do |out|
    out << JSON.pretty_generate(node_template)
  end
end

#create_sandboxObject



30
31
32
33
34
# File 'lib/kitchen/provisioner/nodes.rb', line 30

def create_sandbox
  FileUtils.rm(node_file) if File.exist?(node_file)
  create_node
  super
end

#get_reachable_guest_address(state) ⇒ Object



75
76
77
78
79
80
# File 'lib/kitchen/provisioner/nodes.rb', line 75

def get_reachable_guest_address(state)
  active_ips(instance.transport, state).each do |address|
    next if address == '127.0.0.1'
    return address if Net::Ping::External.new.ping(address)
  end
end

#ipaddressObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kitchen/provisioner/nodes.rb', line 43

def ipaddress
  state = Kitchen::StateFile.new(
    config[:kitchen_root],
    instance.name
  ).read

  if %w(127.0.0.1 localhost).include?(state[:hostname])
    return get_reachable_guest_address(state)
  end
  state[:hostname]
end

#node_dirObject



67
68
69
# File 'lib/kitchen/provisioner/nodes.rb', line 67

def node_dir
  File.join(config[:test_base_path], 'nodes')
end

#node_fileObject



71
72
73
# File 'lib/kitchen/provisioner/nodes.rb', line 71

def node_file
  File.join(node_dir, "#{instance.name}.json")
end

#node_templateObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kitchen/provisioner/nodes.rb', line 55

def node_template
  {
    id: instance.name,
    automatic: {
      ipaddress: ipaddress,
      platform: instance.platform.name.split('-')[0].downcase
    },
    normal: config[:attributes],
    run_list: config[:run_list]
  }
end