Module: ConcertoConfig
- Defined in:
- lib/concerto_client/live_image.rb,
lib/concerto_client/netconfig.rb,
lib/concerto_client/config_store.rb
Overview
A key/value store for strings. Right now implemented as disk files.
Defined Under Namespace
Modules: ConfigStore, LiveImage Classes: DHCPAddressing, Interface, 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
If no configuration is saved or it is corrupt this returns a default configuration that is somewhat likely to work.
-
.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.
500 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 |
# File 'lib/concerto_client/netconfig.rb', line 500 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
534 535 536 537 538 539 540 541 |
# File 'lib/concerto_client/netconfig.rb', line 534 def self.configured_interface ifname = ConfigStore.read_config('network_interface', '') if ifname != '' Interface.new(ifname) else nil end end |
.read_network_config ⇒ Object
If no configuration is saved or it is corrupt this returns a default configuration that is somewhat likely to work.
446 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 |
# File 'lib/concerto_client/netconfig.rb', line 446 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 = ConcertoConfig.const_get(args['connection_method']) addressing_method_class = ConcertoConfig.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.
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/concerto_client/netconfig.rb', line 479 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 |