Class: Chef::Knife::Winrm
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::Winrm
- Includes:
- KnifeWindowsBase, WinrmCommandSharedFunctions
- Defined in:
- lib/chef/knife/winrm.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
writeonly
Sets the attribute password.
Instance Method Summary collapse
- #execute_remote_command ⇒ Object
-
#extract_nested_value(data, nested_value_spec) ⇒ Object
TODO: Copied from Knife::Core:GenericPresenter.
- #relay_winrm_command(command) ⇒ Object
- #run ⇒ Object
Methods included from KnifeWindowsBase
Methods included from WinrmCommandSharedFunctions
Instance Attribute Details
#password=(value) ⇒ Object (writeonly)
Sets the attribute password
46 47 48 |
# File 'lib/chef/knife/winrm.rb', line 46 def password=(value) @password = value end |
Instance Method Details
#execute_remote_command ⇒ Object
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 93 94 95 |
# File 'lib/chef/knife/winrm.rb', line 63 def execute_remote_command begin case @name_args[1] when "interactive" interactive else relay_winrm_command(@name_args[1..-1].join(" ")) if config[:returns] check_for_errors! end # Knife seems to ignore the return value of this method, # so we exit to force the process exit code for this # subcommand if returns is set exit @exit_code if @exit_code && @exit_code != 0 @exit_code || 0 end rescue WinRM::WinRMHTTPTransportError, WinRM::WinRMAuthorizationError => e if (e) if ! config[:suppress_auth_failure] # Display errors if the caller hasn't opted to retry ui.error "Failed to authenticate to #{@name_args[0].split(" ")} as #{locate_config_value(:winrm_user)}" ui.info "Response: #{e.}" ui.info get_failed_authentication_hint raise e end @exit_code = 401 else raise e end end end |
#extract_nested_value(data, nested_value_spec) ⇒ Object
TODO: Copied from Knife::Core:GenericPresenter. Should be extracted
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/chef/knife/winrm.rb', line 105 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 elsif data.respond_to?(attr.to_sym) data = data.send(attr.to_sym) elsif data.respond_to?(:[]) data = data[attr] else data = begin data.send(attr.to_sym) rescue NoMethodError nil end end end ( !data.kind_of?(Array) && data.respond_to?(:to_hash) ) ? data.to_hash : data end |
#relay_winrm_command(command) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/chef/knife/winrm.rb', line 97 def relay_winrm_command(command) Chef::Log.debug(command) @winrm_sessions.each do |s| s.relay_command(command) end end |
#run ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/chef/knife/winrm.rb', line 55 def run STDOUT.sync = STDERR.sync = true configure_session validate_password execute_remote_command end |