Class: Rubyipmi::Freeipmi::Lan

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyipmi/freeipmi/commands/lan.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Lan

Returns a new instance of Lan.



7
8
9
10
11
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 7

def initialize(opts)
  @config = Rubyipmi::Freeipmi::BmcConfig.new(opts)
  @info = {}
  @channel = 2
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



4
5
6
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 4

def channel
  @channel
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 5

def config
  @config
end

#infoObject

Returns the value of attribute info.



3
4
5
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 3

def info
  @info
end

Instance Method Details

#dhcp?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 22

def dhcp?
  info.fetch("ip_address_source", nil).match(/dhcp/i) != nil
end

#gatewayObject



42
43
44
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 42

def gateway
  info.fetch("default_gateway_ip_address", nil)
end

#gateway=(address) ⇒ Object



79
80
81
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 79

def gateway=(address)
  @config.setsection("Lan_Conf", "Default_Gateway_IP_Address", address) if validaddr?(address)
end

#ipObject



30
31
32
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 30

def ip
  info.fetch("ip_address", nil)
end

#ip=(address) ⇒ Object



71
72
73
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 71

def ip=(address)
  @config.setsection("Lan_Conf", "IP_Address", address) if validaddr?(address)
end

#macObject



34
35
36
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 34

def mac
  info.fetch("mac_address", nil)
end

#netmaskObject



38
39
40
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 38

def netmask
  info.fetch("subnet_mask", nil)
end

#netmask=(netmask) ⇒ Object



75
76
77
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 75

def netmask=(netmask)
  @config.setsection("Lan_Conf", "Subnet_Mask", netmask) if validaddr?(netmask)
end

#parse(landata) ⇒ Object

def vlanid=(vlan)

end


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 87

def parse(landata)
  if !landata.nil? && !landata.empty?
    landata.lines.each do |line|
      # clean up the data from spaces
      next if line.match(/#+/)
      next if line.match(/Section/i)
      line.gsub!(/\t/, '')
      item = line.split(/\s+/)
      key = item.first.strip.downcase
      value = item.last.strip
      @info[key] = value
    end
  end
  @info
end

#static?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 26

def static?
  info.fetch("ip_address_source", nil).match(/static/i) != nil
end

#validaddr?(source) ⇒ Boolean

validates that the address, returns true/false

Returns:

  • (Boolean)


62
63
64
65
66
67
68
69
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 62

def validaddr?(source)
  valid = /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/.match("#{source}")
  if valid.nil?
    raise "#{source} is not a valid address"
  else
    return true
  end
end

#vlanidObject

def snmp

end


50
51
52
53
54
55
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 50

def vlanid
  info.fetch("vlan_id", nil)
  # some other vlan configuration that might also be useful
  # "vlan_id_enable"
  # "vlan_priority"
end