@@ -68,6 +68,8 @@ class RToolsHCK
6868 WINRM_OPERATION_TIMEOUT = 9_999
6969 WINRM_RECIEVE_TIMEOUT = 99_999
7070 WINRM_RETRY_INTERVAL = 60
71+ WINRM_DEFAULT_PORT = 5985
72+ ETHER_DEFAULT_PORT = 4000
7173
7274 private
7375
@@ -111,18 +113,22 @@ def logger(level, progname = nil, &)
111113 #
112114 # +init_opts+:: Hash that has various initialize options to configure upon
113115 # initializing a RtoolsHCK object:
114- # :addr - Controller machine's IP address
115- # (default: 127.0.0.1)
116- # :user - The user name to use in order to connect via winrm to the
116+ # :addr - Controller/Studio machine's IP address
117+ # (default: 192.168.100.1)
118+ # (default is based on HLK-Setup-Script settings)
119+ # :port - The port to be used for the WinRM connection
120+ # (default: 5985)
121+ # :ether_port - The port to be used for the toolsHCK Ether connection
122+ # (default: 4000)
123+ # :user - The user name to use in order to connect via WinRM to the
117124 # guest
118125 # (default: Administrator)
119126 # :pass - The password of the user name specified
120127 # (default: PASSWORD)
121- # :port - The port to be used for the connection
122- # (default: 4000)
123- # :winrm_ports - The clients winrm connection ports as a hash
124- # (example: { 'Client' => port, ... })
125- # (default: { 'Cl1' => 4001, 'Cl2' => 4002 }
128+ # :clients_addrs - The clients WinRM connection ip and port (default: 5985) as a hash
129+ # (example: { 'Client' => { addr: '192.168.0.18', port: 4001 }, ... })
130+ # (default: { 'CL1' => { addr: '192.168.100.2' }, 'CL2' => { addr: '192.168.100.3' } })
131+ # (default is based on HLK-Setup-Script settings)
126132 # :json - JSON format the output of the action methods
127133 # (default: true)
128134 # :timeout - The action's timeout in seconds
@@ -153,11 +159,15 @@ def initialize(init_opts)
153159
154160 # init_opts initialization defaults
155161 INIT_OPTS_DEFAULTS = {
156- addr : '127.0.0.1' ,
162+ addr : '192.168.100.1' ,
163+ port : WINRM_DEFAULT_PORT ,
164+ ether_port : ETHER_DEFAULT_PORT ,
157165 user : 'Administrator' ,
158166 pass : 'PASSWORD' ,
159- port : 4000 ,
160- winrm_ports : { 'Cl1' => 4001 , 'Cl2' => 4002 } ,
167+ clients_addrs : {
168+ 'CL1' => { addr : '192.168.100.2' , port : WINRM_DEFAULT_PORT } ,
169+ 'CL2' => { addr : '192.168.100.3' , port : WINRM_DEFAULT_PORT }
170+ } ,
161171 json : true ,
162172 timeout : 60 ,
163173 logger : nil ,
@@ -169,6 +179,11 @@ def initialize(init_opts)
169179 def validate_init_opts ( init_opts )
170180 extra_keys = ( init_opts . keys - INIT_OPTS_DEFAULTS . keys )
171181 unless extra_keys . empty?
182+ if extra_keys . include? ( :winrm_ports )
183+ raise RToolsHCKError . new ( 'initialize' ) ,
184+ 'The :winrm_ports option is deprecated, use :clients_addrs instead.'
185+ end
186+
172187 raise RToolsHCKError . new ( 'initialize' ) ,
173188 "Undefined initialization options: #{ extra_keys . join ( ', ' ) } ."
174189 end
@@ -243,7 +258,8 @@ def load_instance_variables(init_opts)
243258 @user = init_opts [ :user ]
244259 @pass = init_opts [ :pass ]
245260 @port = init_opts [ :port ]
246- @winrm_ports = init_opts [ :winrm_ports ]
261+ @ether_port = init_opts [ :ether_port ]
262+ @clients_addrs = init_opts [ :clients_addrs ]
247263 @timeout = init_opts [ :timeout ]
248264 @json = init_opts [ :json ]
249265 @r_script_file = init_opts [ :r_script_file ]
@@ -263,7 +279,7 @@ def winrm_options_factory(addr, port, user, pass)
263279
264280 def load_winrm_ps
265281 logger ( 'debug' , 'initialize/winrm' ) { 'loading winrm shell...' }
266- @connection_options = winrm_options_factory ( @addr , 5985 , @user , @pass )
282+ @connection_options = winrm_options_factory ( @addr , @port || WINRM_DEFAULT_PORT , @user , @pass )
267283 @connection = WinRM ::Connection . new ( @connection_options )
268284 @winrm_ps = @connection . shell ( :powershell )
269285 run ( 'date' )
@@ -288,8 +304,16 @@ def run(cmd)
288304 end
289305
290306 def machine_connection ( machine )
291- listen_port = @winrm_ports [ machine ]
292- options = winrm_options_factory ( @addr , listen_port , @user , @pass )
307+ clients_addr = @clients_addrs [ machine ]
308+ if clients_addr . nil?
309+ raise RToolsHCKError . new ( 'machine_connection' ) ,
310+ "Unknown machine '#{ machine } '. Available machines: #{ @clients_addrs . keys . join ( ', ' ) } "
311+ end
312+
313+ options = winrm_options_factory (
314+ clients_addr [ :addr ] , clients_addr [ :port ] || WINRM_DEFAULT_PORT ,
315+ @user , @pass
316+ )
293317 WinRM ::Connection . new ( options )
294318 end
295319
@@ -326,7 +350,7 @@ def toolshck_ether_init_opts
326350 {
327351 winrm_connection_options : @connection_options ,
328352 server_addr : @addr ,
329- server_port : @port ,
353+ server_port : @ether_port || ETHER_DEFAULT_PORT ,
330354 operation_timeout : @timeout ,
331355 connection_timeout : TOOLSHCK_CONNECTION_TIMEOUT ,
332356 outp_dir : @outp_dir ,
@@ -388,7 +412,10 @@ def handle_action_exceptions(action, &block)
388412 log_action_call ( action , block . binding )
389413 handle_exceptions do
390414 yield
391- rescue RToolsHCKActionError => e
415+ # We can have ECONNREFUSED error due to direct connection to
416+ # clients instead of proxy through studio
417+ # Safety catch this exception, the action wrapper will retry if needed
418+ rescue RToolsHCKActionError , Errno ::ECONNREFUSED => e
392419 action_exception_handler ( e )
393420 end
394421 end
0 commit comments