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")
|
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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user