Permalink
Browse files

More fixes as things are moved to ConcertoConfig

also move a few more things over there
  • Loading branch information...
1 parent c5182e0 commit 0a0bb4334b96bb5f808d2148236cb50a97809c2b @asquared committed Jun 12, 2012
Showing with 39 additions and 24 deletions.
  1. +19 −13 concerto_config_server.rb
  2. +16 −7 netconfig.rb
  3. +4 −4 views/netsettings.haml
View
@@ -7,15 +7,20 @@
require 'ipaddress'
# Some files we will use. None of these need to exist right away.
-NETCONFIG_FILE='/tmp/netconfig.json'
PASSWORD_FILE='/tmp/concerto_password'
URL_FILE='/tmp/concerto_url'
# push these over to netconfig.rb?
# Our list of available physical-layer connection methods...
-CONNECTION_METHODS = [ WiredConnection, WirelessConnection ]
+CONNECTION_METHODS = [
+ ConcertoConfig::WiredConnection,
+ ConcertoConfig::WirelessConnection
+]
# ... and available layer-3 addressing methods.
-ADDRESSING_METHODS = [ DHCPAddressing, StaticAddressing ]
+ADDRESSING_METHODS = [
+ ConcertoConfig::DHCPAddressing,
+ ConcertoConfig::StaticAddressing
+]
# Hosts we allow to access configuration without authenticating.
LOCALHOSTS = [
@@ -195,9 +200,7 @@ def validate_url(url)
# is not implemented. This is also how we get away with just having
# one instance each of the config classes that are currently selected.
begin
- cm, am = File.open(NETCONFIG_FILE) {
- |f| ConcertoConfig.read_config(f)
- }
+ cm, am = ConcertoConfig.read_config
rescue Errno::ENOENT
cm = nil
am = nil
@@ -215,7 +218,7 @@ def validate_url(url)
# Given the name of a class, pick a class out of a list of allowed classes.
# This is used for parsing the form input for network configuration.
def pick_class(name, list)
- list.find { |klass| klass.name == name }
+ list.find { |klass| klass.basename == name }
end
# Extract arguments from a set of form data that are intended to go to a
@@ -265,8 +268,8 @@ def do_assign(params, instance)
# Now given the names of the specific classes the user has chosen,
# extract the corresponding form fields.
- cmargs = extract_class_args(params, cmclass.name)
- amargs = extract_class_args(params, amclass.name)
+ cmargs = extract_class_args(params, cmclass.basename)
+ amargs = extract_class_args(params, amclass.basename)
# Set properties on each instance given the form values passed in.
do_assign(cmargs, cm)
@@ -279,22 +282,25 @@ def do_assign(params, instance)
# Serialize our instances as JSON data to be written to the config file.
json_data = {
- 'connection_method' => cmclass.name,
+ 'connection_method' => cmclass.basename,
'connection_method_args' => cm.args,
- 'addressing_method' => amclass.name,
+ 'addressing_method' => amclass.basename,
'addressing_method_args' => am.args
}
# Write the config file to disk.
- File.open(NETCONFIG_FILE, 'w') do |f|
+ File.open(ConcertoConfig::CONFIG_FILE, 'w') do |f|
f.write json_data.to_json
end
# Reload network configuration.
+ STDERR.puts "Trying to bring down the interface"
if ConcertoConfig.configured_interface
ConcertoConfig.configured_interface.ifdown
end
- configure_system
+ STDERR.puts "Rewriting configuration files"
+ ConcertoConfig::configure_system
+ STDERR.puts "Bringing interface back up"
ConcertoConfig.configured_interface.ifup
# Back to the network form.
View
@@ -18,13 +18,22 @@
# Each instance also has the opportunity to write out other configuration
# files such as wpa_supplicant.conf, resolv.conf etc.
+class Module
+ def basename
+ name.gsub(/^.*::/, '')
+ end
+end
+
module ConcertoConfig
# Where we store the name of the interface we are going to configure.
INTERFACE_FILE='/tmp/concerto_configured_interface'
# The Debian interfaces configuration file we are going to write out.
INTERFACES_FILE='/etc/network/interfaces'
+ # The configuration file we will read from.
+ CONFIG_FILE='/tmp/netconfig.json'
+
# Some useful interface operations.
class Interface
# Wrap an interface name (eth0, wlan0 etc) with some useful operations.
@@ -432,12 +441,12 @@ def self.description
# and returns the instances
# i.e.
# cm, am = read_config(STDIN)
- def read_config(input)
- input = input.read
+ def self.read_config
+ input = IO.read(CONFIG_FILE)
args = JSON.parse(input)
- connection_method_class = Object.const_get(args['connection_method'])
- addressing_method_class = Object.const_get(args['addressing_method'])
+ 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']
@@ -453,8 +462,8 @@ def read_config(input)
# 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.
- def configure_system
- connection_method, addressing_method = read_config(STDIN)
+ def self.configure_system
+ connection_method, addressing_method = read_config
ifname = connection_method.config_interface_name
@@ -486,7 +495,7 @@ def configure_system
end
# Get the name of the interface we configured
- def configured_interface
+ def self.configured_interface
begin
ifname = File.open(INTERFACE_FILE) do |f|
f.readline.chomp
View
@@ -7,7 +7,7 @@
/ set the html selected flag on the one that is currently
/ selected in the config
- CONNECTION_METHODS.each do |cm|
- %option{:value=>cm.name,
+ %option{:value=>cm.basename,
:selected=>(cm==connection_method.class)}=cm.description
#connection
#WiredConnection
@@ -18,7 +18,7 @@
%option{:value=>""}="Auto Select"
/ list out available interfaces and their MAC addresses
/ preselect one if there was one chosen in config
- - WiredConnection.interfaces.each do |iface|
+ - ConcertoConfig::WiredConnection.interfaces.each do |iface|
%option{:value=>iface.name, :selected=>value_from(connection_method, :interface_name)==iface.name}="#{iface.name} - #{iface.mac}"
#WirelessConnection
%h3="Wireless Connection Settings (no encryption)"
@@ -27,7 +27,7 @@
%select#interface_name{:name=>"WirelessConnection/interface_name"}
%option{:value=>""}="Auto Select"
/ same as above but with the wireless interfaces
- - WirelessConnection.interfaces.each do |iface|
+ - ConcertoConfig::WirelessConnection.interfaces.each do |iface|
%option{:value=>iface.name, :selected=>value_from(connection_method, :interface_name) == iface.name}="#{iface.name} - #{iface.mac}"
%p
%label{:for=>"WirelessConnection_ssid"}="SSID"
@@ -36,7 +36,7 @@
%h2="IP Address"
%select#addressing_type{:name=>"addressing_type"}
- ADDRESSING_METHODS.each do |am|
- %option{:value=>am.name,
+ %option{:value=>am.basename,
:selected=>(am==addressing_method.class)}=am.description
#address
#DHCPAddressing

0 comments on commit 0a0bb43

Please sign in to comment.