I'm trying to find all of the unassigned Elastic IPs using Fog, but it appears that the filtering in Fog::Compute::AWS::Addresses
doesn't allow you to filter on empty values.
For example,
ips = Fog::Compute.new(credentials).addresses.all('domain' => 'vpc', 'instance-id' => '')
returns an empty array, but
ips = Fog::Compute.new(credentials).addresses.all('domain' => 'vpc').find_all {|eip| eip.server.nil? }
results in the list I'm looking for. However, we have a large number of Elastic IPs, and the latter method is incredibly slow.
Is there any way to filter for empty values in Fog? Or maybe a more efficient way to comb through the results to get the list I'm looking for?
I couldn't find an exact answer to my question, but I found a faster way to accomplish my task. eip.server
will trigger Fog to attempt to look up the server resource, so if you can get faster results by using eip.server_id
instead. I.e.,
ips = Fog::Compute.new(credentials).addresses.all('domain' => 'vpc').find_all {|eip| eip.server_id.nil? }