查找未分配的弹性IP [英] Find unassigned Elastic IPs
问题描述
我正在尝试使用Fog查找所有未分配的Elastic IP,但是看来Fog::Compute::AWS::Addresses
中的过滤不允许您过滤空值.
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.
例如,
ips = Fog::Compute.new(credentials).addresses.all('domain' => 'vpc', 'instance-id' => '')
返回一个空数组,但是
ips = Fog::Compute.new(credentials).addresses.all('domain' => 'vpc').find_all {|eip| eip.server.nil? }
得出我要查找的列表.但是,我们拥有大量的弹性IP,而后一种方法的速度却非常慢.
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?
推荐答案
我无法找到问题的确切答案,但是我找到了一种更快的方式来完成任务. eip.server
将触发Fog尝试查找服务器资源,因此如果您可以通过使用eip.server_id
来获得更快的结果.即
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? }
这篇关于查找未分配的弹性IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!