Gitlab Community Edition Instance

Skip to content
Snippets Groups Projects
docker.rb 1.78 KiB
Newer Older
#
# Docker facts
#

$docker_containers = ''
$docker_containers_running = ''
$docker_containers_paused = ''
$docker_containers_stopped = ''
$docker_images = ''
$docker_version = ''

$test_docker=system("which docker")
if $test_docker != 0
  exit
end

$docker_info = %x(docker info 2>/dev/null)
$docker_info.each_line do |line|
  if (line[/^Containers/])
    $docker_containers = line[/^Containers:\s*([0-9]*)/,1].strip
  end
  if (line[/^\sRunning/])
    $docker_containers_running = line[/^\sRunning:\s*([0-9]*)/,1].strip
  end
  if (line[/^\sPaused/])
    $docker_containers_paused = line[/^\sPaused:\s*([0-9]*)/,1].strip
  end
  if (line[/^\sStopped/])
    $docker_containers_stopped = line[/^\sStopped:\s*([0-9]*)/,1].strip
  end
  if (line[/^Images/])
    $docker_containers_images = line[/^Images:\s*([0-9]*)/,1].strip
  end
  if (line[/^Server\sVersion/])
    $docker_version = line[/^Server\sVersion:\s*([0-9.]*)/,1].strip
  end
end

$docker_compose_info = %x(docker-compose version 2>/dev/null)
$docker_compose_info.each_line do |line|
  if (line[/^docker-compose version/])
    $docker_compose_version = line[/^docker-compose version\s([0-9]*)/,1].strip
  end
end

Facter.add("docker_containers") do
  setcode do
    "#{$docker_containers}"
  end
end
Facter.add("docker_containers_running") do
  setcode do
    "#{$docker_containers_running}"
  end
end
Facter.add("docker_containers_paused") do
  setcode do
    "#{$docker_containers_paused}"
  end
end
Facter.add("docker_containers_stopped") do
  setcode do
    "#{$docker_containers_stopped}"
  end
end
Facter.add("docker_images") do
  setcode do
    "#{$docker_images}"
  end
end
Facter.add("docker_version") do
  setcode do
    "#{$docker_version}"
  end
end

Facter.add("docker_compose_version") do
  setcode do
    "#{$docker_compose_version}"
  end
end