[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Ovirt-devel] Re: Added a configuration generation for managed nodes. It takes as input a

+++ David Lutterkort [25/08/08 16:43 -0700]:
+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

Minor nit: you could avoid the use of StringIO completely with a here
string (they allow interpolation with #{..})

Will using a here document allow for conditionally adding lines to the
document? For example, the IPADDR line only shows up if the nic.ip_addr is
defined. If so, can you point me to an example? I couldn't find one in the
pickaxe book that worked like that.

Darryl L. Pierce, Sr. Software Engineer
Red Hat, Inc. - http://www.redhat.com/
oVirt - Virtual Machine Management - http://www.ovirt.org/
"What do you care what other people think, Mr. Feynman?"

Attachment: pgpk6CL9KSST3.pgp
Description: PGP signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]