Find unassigned Elastic IPs

心已入冬 提交于 2019-12-10 19:41:56

问题


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?


回答1:


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? }


来源:https://stackoverflow.com/questions/34384827/find-unassigned-elastic-ips

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!