winrm 2.2.3 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +13 -1
- data/.travis.yml +10 -11
- data/Gemfile +2 -3
- data/README.md +1 -1
- data/Rakefile +3 -4
- data/appveyor.yml +1 -2
- data/bin/rwinrm +90 -97
- data/changelog.md +5 -0
- data/lib/winrm.rb +3 -5
- data/lib/winrm/connection.rb +84 -86
- data/lib/winrm/connection_opts.rb +90 -91
- data/lib/winrm/exceptions.rb +14 -2
- data/lib/winrm/http/response_handler.rb +127 -96
- data/lib/winrm/http/transport.rb +462 -427
- data/lib/winrm/http/transport_factory.rb +1 -5
- data/lib/winrm/output.rb +1 -2
- data/lib/winrm/psrp/fragment.rb +0 -2
- data/lib/winrm/psrp/message.rb +1 -3
- data/lib/winrm/psrp/message_data.rb +0 -2
- data/lib/winrm/psrp/message_data/base.rb +0 -2
- data/lib/winrm/psrp/message_data/error_record.rb +0 -2
- data/lib/winrm/psrp/message_data/pipeline_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/pipeline_output.rb +48 -54
- data/lib/winrm/psrp/message_data/pipeline_state.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_host_call.rb +0 -2
- data/lib/winrm/psrp/message_data/runspacepool_state.rb +0 -2
- data/lib/winrm/psrp/message_data/session_capability.rb +0 -2
- data/lib/winrm/psrp/message_defragmenter.rb +2 -2
- data/lib/winrm/psrp/message_factory.rb +2 -3
- data/lib/winrm/psrp/message_fragmenter.rb +1 -3
- data/lib/winrm/psrp/powershell_output_decoder.rb +0 -2
- data/lib/winrm/psrp/receive_response_reader.rb +3 -5
- data/lib/winrm/psrp/uuid.rb +1 -2
- data/lib/winrm/shells/base.rb +6 -4
- data/lib/winrm/shells/cmd.rb +63 -65
- data/lib/winrm/shells/power_shell.rb +207 -202
- data/lib/winrm/shells/retryable.rb +44 -45
- data/lib/winrm/shells/shell_factory.rb +0 -2
- data/lib/winrm/version.rb +1 -3
- data/lib/winrm/wsmv/base.rb +0 -2
- data/lib/winrm/wsmv/cleanup_command.rb +1 -2
- data/lib/winrm/wsmv/close_shell.rb +1 -2
- data/lib/winrm/wsmv/command.rb +2 -3
- data/lib/winrm/wsmv/command_output.rb +2 -3
- data/lib/winrm/wsmv/command_output_decoder.rb +1 -2
- data/lib/winrm/wsmv/configuration.rb +0 -2
- data/lib/winrm/wsmv/create_pipeline.rb +0 -2
- data/lib/winrm/wsmv/create_shell.rb +2 -6
- data/lib/winrm/wsmv/header.rb +213 -215
- data/lib/winrm/wsmv/init_runspace_pool.rb +96 -95
- data/lib/winrm/wsmv/iso8601_duration.rb +0 -2
- data/lib/winrm/wsmv/keep_alive.rb +0 -2
- data/lib/winrm/wsmv/receive_response_reader.rb +128 -126
- data/lib/winrm/wsmv/send_data.rb +0 -2
- data/lib/winrm/wsmv/soap.rb +0 -2
- data/lib/winrm/wsmv/wql_pull.rb +54 -56
- data/lib/winrm/wsmv/wql_query.rb +98 -99
- data/lib/winrm/wsmv/write_stdin.rb +0 -2
- data/tests/integration/auth_timeout_spec.rb +0 -1
- data/tests/integration/cmd_spec.rb +2 -3
- data/tests/integration/issue_59_spec.rb +0 -1
- data/tests/integration/powershell_spec.rb +4 -5
- data/tests/integration/spec_helper.rb +3 -6
- data/tests/integration/transport_spec.rb +0 -1
- data/tests/integration/wql_spec.rb +33 -34
- data/tests/matchers.rb +2 -3
- data/tests/spec/configuration_spec.rb +0 -1
- data/tests/spec/connection_spec.rb +0 -2
- data/tests/spec/exception_spec.rb +0 -1
- data/tests/spec/http/transport_factory_spec.rb +1 -3
- data/tests/spec/http/transport_spec.rb +0 -1
- data/tests/spec/output_spec.rb +4 -3
- data/tests/spec/psrp/fragment_spec.rb +0 -2
- data/tests/spec/psrp/message_data/base_spec.rb +0 -2
- data/tests/spec/psrp/message_data/error_record_spec.rb +0 -2
- data/tests/spec/psrp/message_data/pipeline_host_call_spec.rb +0 -2
- data/tests/spec/psrp/message_data/pipeline_output_spec.rb +0 -2
- data/tests/spec/psrp/message_data/pipeline_state_spec.rb +0 -2
- data/tests/spec/psrp/message_data/runspace_pool_host_call_spec.rb +0 -2
- data/tests/spec/psrp/message_data/runspacepool_state_spec.rb +0 -2
- data/tests/spec/psrp/message_data/session_capability_spec.rb +0 -2
- data/tests/spec/psrp/message_data_spec.rb +0 -2
- data/tests/spec/psrp/message_defragmenter_spec.rb +0 -2
- data/tests/spec/psrp/message_fragmenter_spec.rb +0 -2
- data/tests/spec/psrp/powershell_output_decoder_spec.rb +0 -2
- data/tests/spec/psrp/psrp_message_spec.rb +10 -7
- data/tests/spec/psrp/recieve_response_reader_spec.rb +0 -2
- data/tests/spec/psrp/uuid_spec.rb +2 -2
- data/tests/spec/response_handler_spec.rb +69 -61
- data/tests/spec/shells/base_spec.rb +7 -5
- data/tests/spec/shells/cmd_spec.rb +4 -4
- data/tests/spec/shells/powershell_spec.rb +221 -175
- data/tests/spec/spec_helper.rb +0 -1
- data/tests/spec/stubs/responses/get_omi_command_output_response.xml.erb +23 -0
- data/tests/spec/stubs/responses/get_omi_command_output_response_not_done.xml.erb +24 -0
- data/tests/spec/stubs/responses/get_omi_config_response.xml +45 -0
- data/tests/spec/stubs/responses/get_omi_powershell_keepalive_response.xml.erb +33 -0
- data/tests/spec/stubs/responses/open_shell_omi.xml +43 -0
- data/tests/spec/stubs/responses/soap_fault_omi.xml +31 -0
- data/tests/spec/wsmv/cleanup_command_spec.rb +0 -2
- data/tests/spec/wsmv/close_shell_spec.rb +0 -2
- data/tests/spec/wsmv/command_output_decoder_spec.rb +0 -2
- data/tests/spec/wsmv/command_output_spec.rb +1 -3
- data/tests/spec/wsmv/command_spec.rb +0 -2
- data/tests/spec/wsmv/configuration_spec.rb +0 -2
- data/tests/spec/wsmv/create_pipeline_spec.rb +2 -3
- data/tests/spec/wsmv/create_shell_spec.rb +6 -5
- data/tests/spec/wsmv/init_runspace_pool_spec.rb +38 -36
- data/tests/spec/wsmv/keep_alive_spec.rb +4 -4
- data/tests/spec/wsmv/receive_response_reader_spec.rb +124 -123
- data/tests/spec/wsmv/send_data_spec.rb +4 -4
- data/tests/spec/wsmv/wql_query_spec.rb +11 -13
- data/tests/spec/wsmv/write_stdin_spec.rb +0 -2
- data/winrm.gemspec +11 -12
- metadata +73 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cd8c4887729128df19666c0a4f2b099b088261f5cb60ecb1b2adf52810188710
|
4
|
+
data.tar.gz: 8711a914b783a6f6a6a5f5f8eb15ad74d4798dcf29242ff4b3b59679858e0c9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87eb8b34f189b70da6d6fd21e70142892cd9a8485f952a649229fb8cde0f073796af6ed9eb904e6c6b2f6d270ee901ec3d8ad69c36cd575e0b8def04faf5f9c9
|
7
|
+
data.tar.gz: eaf8d672f6f53d62029d41452cfeda2f1c9fba0164528ce057376b1ceb8805b5deb5dfd76d320c4f4eac695c66f3ac517460fbe72ca7de1b0a899bacb7cf9c91
|
data/.rubocop.yml
CHANGED
@@ -10,8 +10,17 @@ Style/Encoding:
|
|
10
10
|
Style/NumericLiterals:
|
11
11
|
Enabled: false
|
12
12
|
|
13
|
+
Layout/EndOfLine:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Layout/IndentHeredoc:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/BlockLength:
|
20
|
+
Max: 200
|
21
|
+
|
13
22
|
Metrics/LineLength:
|
14
|
-
Max:
|
23
|
+
Max: 120
|
15
24
|
|
16
25
|
Metrics/MethodLength:
|
17
26
|
Max: 20
|
@@ -19,6 +28,9 @@ Metrics/MethodLength:
|
|
19
28
|
ModuleLength:
|
20
29
|
Max: 250
|
21
30
|
|
31
|
+
Naming/HeredocDelimiterNaming:
|
32
|
+
Enabled: false
|
33
|
+
|
22
34
|
ClassLength:
|
23
35
|
Max: 250
|
24
36
|
|
data/.travis.yml
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
- master
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.2.0
|
4
|
+
before_install:
|
5
|
+
- gem update bundler
|
6
|
+
|
7
|
+
# This prevents testing branches that are created just for PRs
|
8
|
+
branches:
|
9
|
+
only:
|
10
|
+
- master
|
data/Gemfile
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
data/README.md
CHANGED
@@ -72,7 +72,7 @@ The `:negotiate` transport uses the [rubyntlm gem](https://github.com/WinRb/ruby
|
|
72
72
|
### `:ssl`
|
73
73
|
```ruby
|
74
74
|
WinRM::Connection.new(
|
75
|
-
endpoint: 'https://myhost:
|
75
|
+
endpoint: 'https://myhost:5986/wsman',
|
76
76
|
transport: :ssl,
|
77
77
|
user: 'administrator',
|
78
78
|
password: 'Pass@word1'
|
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require 'rubygems'
|
3
2
|
require 'bundler/setup'
|
4
3
|
require 'rspec/core/rake_task'
|
@@ -6,7 +5,7 @@ require 'rubocop/rake_task'
|
|
6
5
|
require 'bundler/gem_tasks'
|
7
6
|
|
8
7
|
# Change to the directory of this file.
|
9
|
-
Dir.chdir(File.expand_path(
|
8
|
+
Dir.chdir(File.expand_path(__dir__))
|
10
9
|
|
11
10
|
desc 'Open a Pry console for this library'
|
12
11
|
task :console do
|
@@ -29,6 +28,6 @@ end
|
|
29
28
|
|
30
29
|
RuboCop::RakeTask.new
|
31
30
|
|
32
|
-
task default: [
|
31
|
+
task default: %i[spec rubocop]
|
33
32
|
|
34
|
-
task all: [
|
33
|
+
task all: %i[default integration]
|
data/appveyor.yml
CHANGED
@@ -11,7 +11,7 @@ environment:
|
|
11
11
|
user_key: c:\projects\winrm\key.pem
|
12
12
|
|
13
13
|
matrix:
|
14
|
-
- ruby_version: "
|
14
|
+
- ruby_version: "22"
|
15
15
|
winrm_endpoint: http://localhost:5985/wsman
|
16
16
|
|
17
17
|
clone_folder: c:\projects\winrm
|
@@ -40,7 +40,6 @@ install:
|
|
40
40
|
- ps: Write-Host $env:PATH
|
41
41
|
- ps: ruby --version
|
42
42
|
- ps: gem --version
|
43
|
-
- ps: gem install bundler --quiet --no-ri --no-rdoc
|
44
43
|
- ps: bundler --version
|
45
44
|
|
46
45
|
build_script:
|
data/bin/rwinrm
CHANGED
@@ -1,97 +1,90 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require '
|
23
|
-
require '
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puts '
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
options
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
options[:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
options[:
|
47
|
-
options[:
|
48
|
-
|
49
|
-
options
|
50
|
-
rescue StandardError => e
|
51
|
-
puts e.message
|
52
|
-
help_msg
|
53
|
-
exit 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def repl(options)
|
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
|
-
puts e.message
|
92
|
-
exit 1
|
93
|
-
end
|
94
|
-
|
95
|
-
repl(parse_options)
|
96
|
-
|
97
|
-
# rubocop:enable all
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2014 Shawn Neal <sneal@sneal.net>
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
# rubocop:disable all
|
18
|
+
|
19
|
+
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
20
|
+
|
21
|
+
require 'readline'
|
22
|
+
require 'io/console'
|
23
|
+
require 'winrm'
|
24
|
+
|
25
|
+
def help_msg
|
26
|
+
puts 'Usage: rwinrm user@host'
|
27
|
+
puts ''
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_options
|
31
|
+
options = {}
|
32
|
+
fail 'Missing required options' unless ARGV.length == 1
|
33
|
+
|
34
|
+
m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
|
35
|
+
fail "#{ARGV[0]} is an invalid host" unless m
|
36
|
+
options[:user] = m[:user]
|
37
|
+
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"
|
38
|
+
|
39
|
+
# Get the password
|
40
|
+
print 'Password: '
|
41
|
+
options[:password] = STDIN.noecho(&:gets).chomp
|
42
|
+
puts
|
43
|
+
|
44
|
+
# Set some defaults required by WinRM WS
|
45
|
+
options[:transport] = :plaintext
|
46
|
+
options[:basic_auth_only] = true
|
47
|
+
options[:operation_timeout] = 3600
|
48
|
+
|
49
|
+
options
|
50
|
+
rescue StandardError => e
|
51
|
+
puts e.message
|
52
|
+
help_msg
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def repl(options)
|
57
|
+
shell = nil
|
58
|
+
|
59
|
+
client = WinRM::Connection.new(options)
|
60
|
+
shell = client.shell(:powershell)
|
61
|
+
prompt = "PS #{ARGV[0]}> "
|
62
|
+
|
63
|
+
while (buf = Readline.readline(prompt, true))
|
64
|
+
if buf =~ /^exit/
|
65
|
+
shell.close
|
66
|
+
shell = nil
|
67
|
+
exit 0
|
68
|
+
else
|
69
|
+
shell.run(buf) do |stdout, stderr|
|
70
|
+
$stdout.write stdout
|
71
|
+
$stderr.write stderr
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
rescue Interrupt
|
76
|
+
puts 'exiting'
|
77
|
+
# ctrl-c
|
78
|
+
rescue WinRM::WinRMAuthorizationError
|
79
|
+
puts 'Authentication failed, bad user name or password'
|
80
|
+
exit 1
|
81
|
+
rescue StandardError => e
|
82
|
+
puts e.message
|
83
|
+
exit 1
|
84
|
+
ensure
|
85
|
+
shell.close unless shell.nil?
|
86
|
+
end
|
87
|
+
|
88
|
+
repl(parse_options)
|
89
|
+
|
90
|
+
# rubocop:enable all
|
data/changelog.md
CHANGED
data/lib/winrm.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
#
|
3
1
|
# Copyright 2010 Dan Wanek <dan.wanek@gmail.com>
|
4
2
|
#
|
5
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -30,9 +28,9 @@ module WinRM
|
|
30
28
|
Logging.logger.root.appenders = Logging.appenders.stderr
|
31
29
|
rescue ArgumentError
|
32
30
|
# This means that the logging level wasn't valid
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
warn "Invalid WINRM_LOG level is set: #{ENV['WINRM_LOG']}"
|
32
|
+
warn ''
|
33
|
+
warn 'Please use one of the standard log levels: ' \
|
36
34
|
'debug, info, warn, or error'
|
37
35
|
end
|
38
36
|
end
|
data/lib/winrm/connection.rb
CHANGED
@@ -1,86 +1,84 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
require_relative '
|
18
|
-
require_relative '
|
19
|
-
require_relative '
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
#
|
37
|
-
# @
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
end
|
86
|
-
end
|
1
|
+
# Copyright 2016 Shawn Neal <sneal@sneal.net>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require_relative 'connection_opts'
|
16
|
+
require_relative 'http/transport_factory'
|
17
|
+
require_relative 'shells/shell_factory'
|
18
|
+
require_relative 'wsmv/wql_query'
|
19
|
+
require_relative 'wsmv/wql_pull'
|
20
|
+
|
21
|
+
module WinRM
|
22
|
+
# WinRM connection used to establish a session with the remote WinRM service.
|
23
|
+
class Connection
|
24
|
+
# Creates a new WinRM connection
|
25
|
+
# See the ConnectionOpts class for connection options.
|
26
|
+
def initialize(connection_opts)
|
27
|
+
configure_connection_opts(connection_opts)
|
28
|
+
configure_logger
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_accessor :logger
|
32
|
+
|
33
|
+
# Creates a new shell on the remote Windows server associated with
|
34
|
+
# this connection.
|
35
|
+
# @param shell_type [Symbol] The shell type :cmd or :powershell
|
36
|
+
# @param shell_opts [Hash] Options targeted for the created shell
|
37
|
+
# @return [Shell] PowerShell or Cmd shell instance.
|
38
|
+
def shell(shell_type, shell_opts = {})
|
39
|
+
shell = shell_factory.create_shell(shell_type, shell_opts)
|
40
|
+
if block_given?
|
41
|
+
begin
|
42
|
+
yield shell
|
43
|
+
ensure
|
44
|
+
shell.close
|
45
|
+
end
|
46
|
+
else
|
47
|
+
shell
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Executes a WQL query against the WinRM connection
|
52
|
+
# @param wql [String] The wql query
|
53
|
+
# @param namespace [String] namespace for query - default is root/cimv2/*
|
54
|
+
# @return [Hash] Hash representation of wql query response (Hash is empty if a block is given)
|
55
|
+
# @yeild [type, item] Yields the time name and item for every item
|
56
|
+
def run_wql(wql, namespace = 'root/cimv2/*', &block)
|
57
|
+
query = WinRM::WSMV::WqlQuery.new(transport, @connection_opts, wql, namespace)
|
58
|
+
query.process_response(transport.send_request(query.build), &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def configure_connection_opts(connection_opts)
|
64
|
+
@connection_opts = ConnectionOpts.create_with_defaults(connection_opts)
|
65
|
+
end
|
66
|
+
|
67
|
+
def configure_logger
|
68
|
+
@logger = Logging.logger[self]
|
69
|
+
logger.level = :warn
|
70
|
+
logger.add_appenders(Logging.appenders.stdout)
|
71
|
+
end
|
72
|
+
|
73
|
+
def shell_factory
|
74
|
+
@shell_factory ||= WinRM::Shells::ShellFactory.new(@connection_opts, transport, logger)
|
75
|
+
end
|
76
|
+
|
77
|
+
def transport
|
78
|
+
@transport ||= begin
|
79
|
+
transport_factory = WinRM::HTTP::TransportFactory.new
|
80
|
+
transport_factory.create_transport(@connection_opts)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|