lxc-config/hooks/cleanup-lxc-config

21 lines
376 B
Ruby
Executable File

#!/usr/bin/env ruby
require_relative "lib/lxc"
registry = Lxc::Registry.new
containers = `lxc-ls -1`.split(/\n/)
modified = false
network = registry.data["network"] || {}
network.each do |host, value|
unless containers.include?(host) or value["lxc"] == false
network.delete(host)
modified = true
end
end
if modified
registry.write
else
puts "Unchanged"
end