Module: Bandshell
- Defined in:
- lib/bandshell/live_image.rb,
lib/bandshell/netconfig.rb,
lib/bandshell/player_info.rb,
lib/bandshell/config_store.rb,
lib/bandshell/hardware_api.rb,
lib/bandshell/screen_control.rb
Overview
This is a stateless class which provides a collection of methods for controlling the display. Currently supported control interfaces include:
* DPMS
Defined Under Namespace
Modules: ConfigStore, HardwareApi, LiveImage Classes: DHCPAddressing, Interface, PlayerInfo, ScreenControl, StaticAddressing, WiredConnection, WirelessConnection
Constant Summary collapse
- INTERFACES_FILE =
The Debian interfaces configuration file we are going to write out.
'/etc/network/interfaces'
Class Method Summary collapse
-
.configure_system_network ⇒ Object
This reads a JSON configuration file on STDIN and writes the interfaces file.
-
.configured_interface ⇒ Object
Get the name of the interface we configured.
-
.read_network_config ⇒ Object
Read a JSON formatted network configuration from the config store.
-
.write_network_config(cm, am) ⇒ Object
Save the network configuration to the configuration store.
Class Method Details
.configure_system_network ⇒ Object
This reads a JSON configuration file on STDIN and writes the interfaces file. Also the classes instantiated will have a chance to write out any auxiliary files needed.
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/bandshell/netconfig.rb', line 501 def self.configure_system_network connection_method, addressing_method = read_network_config ifname = connection_method.config_interface_name # squirrel away the name of the interface we are configuring # This will be useful later for getting network status information. ConfigStore.write_config('network_interface', ifname) # Write the /etc/network/interfaces file. File.open(INTERFACES_FILE, 'w') do |f| f.puts "# Concerto Live network configuration" f.puts "# Generated by netconfig.rb" f.puts "# Changes will be lost on reboot" f.puts "auto lo" f.puts "iface lo inet loopback" f.puts "" f.puts "auto #{ifname}" f.puts "iface #{ifname} inet #{addressing_method.addressing_type}" addressing_method.interfaces_lines.each do |line| f.puts "\t#{line}" end connection_method.interfaces_lines.each do |line| f.puts "\t#{line}" end end # Write auxiliary configuration files. connection_method.write_configs end |
.configured_interface ⇒ Object
Get the name of the interface we configured
535 536 537 538 539 540 541 542 |
# File 'lib/bandshell/netconfig.rb', line 535 def self.configured_interface ifname = ConfigStore.read_config('network_interface', '') if ifname != '' Interface.new(ifname) else nil end end |
.read_network_config ⇒ Object
Read a JSON formatted network configuration from the config store. This instantiates the connection and addressing method classes and returns the instances i.e. cm, am = read_network_config
If no configuration is saved or it is corrupt this returns a default configuration that is somewhat likely to work.
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
# File 'lib/bandshell/netconfig.rb', line 447 def self.read_network_config input = ConfigStore.read_config('network_config', '') begin args = JSON.parse(input) rescue # set up some sane defaults if we have no configuration # or it can't be parsed args = { 'connection_method' => 'WiredConnection', 'addressing_method' => 'DHCPAddressing', 'connection_method_args' => { }, 'addressing_method_args' => { } } end connection_method_class = Bandshell.const_get(args['connection_method']) addressing_method_class = Bandshell.const_get(args['addressing_method']) connection_method = connection_method_class.new( args['connection_method_args'] ) addressing_method = addressing_method_class.new( args['addressing_method_args'] ) return [connection_method, addressing_method] end |
.write_network_config(cm, am) ⇒ Object
Save the network configuration to the configuration store. Arguments are instances of connection method and addressing method classes. Throws exception if either one is not valid.
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/bandshell/netconfig.rb', line 480 def self.write_network_config(cm, am) # Check that everything is consistent. If not, we currently throw # an exception, which probably is not the best long term solution. cm.validate am.validate # Serialize our instances as JSON data to be written to the config file. json_data = { 'connection_method' => cm.class.basename, 'connection_method_args' => cm.args, 'addressing_method' => am.class.basename, 'addressing_method_args' => am.args }.to_json # Save the serialized configuration. ConfigStore.write_config('network_config', json_data) end |