28 lines
595 B
Plaintext
28 lines
595 B
Plaintext
|
#!/usr/bin/env ruby
|
||
|
require 'json'
|
||
|
require 'fileutils'
|
||
|
|
||
|
abort "Must run as root" unless Process.uid == 0
|
||
|
|
||
|
CONTAINER_DATA = "/etc/lxc/container.json"
|
||
|
|
||
|
data = JSON.load(File.open(CONTAINER_DATA))
|
||
|
containers = `lxc-ls -1`.split(/\n/)
|
||
|
|
||
|
modified = false
|
||
|
data["network"].each do |host, value|
|
||
|
unless containers.include?(host) or value["lxc"] == false
|
||
|
data["network"].delete(host)
|
||
|
modified = true
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if modified
|
||
|
FileUtils.cp(CONTAINER_DATA, CONTAINER_DATA + ".backup")
|
||
|
File.open(CONTAINER_DATA, "w+") do |f|
|
||
|
f.puts JSON.pretty_generate(data)
|
||
|
end
|
||
|
else
|
||
|
puts "Unchanged"
|
||
|
end
|