Class: ConcertoConfig::WiredConnection
- Inherits:
-
Object
- Object
- ConcertoConfig::WiredConnection
- Defined in:
- lib/concerto_client/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.
160 161 162 163 164 |
# File 'lib/concerto_client/netconfig.rb', line 160 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.
182 183 184 |
# File 'lib/concerto_client/netconfig.rb', line 182 def interface_name @interface_name end |
Class Method Details
.description ⇒ Object
215 216 217 |
# File 'lib/concerto_client/netconfig.rb', line 215 def self.description "Wired connection" end |
.interfaces ⇒ Object
Try to find all wired interfaces on the system.
209 210 211 212 213 |
# File 'lib/concerto_client/netconfig.rb', line 209 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
188 189 190 191 192 |
# File 'lib/concerto_client/netconfig.rb', line 188 def args { 'interface_name' => @interface_name } end |
#config_interface_name ⇒ Object
170 171 172 173 174 175 176 177 178 |
# File 'lib/concerto_client/netconfig.rb', line 170 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
194 195 196 |
# File 'lib/concerto_client/netconfig.rb', line 194 def interfaces_lines [] end |
#safe_assign ⇒ Object
184 185 186 |
# File 'lib/concerto_client/netconfig.rb', line 184 def safe_assign [ :interface_name ] end |
#validate ⇒ Object
198 199 200 201 202 203 204 205 206 |
# File 'lib/concerto_client/netconfig.rb', line 198 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
166 167 168 |
# File 'lib/concerto_client/netconfig.rb', line 166 def write_configs # We don't need any. end |