\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef/embedded/lib/ruby/gems/2.7.0/gems/ohai-16.3.2/lib/ohai/plugins/aix/

Viewing File: virtualization.rb

#
# Author:: Julian C. Dunn (<jdunn@chef.io>)
# Author:: Isa Farnik (<isa@chef.io>)
# Copyright:: Copyright (c) 2013-2016 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(:Virtualization) do
  provides "virtualization", "virtualization/wpars"

  collect_data(:aix) do
    virtualization Mash.new

    so = shell_out("uname -L")
    lpar_no = so.stdout.split($/)[0].split(/\s/)[0]
    lpar_name = so.stdout.split($/)[0].split(/\s/)[1]

    unless lpar_no.to_i == -1 || (lpar_no.to_i == 1 && lpar_name == "NULL")
      virtualization[:lpar_no] = lpar_no
      virtualization[:lpar_name] = lpar_name
    end

    so = shell_out("uname -W")
    wpar_no = so.stdout.split($/)[0]
    if wpar_no.to_i > 0
      virtualization[:wpar_no] = wpar_no
    else
      # the below parses the output of lswpar in the long format
      so = shell_out("lswpar -L").stdout.scan(/={65}.*?(?:EXPORTED\n\n)+/m)
      wpars = Mash.new
      so.each do |wpar|
        wpar_name = wpar.lines[1].split[0]
        wpars[wpar_name] = Mash.new

        wpar.scan(/^[A-Z]{4,}.*?[A-Z\:0-9]$.*?\n\n/m).each do |section|

          # retrieve title of section
          title = section.lines.first[0..-2].downcase
          wpars[wpar_name][title] = Mash.new

          # discard trailing section newline+title
          # and save as array
          sections = section.lines[1..-2]

          sections.each do |line|
            case title
            when "network"
              next if /^Interface|^---/.match?(line)

              splat = line.strip.split
              key   = splat[0].downcase
              value = {
                        "address" => splat[1],
                        "netmask" => splat[2],
                        "broadcast" => splat[3],
                      }
              wpars[wpar_name][title][key] = value
            when "user-specified routes"
              next if /^Type|^---/.match?(line)

              splat = line.strip.split
              key   = splat[2].downcase
              value = {
                        "destination" => splat[0],
                        "gateway" => splat[1],
                      }
              wpars[wpar_name][title][key] = value
            when "file systems"
              next if /^MountPoint|^---/.match?(line)

              splat = line.strip.split
              key = splat[1].downcase
              value = {
                        "mountpoint" => splat[0],
                        "device" => splat[1],
                        "vfs" => splat[2],
                        "options" => splat[3].split(","),
                      }
              wpars[wpar_name][title][key] = value
            when "security settings"
              privileges ||= ""
              wpars[wpar_name][title]["Privileges"] ||= []

              if /^Privileges/.match?(line)
                privileges << line.split(":")[1].strip
              else
                privileges << line.strip
              end

              wpars[wpar_name][title]["Privileges"] += privileges.split(",")
            when "device exports"
              next if /^Name|^---/.match?(line)

              splat = line.strip.split
              key = splat[0].downcase
              value = {
                        "type" => splat[1],
                        "status" => splat[2],
                      }
              wpars[wpar_name][title][key] = value
            else
              # key-value pairs are handled here
              # such as GENERAL and RESOURCE-
              # CONTROL
              splat = line.strip.split(":")
              key   = splat[0].downcase
              value = splat[1..-1].join(", ").strip
              value = value.empty? ? nil : value
              case value
              when "yes"
                value = true
              when "no"
                value = false
              end
              wpars[wpar_name][title][key] = value
            end
          end
        end
        top_level = [
          "general.directory",
          "general.hostname",
          "general.private /usr",
          "general.type",
          "general.uuid",
          "resource controls.active",
          "network.en0.address",
        ]

        top_level.each do |attribute|
          evalstr = "wpars['#{wpar_name}']"
          breadcrumb = attribute.split(".")
          breadcrumb.each do |node|
            evalstr << "[\'#{node}\']"
          end
          wpars[wpar_name][breadcrumb[-1]] = eval evalstr # rubocop: disable Security/Eval
        end
      end
      virtualization[:wpars] = wpars unless wpars.empty?
    end
  end
end