简体   繁体   中英

Find unassigned Elastic IPs

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. Ie,

ips = Fog::Compute.new(credentials).addresses.all('domain' => 'vpc').find_all {|eip| eip.server_id.nil? }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM