lxc-config/hooks/cleanup-lxc-config

21 lines
375 B
Plaintext
Raw Normal View History

2014-08-18 08:29:43 +00:00
#!/usr/bin/env ruby
2015-01-30 08:08:18 +00:00
require_relative "lib/lxc"
2014-08-18 08:29:43 +00:00
2015-01-30 08:08:18 +00:00
registry = Lxc::Registry.new
2014-08-18 08:29:43 +00:00
containers = `lxc-ls -1`.split(/\n/)
modified = false
2015-01-30 08:08:18 +00:00
network = registry.data["network"] || {}
network.each do |host, value|
2014-08-18 08:29:43 +00:00
unless containers.include?(host) or value["lxc"] == false
2015-01-30 08:08:18 +00:00
network.delete(host)
2014-08-18 08:29:43 +00:00
modified = true
end
end
if modified
2015-08-05 15:33:37 +00:00
registry.save
2014-08-18 08:29:43 +00:00
else
puts "Unchanged"
end