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")
end
def address_free?(assigned_subnets, address)
assigned_subnets.find { |s| s.contains?(address) || s == address }
end
def find_address(subnet, assigned_subsubnets)
def find_address(subnet, assigned_subnets)
subnet.enumerate(Limit: 1E4, Short: true)[1..1E4].each do |cidr|
unless address_free?(assigned_subsubnets, cidr)
return cidr
end
assigned = assigned_subnets.find { |s| s.contains?(cidr) || s == cidr }
return cidr unless assigned
end
end