lib/kitchen/provisioner/nodes.rb in kitchen-nodes-0.1.0.dev vs lib/kitchen/provisioner/nodes.rb in kitchen-nodes-0.2.0.dev
- old
+ new
@@ -16,13 +16,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.
require "kitchen"
require "kitchen/provisioner/chef_zero"
+require "net/ping"
module Kitchen
+ module Transport
+ class Winrm < Kitchen::Transport::Base
+ class Connection < Kitchen::Transport::Base::Connection
+ def node_session(retry_options = {})
+ session(retry_options)
+ end
+ end
+ end
+ end
+
module Provisioner
# Nodes provisioner for Kitchen.
#
# @author Matt Wrock <matt@mattwrock.com>
@@ -37,21 +48,31 @@
node_dir = File.join(config[:test_base_path], "nodes")
Dir.mkdir(node_dir) unless Dir.exist?(node_dir)
node_file = File.join(node_dir, "#{instance.name}.json")
state = Kitchen::StateFile.new(config[:kitchen_root], instance.name).read
+ ipaddress = get_reachable_guest_address(state) || state[:hostname]
node = {
:id => instance.name,
:automatic => {
- :ipaddress => state[:hostname]
+ :ipaddress => ipaddress
},
:run_list => config[:run_list]
}
File.open(node_file, 'w') do |out|
out << JSON.pretty_generate(node)
end
+ end
+
+ def get_reachable_guest_address(state)
+ instance.transport.connection(state).node_session.run_powershell_script("Get-NetIPConfiguration | % { $_.ipv4address.IPAddress}") do |address, _|
+ address = address.chomp unless address.nil?
+ next if address.nil? || address == "127.0.0.1"
+ return address if Net::Ping::External.new.ping(address)
+ end
+ return nil
end
end
end
end