diff --git a/xCAT-server/share/xcat/tools/mkay4z b/xCAT-server/share/xcat/tools/mkay4z index f231e4d1b..6f015f80a 100644 --- a/xCAT-server/share/xcat/tools/mkay4z +++ b/xCAT-server/share/xcat/tools/mkay4z @@ -1,5 +1,5 @@ #!/usr/bin/perl -# IBM(c) 2010 EPL license http://www.eclipse.org/legal/epl-v10.html +# IBM(c) 2012 EPL license http://www.eclipse.org/legal/epl-v10.html #------------------------------------------------------- =head1 mkay4z @@ -8,10 +8,8 @@ Author: Thang Pham (thang.pham@us.ibm.com) Returns: Autoyast template - Usage: mkay4z [conf_file] [ref_template], where - [conf_file]: File containing Linux configuration - [ref_template]: Reference autoyast template to build off of - Example: # ./mkay4z conf.txt ref.sles11.s390x.tmpl > custom.sles11.s390x.tmpl + Usage: mkay4z + Example: # ./mkay4z =cut @@ -19,52 +17,484 @@ use strict; use warnings; -# Check arguments -if(@ARGV != 2) { +# Show help +if (@ARGV > 0) { print < custom.sles11.s390x.tmpl +IBM (c)2012 EPL license http://www.eclipse.org/legal/epl-v10.html END exit(); } -# Get conf file and reference template -my $file = $ARGV[0]; -my $tmpl = $ARGV[1]; +# Show help +print "Creating autoyast template for Linux on System z...\n"; -# Create parameters to search for -my @search = ('dasd', 'partitions', 'software'); -# Get parameters from conf file -my %parms = getParms($file); -# Set parameters for networking and root password -$parms{'hosts'} = '[host_address=replace_host_address,name=replace_long_name replace_short_name]'; -$parms{'dns'} = '[hostname=replace_hostname,dhcp_hostname=true,dhcp_resolv=true,domain=replace_domain,nameserver=replace_nameserver]'; -$parms{'interfaces'} = '[device=replace_device,bootproto=dhcp,lladdr=replace_lladdr,chanids=replace_ccw_chan_ids]'; -$parms{'root_password'} = 'replace_root_password'; - -# Check that all parameters are given -my $missing = ''; -foreach(@search) { - if(!$parms{$_}) { - $missing .= "$_ "; +# Get distro version +my $version = ''; +while (!($version eq '10' || $version eq '11')) { + $version = ask("Select SUSE Linux Enterprise Server version? (10 or 11) "); + + if (!($version eq '10' || $version eq '11')) { + print " Unknown value!\n"; } } -# If there are missing paramters -if($missing) { - print "Please supply the following parameters in $file: $missing"; - exit(); +# Get template path +my $template_path = ask("Where do you want to place the template? (e.g. /tmp/autoyast.tmpl) "); + +# Default dasd and partition configuration +# Used for testing +my %dasd_default = ( + '0.0.0100' => { + 'device_name' => '/dev/dasda', + 'type' => 'dasd_eckd_mod' + }, + '0.0.0101' => { + 'device_name' => '/dev/dasda', + 'type' => 'dasd_eckd_mod' + } +); +my %partitions_default = ( + '/dev/dasda' => { + 'device_fs' => 'ext4', + 'device_size' => '4g', + 'device_mount' => '', + 'device_lvm' => 'VG' + }, + '/dev/dasdb' => { + 'device_fs' => 'ext4', + 'device_size' => 'max', + 'device_mount' => '', + 'device_lvm' => 'VG' + }, + '/dev/VG' => { + 'lvm' => { + 'lv_root' => { + 'name' => 'lv_root', + 'fs' => 'ext4', + 'mount' => '/', + 'size' => '4g' + }, + 'lv_opt' => { + 'name' => 'lv_opt', + 'fs' => 'ext4', + 'mount' => '/opt', + 'size' => 'max' + } + } + } +); + +# Set default parameters for networking and root password +my %parms = ( + 'hosts' => { + 'localhost' => { + 'host_address' => '127.0.0.1', + 'name' => 'localhost' + }, + 'xcat' => { + 'host_address' => 'replace_host_address', + 'name' => 'replace_long_name replace_short_name' + } + }, + 'dns' => { + 'xcat' => { + 'hostname' => 'replace_hostname', + 'dhcp_hostname' => 'true', + 'dhcp_resolv' => 'true', + 'domain' => 'replace_domain', + 'nameserver' => 'replace_nameserver' + } + }, + 'interfaces' => { + 'xcat' => { + 'bootproto' => 'dhcp', + 'device' => 'replace_device', + 'lladdr' => 'replace_lladdr', + 'chanids' => 'replace_ccw_chan_ids' + } + }, + 'root_password' => 'replace_root_password', + 'software' => 'Minimal' +); + +# Use DHCP? +my $dhcp = ''; +while (!($dhcp eq 'Y' || $dhcp eq 'y' || $dhcp eq 'Yes' || $dhcp eq 'yes' || $dhcp eq 'N' || $dhcp eq 'n' || $dhcp eq 'No' || $dhcp eq 'no')) { + $dhcp = ask(" Do you want to use DHCP? (yes or no) "); + + if ($dhcp eq 'Y' || $dhcp eq 'y' || $dhcp eq 'Yes' || $dhcp eq 'yes') { + $parms{'interfaces'} = { + 'xcat' => { + 'bootproto' => 'dhcp', + 'device' => 'replace_device', + 'lladdr' => 'replace_lladdr', + 'chanids' => 'replace_ccw_chan_ids' + } + }; + } elsif ($dhcp eq 'N' || $dhcp eq 'n' || $dhcp eq 'No' || $dhcp eq 'no') { + $parms{'interfaces'} = { + 'xcat' => { + 'bootproto' => 'static', + 'device' => 'replace_device', + 'lladdr' => 'replace_lladdr', + 'ipaddr' => 'replace_ipaddr', + 'netmask' => 'replace_netmask', + 'broadcast' => 'replace_broadcast', + 'network' => 'replace_network', + 'chanids' => 'replace_ccw_chan_ids' + } + }; + } else { + print " Unknown value!\n"; + } +} + +# Hash array containing autoyast configuration +my %dasd; +my %partitions; +my %lvm; + +# Prompts user for input? +my $ask = 0; + +# Configure dasd +my $dasd_option = 0; +my $addr; +my $dasd_type; +my $device_name; +my $device_type; +my $tmp; +my $i = 0; + +print <; + $dasd_option = trim($dasd_option); + while (!($dasd_option eq '1' || $dasd_option eq '2' || $dasd_option eq '3' || $dasd_option eq '4')) { + print " Unknown value!\n"; + $dasd_option = <>; + $dasd_option = trim($dasd_option); + } + + # Add dasd to template + if ($dasd_option == '1') { + # Get virtual address + $addr = ask(" What is the virtual address? "); + while (length($addr) < 4) { # Address length must be 4 + $addr = '0' . $addr; + } + $addr = '0.0.' . $addr; + + # Get dasd type + $ask = 1; + while ($ask) { + $dasd_type = ask(" What is the type? (eckd or fba) "); + if ($dasd_type eq 'eckd') { + $dasd_type = 'dasd_eckd_mod'; + $ask = 0; + } elsif ($dasd_type eq 'fba') { + $dasd_type = 'dasd_fba_mod'; + $ask = 0; + } else { + print " Unknown value!\n"; + } + } + + # Save dasd in hash + $dasd{$addr}{'type'} = $dasd_type; + } + + # Remove dasd from template + elsif ($dasd_option == '2') { + $addr = ask(" What is the virtual address to remove? "); + while (length($addr) < 4) { # Address length must be 4 + $addr = '0' . $addr; + } + $addr = '0.0.' . $addr; + + # Remove from hash + delete $dasd{$addr}; + } + + elsif ($dasd_option == '3') { + # Show configuration + print < @device_list) { + print " Unknown value!\n"; + redo; + } + + # Only configure if a device is selected + if (length($selected)) { + $selected = int($selected); + + @args = split(' ', $device_list[$selected]); + $device_name = $args[0]; + + # Get device filesystem + $device_fs = ''; + while (!($device_fs eq 'ext2' || $device_fs eq 'ext3' || $device_fs eq 'ext4' || $device_fs eq 'swap')) { + $device_fs = ask(" What is the filesystem for $device_name? (ext2, ext3, ext4, or swap) "); + + if (!($device_fs eq 'ext2' || $device_fs eq 'ext3' || $device_fs eq 'ext4' || $device_fs eq 'swap')) { + print " Unknown value!\n"; + } + } + + # Get partition size + $device_size = ''; + while (!$device_size) { + $device_size = ask(" What is the partition size? (e.g. 1g, 2g, or max) "); + if (!$device_size) { + print " Please give a partition size!"; + } + } + + # Is partition an LVM + $lvm = ''; + while (!($lvm eq 'Y' || $lvm eq 'y' || $lvm eq 'Yes' || $lvm eq 'yes' || $lvm eq 'N' || $lvm eq 'n' || $lvm eq 'No' || $lvm eq 'no')) { + $lvm = ask(" Do you want to assign it to an LVM group? (yes or no) "); + $lvm_group = ""; + $device_mount = ""; + + if ($lvm eq 'Y' || $lvm eq 'y' || $lvm eq 'Yes' || $lvm eq 'yes') { + # Get partition LVM group + $lvm_group = ask(" What is the LVM group? "); + $ask_lvm = 1; + + # Create new entry for volume group + $tmp = '/dev/' . $lvm_group; + $partitions{$tmp}{'device_lvm'} = $lvm_group; + } elsif ($lvm eq 'N' || $lvm eq 'n' || $lvm eq 'No' || $lvm eq 'no') { + # Get partition mount point + $device_mount = ask(" What is the mount point? "); + } else { + print " Unknown value!\n"; + } + } + + # Save dasd in hash + $partitions{$device_name}{'device_fs'} = $device_fs; + $partitions{$device_name}{'device_size'} = $device_size; + $partitions{$device_name}{'device_mount'} = $device_mount; + $partitions{$device_name}{'device_lvm'} = $lvm_group; + } else { + $ask = 0; + } +} + +# Configure LVM partitions +my @lvm_list; +if ($ask_lvm) { + print <; + + # Add an LVM volume to template + if ($lvm_option == '1') { + # Get dasd virtual address + $lvm_vol_name = ask(" What is the LVM volume name? "); + + # Get device filesystem + $lvm_vol_fs = ''; + while (!($lvm_vol_fs eq 'ext2' || $lvm_vol_fs eq 'ext3' || $lvm_vol_fs eq 'ext4' || $lvm_vol_fs eq 'swap')) { + $lvm_vol_fs = ask(" What is the LVM volume filesystem? (ext2, ext3, ext4, or swap) "); + + if (!($lvm_vol_fs eq 'ext2' || $lvm_vol_fs eq 'ext3' || $lvm_vol_fs eq 'ext4' || $lvm_vol_fs eq 'swap')) { + print " Unknown value!\n"; + } + } + + # Get partition mount point + $lvm_vol_mount = ask(" what is the Mount point? "); + + # Get partition size + $lvm_vol_size = ask(" What is the LVM volume size? (e.g. 1g, 2g, or max) "); + + # Save dasd in hash + $partitions{$device_name}{'lvm'}{$lvm_vol_name} = { + 'fs' => $lvm_vol_fs, + 'name' => $lvm_vol_name, + 'mount' => $lvm_vol_mount, + 'size' => $lvm_vol_size + }; + } + + # Remove an LVM volume from template + elsif ($lvm_option == '2') { + my $name = ask(" What is the LVM volume to remove? "); + + # Remove from hash + delete $partitions{$device_name}{'lvm'}{$name}; + } + + elsif ($lvm_option == '3') { + # Show configuration + print < section -my $dasdSection = createDasd($parms{'dasd'}); +my $dasdSection = createDasd(\%dasd, \%partitions); + +# Create section +my $partitionsSection = createPartitions(\%dasd, \%partitions); + +# Create section +my $dasdModulesSection = createDasdModules(\%dasd); +my $nicModulesSection = createNicModules($parms{'interfaces'}); # Create section my $hostsSection = createHosts($parms{'hosts'}); @@ -73,14 +503,7 @@ my $hostsSection = createHosts($parms{'hosts'}); my $dnsSection = createDns($parms{'dns'}); # Create section -my ($interfacesSection, %interface) = createInterfaces($parms{'interfaces'}); - -# Create section -my $dasdModulesSection = createDasdModules($parms{'dasd'}); -my $nicModulesSection = createNicModules(%interface); - -# Create section -my $partitionsSection = createPartitions($parms{'partitions'}); +my ($interfacesSection) = createInterfaces($parms{'interfaces'}); # Create software section my $softwareSection = createSoftware($parms{'software'}); @@ -94,7 +517,7 @@ END my $routesSection = createRoutes($parms{'interfaces'}); # Create scripts section -my $scriptsSection = createScripts(%interface); +my $scriptsSection = createScripts($parms{'interfaces'}); # Begin to build template @@ -109,87 +532,67 @@ my $scriptsSection = createScripts(%interface); # insert_root_password # insert_routes -# Read in autoyast template -open(FILE, $tmpl); +# Generate autoyast template +my $tmpl = ''; +if ($version eq '10') { + $tmpl = genSles10Tmpl(); +} elsif ($version eq '11') { + $tmpl = genSles11Tmpl(); +} + +# Print out template +`echo "$tmpl" > $template_path`; + +open(FILE, $template_path); # Go through each line +my $mod_tmpl = ''; while(my $ln = ) { # If the line matches the pattern to replace, print replacement if($ln =~ 'insert_devices') { - print $dasdSection; + $mod_tmpl .= $dasdSection; } elsif($ln =~ 'insert_hosts') { - print $hostsSection; + $mod_tmpl .= $hostsSection; } elsif($ln =~ 'insert_dns') { - print $dnsSection; + $mod_tmpl .= $dnsSection; } elsif($ln =~ 'insert_interfaces') { - print $interfacesSection; + $mod_tmpl .= $interfacesSection; } elsif($ln =~ 'insert_modules') { - print $dasdModulesSection; - print $nicModulesSection; + $mod_tmpl .= $dasdModulesSection; + $mod_tmpl .= $nicModulesSection; } elsif($ln =~ 'insert_partitioning_drives') { - print $partitionsSection; + $mod_tmpl .= $partitionsSection; } elsif($ln =~ 'insert_software_pattern') { - print $softwareSection; + $mod_tmpl .= $softwareSection; } elsif($ln =~ 'insert_root_password') { - print $passwordSection; + $mod_tmpl .= $passwordSection; } elsif($ln =~ 'insert_routes') { - print $routesSection; + $mod_tmpl .= $routesSection; } elsif($ln =~ '') { # Print line $ln =~ s/\r//g; # Remove return carriage - print $ln; + $mod_tmpl .= $ln; - print $scriptsSection; + $mod_tmpl .= $scriptsSection; } else { # Print line $ln =~ s/\r//g; # Remove return carriage - print $ln; + $mod_tmpl .= $ln; } } close(FILE); -#------------------------------------------------------- +# Print out modified template +`echo "$mod_tmpl" > $template_path`; + +# Done +print "Done! See autoyast template under $template_path\n"; +exit(); + + + -=head3 getParms - Description : Get the parameters in the conf file - Arguments : Conf file - Returns : Hash table of parameters - Example : my %parms = getParms($file); - -=cut -#------------------------------------------------------- -sub getParms { - my ($file) = @_; - - # Read in file - open(FILE, $file); - - # Go through line in the file - my %parms; - my $name = ''; - my $tmp = ''; - while(my $ln = ) { - # If the line contains ={, get the parameter name - if ($ln =~ /={/) { - ($name, $tmp) = split(/={/, $ln, 2); - $parms{$name} = ''; - } - - if ($name) { - # Append line to parameter - $parms{$name} = $parms{$name} . trim($ln); - } - } - close(FILE); - - # Remove curly brackets - foreach my $key(keys %parms) { - $parms{$key} =~ s/(.*=\{|\})//g; - } - - return %parms; -} #------------------------------------------------------- @@ -221,46 +624,34 @@ sub trim { =head3 createDasd Description : Create the section - Arguments : Dasd attached to server + Arguments : Dasd and partition hash Returns : section - Example : my $section = createDasd($dasd); + Example : my $section = createDasd($dasd_ref, $partition_ref); =cut #------------------------------------------------------- sub createDasd { - # Get string - my ($str) = @_; - - # Split the dasd - my @args = split(/\],/, $str); - - # Remove square brackets - my $i; - for($i = 0; $i < @args; $i++) { - $args[$i] =~ s/(\[|\])//g; - $args[$i] = trim($args[$i]); - } - - # Create hash table for each dasd - my %dasd; - my @tmp; - my $pos; - my $length; - foreach(@args) { - # Split the arguments - # e.g. 0.0.0100,dasd_eckd_mod,(/dev/dasda,/dev/dasdb) - @tmp = split(/,/,$_,4); - $tmp[0] = trim($tmp[0]); - $dasd{$tmp[0]}{'channel'} = $tmp[0]; - $dasd{$tmp[0]}{'modules'} = trim($tmp[1]); - $dasd{$tmp[0]}{'dev_name'} = trim($tmp[2]); - - # Remove brackets - $tmp[3] = trim($tmp[3]); - $dasd{$tmp[0]}{'partition_info'} = substr($tmp[3], 1, length($tmp[3])-2); - } + # Get inputs + my ($dasd_ref, $partition_ref) = @_; + my %dasd = %$dasd_ref; + my %partition = %$partition_ref; + + # dasd hash should include: + # $dasd{$addr}{'device_name'} = $device_name; + # $dasd{$addr}{'type'} = $dasd_type; + # partition hash should include: + # $partitions{$device_name}{'device_fs'} = ''; + # $partitions{$device_name}{'device_size'} = ''; + # $partitions{$device_name}{'device_mount'} = ''; + # $partitions{$device_name}{'device_lvm'} = ''; + # $partitions{$device_name}{'lvm'}{$lvm_vol_name} = { + # 'name' => $lvm_vol_name, + # 'mount' => $lvm_vol_mount, + # 'size' => $lvm_vol_size + # }; + # Create section # # @@ -302,20 +693,26 @@ sub createDasd { # my $xml = ''; - my @partInfo; - foreach my $id(sort (keys %dasd)){ + my $device_name; + my $device_type; + my $partition_info; + foreach my $addr(sort keys %dasd){ + $device_name = $dasd{$addr}{'device_name'}; + $device_type = $dasd{$addr}{'type'}; + # If this dasd is to be used for Linux - if ($dasd{$id}{'partition_info'} =~ 'Linux native') { + if ($partitions{$device_name}{'device_mount'} || $partitions{$device_name}{'device_lvm'}) { + $partition_info = $device_name . "1 (Linux native)"; $xml .= < None none - $id + $addr true - $dasd{$id}{'dev_name'} + $device_name - $dasd{$id}{'dev_name'} - /dev/disk/by-path/ccw-$id + $device_name + /dev/disk/by-path/ccw-$addr DASD io_subchannel @@ -325,14 +722,14 @@ sub createDasd { true - $dasd{$id}{'modules'} + $device_type false - $dasd{$id}{'partition_info'} + $partition_info @@ -342,19 +739,20 @@ sub createDasd { - $id + $addr END } else { + $partition_info = $device_name; $xml .= < None none - $id - $dasd{$id}{'dev_name'} + $addr + $device_name - $dasd{$id}{'dev_name'} - /dev/disk/by-path/ccw-$id + $device_name + /dev/disk/by-path/ccw-$addr DASD io_subchannel @@ -364,14 +762,14 @@ END true - $dasd{$id}{'modules'} + $device_type true - $dasd{$id}{'partition_info'} + $partition_info @@ -380,12 +778,12 @@ END - $id + $addr END - } + } } - + return $xml; } @@ -396,54 +794,16 @@ END Description : Create the section Arguments : Interfaces attached to server Returns : section - Example : my $section = createInterfaces($interfaces); + Example : my $section = createInterfaces($interfaces_ref); =cut #------------------------------------------------------- sub createInterfaces { # Get string - my ($str) = @_; - - # Split the interfaces - my @device = split(/\],/,$str); - - # Remove square brackets - my $i; - for($i = 0; $i < @device; $i++) { - $device[$i] =~ s/(\[|\])//g; - $device[$i] = trim($device[$i]); - } - - # Create hash table for each interface - my %interface; - my @args; - - my $id; - my $name; - my $value; - - # Loop through each interface - foreach(@device) { - # Split the arguments - # e.g. device=eth0,bootproto=static,broadcast=10.1.100.255,... - @args = split(/,/,$_); - - # Device name should always be the first index - $args[0] =~ s/device=//g; - $id = trim($args[0]); + my ($interfaces_ref) = @_; + my %interfaces = %$interfaces_ref; - # Go through each attribute and set hash table - for($i = 1; $i < @args; $i++) { - # Get the attribute name value pair - ($name, $value) = split(/=/, $args[$i], 2); - $name = trim($name); - $value = trim($value); - - $interface{$id}{$name} = $value; - } - } - # Create section # # static @@ -465,18 +825,18 @@ sub createInterfaces { # no # my $xml = ''; - foreach my $id(keys %interface){ + foreach my $i(keys %interfaces){ # Create static interface - if($interface{$id}{'bootproto'} eq 'static') { + if($interfaces{$i}{'bootproto'} eq 'static') { $xml .= < - $interface{$id}{'bootproto'} - $interface{$id}{'broadcast'} - $id - $interface{$id}{'ipaddr'} - $interface{$id}{'name'} - $interface{$id}{'netmask'} - 25 + $interfaces{$i}{'bootproto'} + $interfaces{$i}{'broadcast'} + $interfaces{$i}{'device'} + $interfaces{$i}{'ipaddr'} + $interfaces{$i}{'lladdr'} + $interfaces{$i}{'netmask'} + $interfaces{$i}{'network'} auto END @@ -486,9 +846,9 @@ END else { $xml .= < - $interface{$id}{'bootproto'} - $id - $interface{$id}{'lladdr'} + $interfaces{$i}{'bootproto'} + $interfaces{$i}{'device'} + $interfaces{$i}{'lladdr'} auto no @@ -496,7 +856,7 @@ END } } - return ($xml, %interface); + return ($xml); } #------------------------------------------------------- @@ -504,47 +864,20 @@ END =head3 createPartitions Description : Create the section - Arguments : Partitions to create on server + Arguments : Dasds and partition hash Returns : section - Example : my $section = createPartitions($partitions); + Example : my $section = createPartitions($dasd_ref, $partition_ref); =cut #------------------------------------------------------- sub createPartitions { - # Get string - my ($str) = @_; - - # Split the interfaces - my @device = split(/\],/,$str); - - # Remove square brackets - my $i; - for($i = 0; $i < @device; $i++) { - $device[$i] =~ s/(\[|\])//g; - $device[$i] = trim($device[$i]); - } - - # Create hash table for each partitions - my %partitions; - my @args; - my $id; - - # Loop through each partitions - foreach(@device) { - # Split the arguments - # e.g. device=/dev/dasda,filesystem=ext3,(mount=/;size=4G),(lvm_group=VG;size=max) - # device=/dev/VG,(lv_name=LV_home;filesystenm=ext3;mount=/home;size=3G),(lv_name=LV_opt;filesystem=ext3;mount=/opt;size=3G) - @args = split(/,/,$_,2); - - # Device name should always be the first index - $args[0] =~ s/device=//g; - $id = trim($args[0]); - - # Partition setup should always be the second index - $partitions{$id}{'partition'} = trim($args[1]); - } + # Get inputs + my ($dasd_ref, $partition_ref) = @_; + my %dasd = %$dasd_ref; + my %partitions = %$partition_ref; + # Create section # # /dev/dasda @@ -584,117 +917,83 @@ sub createPartitions { # all # my $xml = ''; - my %layoutAttr; - my @layout; - - my @attrs; - my $name; - my $value; - + # Go through each partition - foreach my $id(sort (keys %partitions)){ - # Split partition layout - @layout = split(/,/, $partitions{$id}{'partition'}); - %layoutAttr = (); - - # Go through each layout - for($i = 0; $i < @layout; $i++) { - # Remove parenthesis - $layout[$i] =~ s/(\(|\))//g; - $layout[$i] = trim($layout[$i]); - - # Split layout attributes - @attrs = split(/;/, $layout[$i]); - foreach(@attrs) { - ($name, $value) = split(/=/, $_, 2); - $name = trim($name); - $value = trim($value); - $layoutAttr{$i}{$name} = $value; - } - } - + foreach my $device_name(sort keys %partitions) { # Create head $xml .= < - $id + $device_name END - # Go through each layout and create section(s) - my $isLvm; - foreach my $p(keys %layoutAttr){ - $isLvm = 0; - - # If this partition is an LVM group - if($layoutAttr{$p}{'lvm_group'}) { + if (exists $partitions{$device_name}{'lvm'}) { + my %lvm_vols = %{ $partitions{$device_name}{'lvm'} }; + foreach my $vol(sort keys %lvm_vols) { + # Create section for LVM volume $xml .= < true false - $layoutAttr{$p}{'filesystem'} - false - false - $layoutAttr{$p}{'lvm_group'} - path - 142 - 1 - false - $layoutAttr{$p}{'size'} - -END - } - - # If this partition is an LVM volume - elsif($layoutAttr{$p}{'lv_name'}) { - $isLvm = 1; - $xml .= < - true - false - $layoutAttr{$p}{'filesystem'} + $lvm_vols{$vol}{'fs'} true acl,user_xattr - $layoutAttr{$p}{'lv_name'} - $layoutAttr{$p}{'mount'} + $lvm_vols{$vol}{'name'} + $lvm_vols{$vol}{'mount'} path 131 false - $layoutAttr{$p}{'size'} + $lvm_vols{$vol}{'size'} END } - - # Not an LVM - else { - $xml .= < section for LVM group + $xml .= < true - $layoutAttr{$p}{'filesystem'} + false + $partitions{$device_name}{'device_fs'} + false + false + $partitions{$device_name}{'device_lvm'} + path + 142 + 1 + false + $partitions{$device_name}{'device_size'} + +END + } else { + # Not an LVM group or volume + $xml .= < + true + $partitions{$device_name}{'device_fs'} true - $layoutAttr{$p}{'mount'} + $partitions{$device_name}{'device_mount'} path 131 1 primary - $layoutAttr{$p}{'size'} + $partitions{$device_name}{'device_size'} END - } } # Create tail - if(!$isLvm) { - $xml .= < + 4M + CT_LVM all END } else { - $xml .= < - 4M - CT_LVM all END @@ -709,7 +1008,7 @@ END =head3 createHosts Description : Create the section - Arguments : Hosts to be created on server + Arguments : Hosts to be created Returns : section Example : my $section = createHosts($hosts); @@ -717,47 +1016,8 @@ END #------------------------------------------------------- sub createHosts { - # Get string - my ($str) = @_; - - # Split the hosts - my @hosts = split(/\],/,$str); - - # Remove square brackets - my $i; - for($i = 0; $i < @hosts; $i++) { - $hosts[$i] =~ s/(\[|\])//g; - $hosts[$i] = trim($hosts[$i]); - } - - # Create hash table for each host - my %host; - my @args; - - my $id; - my $name; - my $value; - - # Loop through each host - foreach(@hosts) { - # Split the arguments - # e.g. host_address=10.1.100.100,name=gpok100.endicott.ibm.com gpok100 - @args = split(/,/,$_); - - # Host address should always be the first index - $args[0] =~ s/host_address=//g; - $id = trim($args[0]); - - # Go through each attribute and set hash table - for($i = 1; $i < @args; $i++) { - # Get the attribute name value pair - ($name, $value) = split(/=/, $args[$i], 2); - $name = trim($name); - $value = trim($value); - - $host{$id}{$name} = $value; - } - } + my ($hosts_ref) = @_; + my %hosts = %$hosts_ref; # Create section # e.g. @@ -769,28 +1029,18 @@ sub createHosts { # my $xml = ''; - # Create standard localhost entry - $xml .= < - 127.0.0.1 - - localhost - - -END - # Create host entries - foreach my $id(keys %host){ + foreach my $i(keys %hosts){ $xml .= < - $id + $hosts{$i}{'host_address'} - $host{$id}{'name'} + $hosts{$i}{'name'} END } - + return $xml; } @@ -799,7 +1049,7 @@ END =head3 createDns Description : Create the section - Arguments : DNS to use + Arguments : DNS Returns : section Example : my $section = createDns($dns); @@ -808,46 +1058,8 @@ END #------------------------------------------------------- sub createDns { # Get string - my ($str) = @_; - - # Split the hosts - my @dns = split(/\],/,$str); - - # Remove square brackets - my $i; - for($i = 0; $i < @dns; $i++) { - $dns[$i] =~ s/(\[|\])//g; - $dns[$i] = trim($dns[$i]); - } - - # Create hash table for each DNS - my %dn; - my @args; - - my $id; - my $name; - my $value; - - # Loop through each host - foreach(@dns) { - # Split the arguments - # e.g. hostname=gpok100,domain=endicott.ibm.com,nameserver=10.1.100.1 - @args = split(/,/,$_); - - # Hostname should always be the first index - $args[0] =~ s/hostname=//g; - $id = trim($args[0]); - - # Go through each attribute and set hash table - for($i = 1; $i < @args; $i++) { - # Get the attribute name value pair - ($name, $value) = split(/=/, $args[$i], 2); - $name = trim($name); - $value = trim($value); - - $dn{$id}{$name} = $value; - } - } + my ($dns_ref) = @_; + my %dns = %$dns_ref; # Create section # false @@ -858,14 +1070,14 @@ sub createDns { # 10.1.100.100 # my $xml = ''; - foreach my $id(keys %dn){ + foreach my $i(keys %dns){ $xml .= <$dn{$id}{'dhcp_hostname'} -$dn{$id}{'dhcp_resolv'} -$dn{$id}{'domain'} -$id +$dns{$i}{'dhcp_hostname'} +$dns{$i}{'dhcp_resolv'} +$dns{$i}{'domain'} +$dns{$i}{'hostname'} - $dn{$id}{'nameserver'} + $dns{$i}{'nameserver'} END } @@ -878,39 +1090,18 @@ END =head3 createDasdModules Description : Create the section for each dasd attached - Arguments : Dasd attached to server + Arguments : Dasd hash Returns : section - Example : my $section = createDasdModules($modules); + Example : my $section = createDasdModules($dasd_ref); =cut #------------------------------------------------------- sub createDasdModules { # Get string - my ($str) = @_; - - # Split the dasd - my @args = split(/\],/,$str); - - # Remove square brackets - my $i; - for($i = 0; $i < @args; $i++) { - $args[$i] =~ s/(\[|\])//g; - $args[$i] = trim($args[$i]); - } - - # Create hash table for each dasd - my %modules; - my @tmp; - foreach(@args) { - # Split the arguments - # e.g. 0.0.0100,dasd_eckd_mod,/dev/dasda,(/dev/dasda1;/dev/dasda2) - @tmp = split(/,/,$_,4); - $tmp[0] = trim($tmp[0]); - $modules{$tmp[0]}{'channel'} = $tmp[0]; - $modules{$tmp[0]}{'module'} = trim($tmp[1]); - } - + my ($dasd_ref) = @_; + my %dasd = %$dasd_ref; + # Create section # # dasd-bus-ccw-0.0.0100 @@ -919,11 +1110,11 @@ sub createDasdModules { # my $xml = ''; - foreach my $id(keys %modules){ + foreach my $addr(keys %dasd){ $xml .= < - dasd-bus-ccw-$id - $modules{$id}{'module'} + dasd-bus-ccw-$addr + $dasd{$addr}{'type'} END @@ -946,7 +1137,8 @@ END #------------------------------------------------------- sub createNicModules { # Get hash table - my (%interface) = @_; + my ($interfaces_ref) = @_; + my %interfaces = %$interfaces_ref; # Create section # @@ -958,14 +1150,13 @@ sub createNicModules { # # my $xml = ''; - my $script = ''; - foreach my $id(sort (keys %interface)){ + foreach my $i(sort (keys %interfaces)){ $xml .= < - $interface{$id}{'chanids'} + $interfaces{$i}{'chanids'} FOOBAR 3 - $id + $interfaces{$i}{'device'} qeth @@ -996,14 +1187,14 @@ sub createSoftware { my @software = split(/,/,$str); # Create section - # Basis-Devel - # Minimal - # base - # documentation - # file_server - # gnome - # print_server - # x11 + # Basis-Devel + # Minimal + # base + # documentation + # file_server + # gnome + # print_server + # x11 my $xml = ''; foreach (@software){ $xml .= < section # false @@ -1082,24 +1235,24 @@ sub createRoutes { my $xml = ''; my $dest = ''; - foreach my $id(sort (keys %interface)){ + foreach my $i(sort (keys %interfaces)){ if(!$dest) { # The first interface is the default route $dest = 'default'; } else { # Get network - $dest = substr($interface{$id}{'ipaddr'}, 0, rindex($interface{$id}{'ipaddr'}, '.')); + $dest = substr($interfaces{$i}{'ipaddr'}, 0, rindex($interfaces{$i}{'ipaddr'}, '.')); $dest .= ".0"; } - # Do not set route for DHCP interface - if(!($interface{$id}{'bootproto'} eq 'dhcp')) { + # Do not set gateway for DHCP interface + if(!($interfaces{$i}{'bootproto'} eq 'dhcp')) { $xml .= < $dest - $id + $interfaces{$i}{'device'} - $interface{$id}{'netmask'} + $interfaces{$i}{'netmask'} END } @@ -1122,18 +1275,19 @@ END #------------------------------------------------------- sub createScripts { # Get hash table - my (%interface) = @_; + my ($interfaces_ref) = @_; + my %interfaces = %$interfaces_ref; # Default route is being added by autoyast (bug) # Setting default route in post-script my $xml = ''; my $script = ''; - foreach my $id(sort (keys %interface)){ + foreach my $i(sort (keys %interfaces)){ # Set the default route for the firs interface # Do not set default route for DHCP interface - if(!$script && !($interface{$id}{'bootproto'} eq 'dhcp')) { + if(!$script && !($interfaces{$i}{'bootproto'} eq 'dhcp')) { $script .= < /etc/sysconfig/network/routes +echo "default - 0.0.0.0 $interfaces{$i}{'device'}" > /etc/sysconfig/network/routes END last; } @@ -1159,4 +1313,1421 @@ END } return $xml; +} + +#------------------------------------------------------- + +=head3 ask + + Description : Prompt user for input + Arguments : Question + Returns : Answer + Example : my $answer = ask("What day is today?"); + +=cut + +#------------------------------------------------------- +sub ask { + my ($question) = @_; + + print "$question"; + my $answer = <>; + return trim($answer); +} + +#------------------------------------------------------- + +=head3 pad + + Description : Pad a string to a given length + Arguments : String and size + Returns : Padded string + Example : my $str = pad($str, 12); + +=cut + +#------------------------------------------------------- +sub pad { + my ($str, $size) = @_; + + while (length($str) < $size) { + $str = "$str "; + } + + return $str; +} + +#------------------------------------------------------- + +=head3 genSles11Tmpl + + Description : Generate SLES 11 autoyast template + Arguments : Nothing + Returns : SLES 11 autoyast template + Example : my $tmpl = genSles11Tmpl(); + +=cut + +#------------------------------------------------------- +sub genSles11Tmpl { + my $tmpl = < + + + + + + + insert_devices + + + + + + + false + + + none + + + + + + + + + users + + + + floppy + + + + bin + daemon + + + xok + + + + nobody + + + + modem + + + + lp + + + + tty + + + + ! + postfix + + + + ! + gdm + + + + nogroup + nobody + + + ! + maildrop + + + + ! + messagebus + + + + video + + + + sys + + + + shadow + + + + console + + + + cdrom + + + + ! + haldaemon + + + + trusted + + + + dialout + + + + ! + ts-shell + + + + wheel + + + + www + + + + games + + + + disk + + + + audio + + + + ! + suse-ncc + + + + ftp + + + + ! + at + + + + kmem + + + + public + + + + root + + + + mail + + + + daemon + + + + ! + ntp + + + + uucp + + + + ! + ntadmin + + + + man + + + + utmp + + + + news + + + + ! + sshd + + + + + + + + + insert_hosts + + + + + + + + 1.0 + + + + + + en_US + + + + + + + + + + AUTO + + + insert_dns + + + insert_interfaces + + false + + + + + insert_modules + + + false + + insert_routes + + + + + + + false + false + false + + false + + + + + false + false + + + + + + insert_partitioning_drives + + + + + false + + + + localhost, 127.0.0.1 + + + + + + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + + + + + 5 + + + + + + + replace_software_patterns + + + replace_software_packages + + + + + + + UTC + US/Eastern + + + + + + 100 + video,dialout + /home + -1 + /bin/bash + /etc/skel + +AUTOYASTEND + + # Handle second half + $tmpl .= < + + + true + Games account + 100 + /var/games + + + + + + + + + /bin/bash + 12 + * + games + + + true + bin + 1 + /bin + + + + + + + + + /bin/bash + 1 + * + bin + + + true + nobody + 65533 + /var/lib/nobody + + + + + + + + + /bin/bash + 65534 + * + nobody + + + true + Printing daemon + 7 + /var/spool/lpd + + + + + + + + + /bin/bash + 4 + * + lp + + + true + Postfix Daemon + 51 + /var/spool/postfix + + + + + 99999 + 0 + 7 + + /bin/false + 51 + ! + postfix + + + true + Novell Customer Center User + 106 + /var/lib/YaST2/suse-ncc-fakehome + + + + + 99999 + 0 + 7 + + /bin/bash + 102 + ! + suse-ncc + + + true + FTP account + 49 + /srv/ftp + + + + + + + + + /bin/bash + 40 + * + ftp + + + false + root + 0 + /root + + + + + + + + + /bin/bash + 0 + insert_root_password + root + + + true + Mailer daemon + 12 + /var/spool/clientmqueue + + + + + + + + + /bin/false + 8 + * + mail + + + true + Daemon + 2 + /sbin + + + + + + + + + /bin/bash + 2 + * + daemon + + + true + NTP daemon + 103 + /var/lib/ntp + + + + + 99999 + 0 + 7 + + /bin/false + 74 + ! + ntp + + + true + Unix-to-Unix CoPy system + 14 + /etc/uucp + + + + + + + + + /bin/bash + 10 + * + uucp + + + User for D-BUS + 101 + /var/run/dbus + /bin/false + 100 + + + User for haldaemon + 102 + /var/run/hal + /bin/false + 101 + + + true + WWW daemon apache + 8 + /var/lib/wwwrun + + + + + + + + + /bin/false + 30 + * + wwwrun + + + true + Manual pages viewer + 62 + /var/cache/man + + + + + + + + + /bin/bash + 13 + * + man + + + true + News system + 13 + /etc/news + + + + + + + + + /bin/bash + 9 + * + news + + + true + SSH daemon + 65 + /var/lib/sshd + + + + + 99999 + 0 + 7 + + /bin/false + 71 + ! + sshd + + + + + + + + + + + + + + + +AUTOYASTEND + return $tmpl; +} + +#------------------------------------------------------- + +=head3 genSles10Tmpl + + Description : Generate SLES 10 autoyast template + Arguments : Nothing + Returns : SLES 10 autoyast template + Example : my $tmpl = genSles10Tmpl(); + +=cut + +#------------------------------------------------------- +sub genSles10Tmpl { + my $tmpl = < + + + + + + + insert_devices + + + + + + + false + + + none + + + + + + + + + users + + + + floppy + + + + bin + daemon + + + xok + + + + nobody + + + + modem + + + + lp + + + + tty + + + + ! + postfix + + + + ! + gdm + + + + nogroup + nobody + + + ! + maildrop + + + + ! + messagebus + + + + video + + + + sys + + + + shadow + + + + console + + + + cdrom + + + + ! + haldaemon + + + + trusted + + + + dialout + + + + ! + ts-shell + + + + wheel + + + + www + + + + games + + + + disk + + + + audio + + + + ! + suse-ncc + + + + ftp + + + + ! + at + + + + kmem + + + + public + + + + root + + + + mail + + + + daemon + + + + ! + ntp + + + + uucp + + + + ! + ntadmin + + + + man + + + + utmp + + + + news + + + + ! + sshd + + + + + + + + + insert_hosts + + + + + + + + 1.0 + + + + + + en_US + + + + + + + + + + AUTO + + + insert_dns + + + insert_interfaces + + false + + + + + insert_modules + + + false + + insert_routes + + + + + + + false + false + false + + false + + + + + false + false + + + + + + insert_partitioning_drives + + + + + false + + + + localhost, 127.0.0.1 + + + + + + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + + true + true + 0 + + + + + + 5 + + + + + + + replace_software_patterns + + + replace_software_packages + + + + + + + UTC + US/Eastern + + + + + + 100 + video,dialout + /home + -1 + /bin/bash + /etc/skel + +AUTOYASTEND + + $tmpl .= < + + + true + Games account + 100 + /var/games + + + + + + + + + /bin/bash + 12 + * + games + + + true + bin + 1 + /bin + + + + + + + + + /bin/bash + 1 + * + bin + + + true + nobody + 65533 + /var/lib/nobody + + + + + + + + + /bin/bash + 65534 + * + nobody + + + true + Printing daemon + 7 + /var/spool/lpd + + + + + + + + + /bin/bash + 4 + * + lp + + + true + Postfix Daemon + 51 + /var/spool/postfix + + + + + 99999 + 0 + 7 + + /bin/false + 51 + ! + postfix + + + true + Novell Customer Center User + 106 + /var/lib/YaST2/suse-ncc-fakehome + + + + + 99999 + 0 + 7 + + /bin/bash + 102 + ! + suse-ncc + + + true + FTP account + 49 + /srv/ftp + + + + + + + + + /bin/bash + 40 + * + ftp + + + false + root + 0 + /root + + + + + + + + + /bin/bash + 0 + insert_root_password + root + + + true + Mailer daemon + 12 + /var/spool/clientmqueue + + + + + + + + + /bin/false + 8 + * + mail + + + true + Daemon + 2 + /sbin + + + + + + + + + /bin/bash + 2 + * + daemon + + + true + NTP daemon + 103 + /var/lib/ntp + + + + + 99999 + 0 + 7 + + /bin/false + 74 + ! + ntp + + + true + Unix-to-Unix CoPy system + 14 + /etc/uucp + + + + + + + + + /bin/bash + 10 + * + uucp + + + User for D-BUS + 101 + /var/run/dbus + /bin/false + 100 + + + User for haldaemon + 102 + /var/run/hal + /bin/false + 101 + + + true + WWW daemon apache + 8 + /var/lib/wwwrun + + + + + + + + + /bin/false + 30 + * + wwwrun + + + true + Manual pages viewer + 62 + /var/cache/man + + + + + + + + + /bin/bash + 13 + * + man + + + true + News system + 13 + /etc/news + + + + + + + + + /bin/bash + 9 + * + news + + + true + SSH daemon + 65 + /var/lib/sshd + + + + + 99999 + 0 + 7 + + /bin/false + 71 + ! + sshd + + + + + + + + + + + + + + + +AUTOYASTEND + return $tmpl; } \ No newline at end of file