Module: CommandMixins::Networksrc

Included in:
DRACCommands::Networksrc, SMCCommands::Networksrc
Defined in:
lib/setup_oob/command/mixins.rb

Instance Method Summary collapse

Instance Method Details

#_converge!Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/setup_oob/command/mixins.rb', line 174

def _converge!
  unless mode?
    logger.info(" - Setting network src to #{desired_mode}")
    set_mode
  end
  if desired_mode == 'static'
    logger.info(' - Checking address')
    if address != desired_address
      logger.info(" - Setting network address to #{desired_address}")
      set_address
    end
    if netmask != desired_netmask
      logger.info(" - Setting network mask to #{desired_netmask}")
      set_netmask
    end
  end
end

#_converged?Boolean



156
157
158
# File 'lib/setup_oob/command/mixins.rb', line 156

def _converged?
  mode? && address?
end

#addressObject



135
136
137
# File 'lib/setup_oob/command/mixins.rb', line 135

def address
  current['IP Address']
end

#address?Boolean



160
161
162
163
164
165
166
167
# File 'lib/setup_oob/command/mixins.rb', line 160

def address?
  if desired_mode == 'static'
    logger.debug('  - Checking of address is set')
    logger.debug("'#{@data}' vs '#{@data}'")
    return address == desired_address || netmask == desired_netmask
  end
  true
end

#currentObject



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/setup_oob/command/mixins.rb', line 143

def current
  return @current if @current

  @current = {}
  cmd = ipmicmd + ['lan', 'print', '1']
  s = run(cmd)
  s.stdout.each_line do |line|
    key, val = line.chomp.split(':')
    @current[key.strip] = val.strip
  end
  @current
end

#desired_addressObject



107
108
109
110
111
112
113
# File 'lib/setup_oob/command/mixins.rb', line 107

def desired_address
  if @data == 'dhcp'
    fail 'Set to DHCP, but looking for address, what?'
  end

  IPAddress(@data).address
end

#desired_modeObject



103
104
105
# File 'lib/setup_oob/command/mixins.rb', line 103

def desired_mode
  @data == 'dhcp' ? 'dhcp' : 'static'
end

#desired_netmaskObject



115
116
117
118
119
120
121
# File 'lib/setup_oob/command/mixins.rb', line 115

def desired_netmask
  if @data == 'dhcp'
    fail 'Set to DHCP, but looking for address, what?'
  end

  IPAddress(@data).netmask
end

#ipmicmd(set = false) ⇒ Object



211
212
213
# File 'lib/setup_oob/command/mixins.rb', line 211

def ipmicmd(set = false)
  smc? ? basecmd(set) : SMCCommandBase.basecmd('localhost')
end

#modeObject



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/setup_oob/command/mixins.rb', line 123

def mode
  x = current['IP Address Source']
  case x
  when /DHCP/
    'dhcp'
  when /Static/
    'static'
  else
    'other'
  end
end

#mode?Boolean



169
170
171
172
# File 'lib/setup_oob/command/mixins.rb', line 169

def mode?
  logger.debug("  - Checking if network src mode set to #{desired_mode}")
  mode == desired_mode
end

#netmaskObject



139
140
141
# File 'lib/setup_oob/command/mixins.rb', line 139

def netmask
  current['Subnet Mask']
end

#set_addressObject



201
202
203
204
# File 'lib/setup_oob/command/mixins.rb', line 201

def set_address
  cmd = ipmicmd(true) + ['lan', 'set', '1', 'ipaddr', desired_address]
  run(cmd)
end

#set_modeObject



196
197
198
199
# File 'lib/setup_oob/command/mixins.rb', line 196

def set_mode
  cmd = ipmicmd(true) + ['lan', 'set', '1', 'ipsrc', desired_mode]
  run(cmd)
end

#set_netmaskObject



206
207
208
209
# File 'lib/setup_oob/command/mixins.rb', line 206

def set_netmask
  cmd = ipmicmd(true) + ['lan', 'set', '1', 'netmask', desired_netmask]
  run(cmd)
end

#smc?Boolean



192
193
194
# File 'lib/setup_oob/command/mixins.rb', line 192

def smc?
  @smc ||= self.class.to_s.start_with?('SMC')
end