Class: ConcertoConfig::WiredConnection

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject

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

.descriptionObject



215
216
217
# File 'lib/concerto_client/netconfig.rb', line 215

def self.description
    "Wired connection"
end

.interfacesObject

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

#argsObject



188
189
190
191
192
# File 'lib/concerto_client/netconfig.rb', line 188

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

#config_interface_nameObject



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_linesObject



194
195
196
# File 'lib/concerto_client/netconfig.rb', line 194

def interfaces_lines
    []
end

#safe_assignObject



184
185
186
# File 'lib/concerto_client/netconfig.rb', line 184

def safe_assign
    [ :interface_name ]
end

#validateObject



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_configsObject



166
167
168
# File 'lib/concerto_client/netconfig.rb', line 166

def write_configs
    # We don't need any.
end