147
147
show (io:: IO , manager:: SSHManager ) = println (io, " SSHManager(machines=" , manager. machines, " )" )
148
148
149
149
150
- function launch_on_machine (manager:: SSHManager , machine, cnt, params, launched, launch_ntfy:: Condition )
150
+ function parse_machine (machine:: AbstractString )
151
+ hoststr = " "
152
+ portnum = nothing
153
+
154
+ if machine[begin ] == ' [' # ipv6 bracket notation (RFC 2732)
155
+ ipv6_end = findlast (' ]' , machine)
156
+ if ipv6_end == nothing
157
+ throw (ArgumentError (" invalid machine definition format string: invalid port format \" $machine_def \" " ))
158
+ end
159
+ hoststr = machine[begin + 1 : prevind (machine,ipv6_end)]
160
+ machine_def = split (machine[ipv6_end : end ] , ' :' )
161
+ else # ipv4
162
+ machine_def = split (machine, ' :' )
163
+ hoststr = machine_def[1 ]
164
+ end
165
+
166
+ if length (machine_def) > 2
167
+ throw (ArgumentError (" invalid machine definition format string: invalid port format \" $machine_def \" " ))
168
+ end
169
+
170
+ if length (machine_def) == 2
171
+ portstr = machine_def[2 ]
172
+
173
+ portnum = tryparse (Int, portstr)
174
+ if portnum == nothing
175
+ msg = " invalid machine definition format string: invalid port format \" $machine_def \" "
176
+ throw (ArgumentError (msg))
177
+ end
178
+
179
+ if portnum < 1 || portnum > 65535
180
+ msg = " invalid machine definition format string: invalid port number \" $machine_def \" "
181
+ throw (ArgumentError (msg))
182
+ end
183
+ end
184
+ (hoststr, portnum)
185
+ end
186
+
187
+ function launch_on_machine (manager:: SSHManager , machine:: AbstractString , cnt, params:: Dict , launched:: Array , launch_ntfy:: Condition )
151
188
dir = params[:dir ]
152
189
exename = params[:exename ]
153
190
exeflags = params[:exeflags ]
@@ -165,21 +202,8 @@ function launch_on_machine(manager::SSHManager, machine, cnt, params, launched,
165
202
end
166
203
exeflags = ` $exeflags --worker`
167
204
168
- machine_def = split (machine_bind[1 ], ' :' )
169
- # if this machine def has a port number, add the port information to the ssh flags
170
- if length (machine_def) > 2
171
- throw (ArgumentError (" invalid machine definition format string: invalid port format \" $machine_def \" " ))
172
- end
173
- host = machine_def[1 ]
174
- portopt = ` `
175
- if length (machine_def) == 2
176
- portstr = machine_def[2 ]
177
- if ! all (isdigit, portstr) || (p = parse (Int,portstr); p < 1 || p > 65535 )
178
- msg = " invalid machine definition format string: invalid port format \" $machine_def \" "
179
- throw (ArgumentError (msg))
180
- end
181
- portopt = ` -p $(machine_def[2 ]) `
182
- end
205
+ host, portnum = parse_machine (machine_bind[1 ])
206
+ portopt = portnum === nothing ? ` ` : ` -p $portnum `
183
207
sshflags = ` $(params[:sshflags ]) $portopt `
184
208
185
209
if tunnel
0 commit comments