42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/chef/knife/wsman_test.rb', line 42
def verify_wsman_accessiblity_for_nodes
error_count = 0
@winrm_sessions.each do |item|
Chef::Log.debug("checking for WSMAN availability at #{item.endpoint}")
xml = '<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:wsmid="http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd"><s:Header/><s:Body><wsmid:Identify/></s:Body></s:Envelope>'
= {
'WSMANIDENTIFY' => 'unauthenticated',
'Content-Type' => 'application/soap+xml; charset=UTF-8'
}
output_object = Chef::Knife::WsmanEndpoint.new(item.host, item.port, item.endpoint)
error_message = nil
begin
client = HTTPClient.new
response = client.post(item.endpoint, xml, )
rescue Exception => e
error_message = e.message
else
ui.msg "Connected successfully to #{item.host} at #{item.endpoint}."
output_object.response_status_code = response.status_code
end
if response.nil? || output_object.response_status_code != 200
error_message = "No valid WSMan endoint listening at #{item.endpoint}."
else
require 'nokogiri'
doc = Nokogiri::XML response.body
namespace = 'http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.xsd'
output_object.protocol_version = doc.xpath('//wsmid:ProtocolVersion', 'wsmid' => namespace).text
output_object.product_version = doc.xpath('//wsmid:ProductVersion', 'wsmid' => namespace).text
output_object.product_vendor = doc.xpath('//wsmid:ProductVendor', 'wsmid' => namespace).text
if output_object.protocol_version.to_s.strip.length == 0
error_message = "Endpoint #{item.endpoint} on #{item.host} does not appear to be a WSMAN endpoint."
end
end
unless error_message.nil?
ui.warn "Failed to connect to #{item.host} at #{item.endpoint}."
output_object.error_message = error_message
error_count += 1
end
if config[:verbosity] >= 1
output(output_object)
end
end
if error_count > 0
ui.error "Failed to connect to #{error_count} nodes."
exit 1
end
end
|