Class: Kitchen::Provisioner::Nodes
- Inherits:
-
ChefZero
- Object
- ChefZero
- Kitchen::Provisioner::Nodes
- Defined in:
- lib/kitchen/provisioner/nodes.rb
Overview
Nodes provisioner for Kitchen.
Instance Method Summary collapse
- #active_ips(transport, state) ⇒ Object
- #create_node ⇒ Object
- #create_sandbox ⇒ Object
- #get_reachable_guest_address(state) ⇒ Object
- #node_dir ⇒ Object
- #node_file ⇒ Object
Instance Method Details
#active_ips(transport, state) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/kitchen/provisioner/nodes.rb', line 74 def active_ips(transport, state) # inject creds into state for legacy drivers state[:password] = instance.driver[:password] if instance.driver[:password] state[:username] = instance.driver[:username] if instance.driver[:username] IpFinder.for_transport(transport, state).find_ips end |
#create_node ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/kitchen/provisioner/nodes.rb', line 38 def create_node state = Kitchen::StateFile.new(config[:kitchen_root], instance.name).read ip = state[:hostname] ipaddress = (ip == "127.0.0.1" || ip == "localhost") ? get_reachable_guest_address(state) : ip node = { :id => instance.name, :automatic => { :ipaddress => ipaddress, :platform => instance.platform.name.split("-")[0].downcase }, :run_list => config[:run_list] } FileUtils.mkdir_p(node_dir) unless Dir.exist?(node_dir) File.open(node_file, 'w') do |out| out << JSON.pretty_generate(node) end end |
#create_sandbox ⇒ Object
32 33 34 35 36 |
# File 'lib/kitchen/provisioner/nodes.rb', line 32 def create_sandbox FileUtils.rm(node_file) if File.exist?(node_file) super create_node end |
#get_reachable_guest_address(state) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/kitchen/provisioner/nodes.rb', line 66 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 return nil end |
#node_dir ⇒ Object
58 59 60 |
# File 'lib/kitchen/provisioner/nodes.rb', line 58 def node_dir File.join(config[:test_base_path], "nodes") end |
#node_file ⇒ Object
62 63 64 |
# File 'lib/kitchen/provisioner/nodes.rb', line 62 def node_file File.join(node_dir, "#{instance.name}.json") end |