[Ovirt-devel] Re: Added a configuration generation for managed nodes. It takes as input a
Darryl L. Pierce
dpierce at redhat.com
Tue Aug 26 12:53:17 UTC 2008
+++ 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
>> +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?"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20080826/19e05cc1/attachment.sig>
More information about the ovirt-devel
mailing list