-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Currently the implementation creates hash of the current docker networks - Also adds a docker.network.managed_interfaces hash to correspond a docker network with real interface
- Loading branch information
Bob
committed
Aug 28, 2019
1 parent
4ca7fe8
commit 3cb2f9b
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'facter' | ||
require 'json' | ||
|
||
def interfaces | ||
Facter.value(:interfaces).split(',') | ||
end | ||
|
||
Facter.add(:docker) do | ||
setcode do | ||
if Facter::Util::Resolution.which('docker') | ||
docker = Hash.new | ||
docker['network'] = Hash.new | ||
docker['network']['managed_interfaces'] = Hash.new | ||
network_list = Facter::Util::Resolution.exec('docker network ls | tail -n +2') | ||
docker_network_names = Array.new | ||
network_list.each_line {|line| docker_network_names.push line.split[1] } | ||
docker_network_ids = Array.new | ||
network_list.each_line {|line| docker_network_ids.push line.split[0] } | ||
docker_network_names.each do |network| | ||
inspect = JSON.parse(Facter::Util::Resolution.exec("docker network inspect #{network}")) | ||
docker['network'][network] = inspect[0] | ||
network_id = docker['network'][network]['Id'][0..11] | ||
interfaces.each do |iface| | ||
docker['network']['managed_interfaces'][iface] = network if iface =~ /#{network_id}/ | ||
end | ||
end | ||
docker | ||
end | ||
end | ||
end |