create-lxc-config: refactor free_address

This commit is contained in:
Jörg Thalheim 2015-01-17 20:31:40 +00:00
parent df90f83eb7
commit 05fac20909

View File

@ -11,15 +11,10 @@ def try_env(key)
ENV[key] or abort("enviroment variable '#{key}' not set") ENV[key] or abort("enviroment variable '#{key}' not set")
end end
def address_free?(assigned_subnets, address) def find_address(subnet, assigned_subnets)
assigned_subnets.find { |s| s.contains?(address) || s == address }
end
def find_address(subnet, assigned_subsubnets)
subnet.enumerate(Limit: 1E4, Short: true)[1..1E4].each do |cidr| subnet.enumerate(Limit: 1E4, Short: true)[1..1E4].each do |cidr|
unless address_free?(assigned_subsubnets, cidr) assigned = assigned_subnets.find { |s| s.contains?(cidr) || s == cidr }
return cidr return cidr unless assigned
end
end end
end end