summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-01-29 15:33:15 -0800
committerTim Smith <tsmith@chef.io>2018-02-15 11:04:39 -0800
commit52a3878b8b167aee8700d292fadf051fca9ee020 (patch)
tree50ae91c6faf8e34ca20b476ed407cf84198d3f95
parentb756590d05722d0ca66b684a2822256d98fece6b (diff)
downloadohai-52a3878b8b167aee8700d292fadf051fca9ee020.tar.gz
Add docker plugin
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/docker.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/ohai/plugins/docker.rb b/lib/ohai/plugins/docker.rb
new file mode 100644
index 00000000..5c544185
--- /dev/null
+++ b/lib/ohai/plugins/docker.rb
@@ -0,0 +1,57 @@
+#
+# Copyright:: 2018 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
+ require "json"
+
+ provides "docker"
+ depends "virtualization"
+
+ def docker_info_json
+ so = shell_out("docker info --format '{{json .}}'")
+ if so.exitstatus == 0
+ return JSON.parse(so.stdout)
+ end
+ rescue Ohai::Exceptions::Exec
+ Ohai::Log.debug('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 do
+ if virtualization[:systems][:docker]
+ docker_ohai_data(docker_info_json)
+ end
+ end
+end