blob: 425d03c24c14a5f965a28c62181a7cb952a89deb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# frozen_string_literal: true
#
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Ohai.plugin(:Docker) do
provides "docker"
depends "virtualization"
def docker_info_json
so = shell_out("docker info --format '{{json .}}'")
if so.exitstatus == 0
JSON.parse(so.stdout)
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Docker: Could not shell_out "docker info --format \'{{json .}}\'". Skipping plugin')
end
def docker_ohai_data(shellout_data)
docker Mash.new
docker[:version_string] = shellout_data["ServerVersion"]
docker[:version] = shellout_data["ServerVersion"].split("-")[0] if shellout_data["ServerVersion"] # guard this so missing data doesn't fail the run
docker[:runtimes] = shellout_data["Runtimes"]
docker[:root_dir] = shellout_data["DockerRootDir"]
docker[:containers] = {}
docker[:containers][:total] = shellout_data["Containers"]
docker[:containers][:running] = shellout_data["ContainersRunning"]
docker[:containers][:paused] = shellout_data["ContainersPaused"]
docker[:containers][:stopped] = shellout_data["ContainersStopped"]
docker[:plugins] = shellout_data["Plugins"]
docker[:networking] = {}
docker[:networking][:ipv4_forwarding] = shellout_data["IPv4Forwarding"]
docker[:networking][:bridge_nf_iptables] = shellout_data["BridgeNfIptables"]
docker[:networking][:bridge_nf_ipv6_iptables] = shellout_data["BridgeNfIp6tables"]
docker[:swarm] = shellout_data["Swarm"]
end
collect_data(:linux, :windows, :darwin) do
require "json" unless defined?(JSON)
if virtualization[:systems][:docker]
docker_ohai_data(docker_info_json)
end
end
end
|