lib/kitchen/provisioner/nodes.rb in kitchen-nodes-0.4.1 vs lib/kitchen/provisioner/nodes.rb in kitchen-nodes-0.5.0

- old
+ new

@@ -16,11 +16,11 @@ # See the License for the specific language governing permissions and # limitations under the License. require 'kitchen' require 'kitchen/provisioner/chef_zero' -require 'kitchen/provisioner/ip_finder' +require 'kitchen/provisioner/finder' require 'net/ping' module Kitchen module Provisioner # Nodes provisioner for Kitchen. @@ -39,22 +39,38 @@ File.open(node_file, 'w') do |out| out << JSON.pretty_generate(template_to_write) end end - def ipaddress - state = Kitchen::StateFile.new( + def state_file + @state_file ||= Kitchen::StateFile.new( config[:kitchen_root], instance.name ).read + end + 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 + 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 + def chef_environment env = '_default' if config[:client_rb] && config[:client_rb][:environment] env = config[:client_rb][:environment] end @@ -65,11 +81,12 @@ { id: instance.name, chef_environment: chef_environment, automatic: { ipaddress: ipaddress, - platform: instance.platform.name.split('-')[0].downcase + platform: instance.platform.name.split('-')[0].downcase, + fqdn: fqdn }, normal: config[:attributes], run_list: config[:run_list] } end @@ -92,10 +109,10 @@ 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 = IpFinder.for_transport(transport, state).find_ips + ips = Finder.for_transport(transport, state).find_ips fail 'Unable to retrieve IPs' if ips.empty? ips end end end