Class: Bandshell::WiredConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/bandshell/netconfig.rb

Overview

Layer 2 connection via wired media. We will look for wired interfaces that have media connected, or use an interface chosen by the user via the args. There’s nothing extra to be contributed to the interfaces file besides the name of the interface to be used.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ WiredConnection

Returns a new instance of WiredConnection.



161
162
163
164
165
# File 'lib/bandshell/netconfig.rb', line 161

def initialize(args={})
  if args['interface_name']
    @interface_name = args['interface_name']
  end
end

Instance Attribute Details

#interface_nameObject

If interface_name is something other than nil or the empty string, we will override the automatic detection and use that interface.



183
184
185
# File 'lib/bandshell/netconfig.rb', line 183

def interface_name
  @interface_name
end

Class Method Details

.descriptionObject



216
217
218
# File 'lib/bandshell/netconfig.rb', line 216

def self.description
  "Wired connection"
end

.interfacesObject

Try to find all wired interfaces on the system.



210
211
212
213
214
# File 'lib/bandshell/netconfig.rb', line 210

def self.interfaces
  # This is somewhat Linux specific and may miss some oddballs.
  devices = Dir.glob('/sys/class/net/eth*')
  devices.map { |d| Interface.new(File.basename(d)) }
end

Instance Method Details

#argsObject



189
190
191
192
193
# File 'lib/bandshell/netconfig.rb', line 189

def args
  {
    'interface_name' => @interface_name
  }
end

#config_interface_nameObject



171
172
173
174
175
176
177
178
179
# File 'lib/bandshell/netconfig.rb', line 171

def config_interface_name
  if @interface_name && @interface_name.length > 0
    # the user has specified an interface to use
    @interface_name
  else
    # scan for the first wired interface that has media
    scan_interfaces
  end
end

#interfaces_linesObject



195
196
197
# File 'lib/bandshell/netconfig.rb', line 195

def interfaces_lines
  []
end

#safe_assignObject



185
186
187
# File 'lib/bandshell/netconfig.rb', line 185

def safe_assign
  [ :interface_name ]
end

#validateObject



199
200
201
202
203
204
205
206
207
# File 'lib/bandshell/netconfig.rb', line 199

def validate
  if @interface_name != ''
    if self.class.interfaces.find {
          |iface| iface.name == @interface_name
        }.nil?
      fail "The interface doesn't exist on the system"
    end
  end
end

#write_configsObject



167
168
169
# File 'lib/bandshell/netconfig.rb', line 167

def write_configs
  # We don't need any.
end