lib/chef/knife/winrm.rb in knife-windows-0.6.0 vs lib/chef/knife/winrm.rb in knife-windows-0.8.0.rc.0
- old
+ new
@@ -42,21 +42,20 @@
:default => "fqdn"
option :returns,
:long => "--returns CODES",
:description => "A comma delimited list of return codes which indicate success",
- :default => nil,
- :proc => Proc.new { |codes|
- Chef::Config[:knife][:returns] = codes.split(',').collect {|item| item.to_i} }
+ :default => "0"
option :manual,
:short => "-m",
:long => "--manual-list",
:boolean => true,
:description => "QUERY is a space separated list of servers",
:default => false
+
def session
session_opts = {}
session_opts[:logger] = Chef::Log.logger if Chef::Log.level == :debug
@session ||= begin
s = EventMachine::WinRM::Session.new(session_opts)
@@ -73,10 +72,16 @@
s
end
end
+ def success_return_codes
+ #Redundant if the CLI options parsing occurs
+ return [0] unless config[:returns]
+ return config[:returns].split(',').collect {|item| item.to_i}
+ end
+
# TODO: Copied from Knife::Core:GenericPresenter. Should be extracted
def extract_nested_value(data, nested_value_spec)
nested_value_spec.split(".").each do |attr|
if data.nil?
nil # don't get no method error on nil
@@ -94,10 +99,11 @@
end
( !data.kind_of?(Array) && data.respond_to?(:to_hash) ) ? data.to_hash : data
end
def configure_session
+
list = case config[:manual]
when true
@name_args[0].split(" ")
when false
r = Array.new
@@ -145,11 +151,18 @@
if config.keys.any? {|k| k.to_s =~ /kerberos/ }
session_opts[:transport] = :kerberos
session_opts[:basic_auth_only] = false
else
session_opts[:transport] = (Chef::Config[:knife][:winrm_transport] || config[:winrm_transport]).to_sym
- session_opts[:disable_sspi] = true
+ if Chef::Platform.windows? and session_opts[:transport] == :plaintext
+ # windows - force only encrypted communication
+ require 'winrm-s'
+ session_opts[:transport] = :sspinegotiate
+ session_opts[:disable_sspi] = false
+ else
+ session_opts[:disable_sspi] = true
+ end
if session_opts[:user] and
(not session_opts[:password])
session_opts[:password] = Chef::Config[:knife][:winrm_password] = config[:winrm_password] = get_password
end
@@ -238,18 +251,19 @@
end
def check_for_errors!(exit_codes)
exit_codes.each do |host, value|
- unless Chef::Config[:knife][:returns].include? value.to_i
+ unless success_return_codes.include? value.to_i
@exit_code = 1
ui.error "Failed to execute command on #{host} return code #{value}"
end
end
end
def run
+
STDOUT.sync = STDERR.sync = true
begin
@longest = 0