Class: Bandshell::WiredConnection
- Inherits:
-
Object
- Object
- Bandshell::WiredConnection
- 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
-
#interface_name ⇒ Object
If interface_name is something other than nil or the empty string, we will override the automatic detection and use that interface.
Class Method Summary collapse
- .description ⇒ Object
-
.interfaces ⇒ Object
Try to find all wired interfaces on the system.
Instance Method Summary collapse
- #args ⇒ Object
- #config_interface_name ⇒ Object
-
#initialize(args = {}) ⇒ WiredConnection
constructor
A new instance of WiredConnection.
- #interfaces_lines ⇒ Object
- #safe_assign ⇒ Object
- #validate ⇒ Object
- #write_configs ⇒ Object
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_name ⇒ Object
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
.description ⇒ Object
216 217 218 |
# File 'lib/bandshell/netconfig.rb', line 216 def self.description "Wired connection" end |
.interfaces ⇒ Object
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
#args ⇒ Object
189 190 191 192 193 |
# File 'lib/bandshell/netconfig.rb', line 189 def args { 'interface_name' => @interface_name } end |
#config_interface_name ⇒ Object
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_lines ⇒ Object
195 196 197 |
# File 'lib/bandshell/netconfig.rb', line 195 def interfaces_lines [] end |
#safe_assign ⇒ Object
185 186 187 |
# File 'lib/bandshell/netconfig.rb', line 185 def safe_assign [ :interface_name ] end |
#validate ⇒ Object
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_configs ⇒ Object
167 168 169 |
# File 'lib/bandshell/netconfig.rb', line 167 def write_configs # We don't need any. end |