Sha256: 862735f9164d1fe3c9a5c53f76bff55ce5045b508f0f2b6e4151acb8270094e9

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

#
# Author:: Adam Jacob (<adam@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, 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.
#

network Mash.new unless network
network[:interfaces] = Mash.new unless network[:interfaces]

require_plugin "hostname"
require_plugin "#{os}::network"

def find_ip_and_mac(addresses)
  ip = nil; mac = nil
  addresses.each do |addr|
    ip = addr["address"] if addr["family"].eql?("inet")
    mac = addr["address"] if addr["family"].eql?("lladdr")
    break if (ip and mac)
  end
  [ip, mac]
end

if attribute?("default_interface")
  im = find_ip_and_mac(network["interfaces"][iface]["addresses"])
  ipaddress im.shift
  macaddress im.shift
else
  network["interfaces"].keys.each do |iface|
    if network["interfaces"][iface]["encapsulation"].eql?("Ethernet")
      im = find_ip_and_mac(network["interfaces"][iface]["addresses"])
      ipaddress im.shift
      macaddress im.shift
      return if (ipaddress and macaddress)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opscode-ohai-0.1.2 lib/ohai/plugins/network.rb