[Ovirt-devel] [PATCH] Added a configuration generation for managed nodes. It takes as input a
David Lutterkort
lutter at redhat.com
Mon Aug 25 23:43:12 UTC 2008
On Thu, 2008-08-21 at 13:12 -0400, Darryl L. Pierce wrote:
The subject of the patch is mangled, and it would be good to have a
little more description, too.
I'd ACK this if the description was fixed, and the spurious change to
application.rb removed.
> ---
> wui/src/app/controllers/application.rb | 2 +-
> wui/src/lib/managed_node_configuration.rb | 53 +++++++++++
> wui/src/test/fixtures/hosts.yml | 9 ++
> wui/src/test/fixtures/nics.yml | 7 +-
> wui/src/test/fixtures/pools.yml | 4 +
> .../functional/managed_node_configuration_test.rb | 98 ++++++++++++++++++++
> 6 files changed, 171 insertions(+), 2 deletions(-)
> create mode 100644 wui/src/lib/managed_node_configuration.rb
> create mode 100644 wui/src/test/functional/managed_node_configuration_test.rb
>
> diff --git a/wui/src/app/controllers/application.rb b/wui/src/app/controllers/application.rb
> index d653171..b27ddbe 100644
> --- a/wui/src/app/controllers/application.rb
> +++ b/wui/src/app/controllers/application.rb
> @@ -35,7 +35,7 @@ class ApplicationController < ActionController::Base
> before_filter :is_logged_in
>
> def is_logged_in
> - redirect_to (:controller => "login", :action => "login") unless get_login_user
> + redirect_to(:controller => "login", :action => "login") unless get_login_user
> end
Seems to have slipped in by accident.
> def get_login_user
> diff --git a/wui/src/lib/managed_node_configuration.rb b/wui/src/lib/managed_node_configuration.rb
> new file mode 100644
> index 0000000..6d6b7c9
> --- /dev/null
> +++ b/wui/src/lib/managed_node_configuration.rb
> @@ -0,0 +1,53 @@
> +#
> +# Copyright (C) 2008 Red Hat, Inc.
> +# Written by Darryl L. Pierce <dpierce at redhat.com>.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; version 2 of the License.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> +# MA 02110-1301, USA. A copy of the GNU General Public License is
> +# also available at http://www.gnu.org/copyleft/gpl.html.
> +
> +# +ManagedNodeConfiguration+ takes in the description for a managed node and,
> +# from that, generates the configuration file that is consumed the next time
> +# the managed node starts up.
> +#
> +
> +require 'stringio'
> +
> +$: << File.join(File.dirname(__FILE__), "../dutils")
> +$: << File.join(File.dirname(__FILE__), "../")
Manipulating $: in production code is kinda ugly .. is that just a relic
from testing ?
> +class ManagedNodeConfiguration
> + NIC_ENTRY_PREFIX='/files/etc/sysconfig/network-scripts'
> +
> + def self.generate(host, macs)
> + result = StringIO.new
> +
> + host.nics.each do |nic|
> + iface_name = macs[nic.mac]
> +
> + if iface_name
> + result.puts "rm #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}"
> + result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/DEVICE #{iface_name}"
> + result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/IPADDR #{nic.ip_addr}" if nic.ip_addr
> + result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BOOTPROTO dhcp" if nic.ip_addr == nil
> + result.puts "set #{NIC_ENTRY_PREFIX}/ifcfg-#{iface_name}/BRIDGE #{nic.bridge}" if nic.bridge
> + result.puts ""
> + end
> + end
> +
> + result.puts "save"
> +
> + result.string
> + end
> +end
Minor nit: you could avoid the use of StringIO completely with a here
string (they allow interpolation with #{..})
David
More information about the ovirt-devel
mailing list