@@ -263,88 +263,20 @@ def cloud_init_volume_name
263
263
def addresses ( service_arg = service , options = { } )
264
264
mac = self . mac
265
265
266
- # Aug 24 17:34:41 juno arpwatch: new station 10.247.4.137 52:54:00:88:5a:0a eth0.4
267
- # Aug 24 17:37:19 juno arpwatch: changed ethernet address 10.247.4.137 52:54:00:27:33:00 (52:54:00:88:5a:0a) eth0.4
268
- # Check if another ip_command string was provided
269
- ip_command_global = service_arg . ip_command . nil? ? 'grep $mac /var/log/arpwatch.log|sed -e "s/new station//"|sed -e "s/changed ethernet address//g" |sed -e "s/reused old ethernet //" |tail -1 |cut -d ":" -f 4-| cut -d " " -f 3' : service_arg . ip_command
270
- ip_command_local = options [ :ip_command ] . nil? ? ip_command_global : options [ :ip_command ]
271
-
272
- ip_command = "mac=#{ mac } ; server_name=#{ name } ; " +ip_command_local
273
-
274
- ip_address = nil
275
-
276
- if service_arg . uri . ssh_enabled?
277
-
278
- # Retrieve the parts we need from the service to setup our ssh options
279
- user = service_arg . uri . user #could be nil
280
- host = service_arg . uri . host
281
- keyfile = service_arg . uri . keyfile
282
- port = service_arg . uri . port
283
-
284
- # Setup the options
285
- ssh_options = { }
286
- ssh_options [ :keys ] = [ keyfile ] unless keyfile . nil?
287
- ssh_options [ :port ] = port unless keyfile . nil?
288
- ssh_options [ :paranoid ] = true if service_arg . uri . no_verify?
289
-
290
- begin
291
- result = Fog ::SSH . new ( host , user , ssh_options ) . run ( ip_command )
292
- rescue Errno ::ECONNREFUSED
293
- raise Fog ::Errors ::Error . new ( "Connection was refused to host #{ host } to retrieve the ip_address for #{ mac } " )
294
- rescue Net ::SSH ::AuthenticationFailed
295
- raise Fog ::Errors ::Error . new ( "Error authenticating over ssh to host #{ host } and user #{ user } " )
296
- end
297
-
298
- # Check for a clean exit code
299
- if result . first . status == 0
300
- ip_address = result . first . stdout . strip
301
- else
302
- # We got a failure executing the command
303
- raise Fog ::Errors ::Error . new ( "The command #{ ip_command } failed to execute with a clean exit code" )
304
- end
305
-
306
- else
307
- # It's not ssh enabled, so we assume it is
308
- if service_arg . uri . transport =="tls"
309
- raise Fog ::Errors ::Error . new ( "TlS remote transport is not currently supported, only ssh" )
310
- end
311
-
312
- # Execute the ip_command locally
313
- # Initialize empty ip_address string
314
- ip_address = ""
315
-
316
- IO . popen ( "#{ ip_command } " ) do |p |
317
- p . each_line do |l |
318
- ip_address +=l
319
- end
320
- status = Process . waitpid2 ( p . pid ) [ 1 ] . exitstatus
321
- if status !=0
322
- raise Fog ::Errors ::Error . new ( "The command #{ ip_command } failed to execute with a clean exit code" )
266
+ ip_address = nil
267
+ nic = self . nics . find { |nic | nic . mac ==mac }
268
+ if !nic . nil?
269
+ Fog ::Compute [ :libvirt ] . networks . all . each do |net |
270
+ if net . name == nic . network
271
+ leases = net . dhcp_leases ( mac , 0 )
272
+ # Assume the lease expiring last is the current IP address
273
+ ip_address = leases . sort_by { |lse | lse [ "expirytime" ] } . last [ "ipaddr" ] if !leases . empty?
274
+ break
323
275
end
324
276
end
325
-
326
- #Strip any new lines from the string
327
- ip_address = ip_address . chomp
328
- end
329
-
330
- # The Ip-address command has been run either local or remote now
331
-
332
- if ip_address ==""
333
- #The grep didn't find an ip address result"
334
- ip_address = nil
335
- else
336
- # To be sure that the command didn't return another random string
337
- # We check if the result is an actual ip-address
338
- # otherwise we return nil
339
- unless ip_address =~/^(\d {1,3}\. ){3}\d {1,3}$/
340
- raise Fog ::Errors ::Error . new (
341
- "The result of #{ ip_command } does not have valid ip-address format\n " +
342
- "Result was: #{ ip_address } \n "
343
- )
344
- end
345
277
end
346
278
347
- return { :public => [ ip_address ] , :private => [ ip_address ] }
279
+ return { :public => [ ip_address ] , :private => [ ip_address ] }
348
280
end
349
281
350
282
def ip_address ( key )
0 commit comments