create-lxc-config: refactor free_address
This commit is contained in:
parent
df90f83eb7
commit
05fac20909
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user