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.



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

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

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



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

def channel
  @channel
end

#configObject

Returns the value of attribute config.



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

def config
  @config
end

#infoObject

Returns the value of attribute info.



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

def info
  @info
end

Instance Method Details

#dhcp?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 24

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

#gatewayObject



44
45
46
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 44

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

#gateway=(address) ⇒ Object



81
82
83
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 81

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

#ipObject



32
33
34
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 32

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

#ip=(address) ⇒ Object



73
74
75
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 73

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

#macObject



36
37
38
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 36

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

#netmaskObject



40
41
42
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 40

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

#netmask=(netmask) ⇒ Object



77
78
79
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 77

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

#parse(landata) ⇒ Object

def vlanid=(vlan)

end


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

def parse(landata)
  if ! landata.nil? and ! 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)


28
29
30
# File 'lib/rubyipmi/freeipmi/commands/lan.rb', line 28

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)


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

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


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

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