-Fix rspreset for blades
-Stateless image tweaks including squashfs ram hosted image git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@414 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		@@ -23,6 +23,7 @@ sub handled_commands {
 | 
			
		||||
    rvitals => 'nodehm:vitals,mgt',
 | 
			
		||||
    rinv => 'nodehm:inv,mgt',
 | 
			
		||||
    rbeacon => 'nodehm:beacon,mgt',
 | 
			
		||||
    rspreset => 'nodehm:mgt',
 | 
			
		||||
    rbootseq => 'nodehm:bootseq,mgt',
 | 
			
		||||
    reventlog => 'nodehm:eventlog,mgt',
 | 
			
		||||
  };
 | 
			
		||||
@@ -186,14 +187,17 @@ sub resetmp {
 | 
			
		||||
  my $data;
 | 
			
		||||
  my $stat;
 | 
			
		||||
  my $rc;
 | 
			
		||||
  $data = $session->set($mpresetoid.".$slot", 1);
 | 
			
		||||
  #$data = $session->set($mpresetoid.".$slot", 1);
 | 
			
		||||
  $data = $session->set(new SNMP::Varbind([".".$mpresetoid,$slot,1,'INTEGER']));
 | 
			
		||||
  unless ($data) { return (1,$session->{ErrorStr}); }
 | 
			
		||||
  return (0,"mpreset");
 | 
			
		||||
  #if ($session->{ErrorStr}) { return (1,$session->{ErrorStr}); }
 | 
			
		||||
  if ($session->{ErrorStr}) { return (1,$session->{ErrorStr}); }
 | 
			
		||||
  if ($data->{$mpresetoid.".$slot"} == 1) {
 | 
			
		||||
    return (0, "mpreset");
 | 
			
		||||
  } else {
 | 
			
		||||
    return (1,"error");
 | 
			
		||||
  }
 | 
			
		||||
  #if ($session->{ErrorStr}) { return (1,$session->{ErrorStr}); }
 | 
			
		||||
  #if ($data->{$mpresetoid.".$slot"} == 1) {
 | 
			
		||||
  #  return (0, "mpreset");
 | 
			
		||||
  #} else {
 | 
			
		||||
  #  return (1,"error");
 | 
			
		||||
  #}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub walkelog {
 | 
			
		||||
@@ -1008,7 +1012,7 @@ sub dompa {
 | 
			
		||||
                    SecLevel => 'authPriv',
 | 
			
		||||
                    UseNumeric => 1,
 | 
			
		||||
                    Retries => 2, # Give up sooner to make commands go smoother
 | 
			
		||||
                    Timeout=>1200000, #Beacon, for one, takes a bit over a second to return
 | 
			
		||||
                    Timeout=>1300000, #Beacon, for one, takes a bit over a second to return
 | 
			
		||||
                    PrivPass => $mpahash->{$mpa}->{password});
 | 
			
		||||
  if ($session->{ErrorStr}) { return 1,$session->{ErrorStr}; }
 | 
			
		||||
  unless ($session) {
 | 
			
		||||
 
 | 
			
		||||
@@ -114,7 +114,12 @@ sub mknetboot {
 | 
			
		||||
        my $arch = $ent->{arch};
 | 
			
		||||
        my $profile = $ent->{profile};
 | 
			
		||||
         #packimage($osver,$arch,$profile,$installroot,$callback);
 | 
			
		||||
         unless (-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.gz" and
 | 
			
		||||
         my $suffix = 'gz';
 | 
			
		||||
         if (-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") {
 | 
			
		||||
            $suffix = 'sfs';
 | 
			
		||||
         }
 | 
			
		||||
         unless ((-r "/$installroot/netboot/$osver/$arch/$profile/rootimg.gz" or
 | 
			
		||||
         -r "/$installroot/netboot/$osver/$arch/$profile/rootimg.sfs") and
 | 
			
		||||
         -r "/$installroot/netboot/$osver/$arch/$profile/kernel" and
 | 
			
		||||
         -r  "/$installroot/netboot/$osver/$arch/$profile/initrd.gz") {
 | 
			
		||||
            $callback->({error=>["No packed image for platform $osver, architecture $arch, profile $profile, please run packimage -o $osver -p $profile -a $arch"],errorcode=>[1]});
 | 
			
		||||
@@ -143,7 +148,7 @@ sub mknetboot {
 | 
			
		||||
           $callback->({error=>["Unable to determine image server for $node"]});
 | 
			
		||||
           next;
 | 
			
		||||
        }
 | 
			
		||||
        my $kcmdline = "imgurl=$imgsrv/install/netboot/$osver/$arch/$profile/rootimg.gz ";
 | 
			
		||||
        my $kcmdline = "imgurl=http://$imgsrv/install/netboot/$osver/$arch/$profile/rootimg.$suffix ";
 | 
			
		||||
        if (defined $ent->{serialport}) {
 | 
			
		||||
            my $sent = $hmtab->getNodeAttribs($node,['serialspeed','serialflow']);
 | 
			
		||||
            unless ($sent->{serialspeed}) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										92
									
								
								xCAT-server-2.0/lib/xcat/plugins/packimage.pm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								xCAT-server-2.0/lib/xcat/plugins/packimage.pm
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
			
		||||
package xCAT_plugin::packimage;
 | 
			
		||||
use xCAT::Table;
 | 
			
		||||
use Getopt::Long;
 | 
			
		||||
use File::Path;
 | 
			
		||||
use Cwd;
 | 
			
		||||
use File::Temp;
 | 
			
		||||
Getopt::Long::Configure("bundling");
 | 
			
		||||
Getopt::Long::Configure("pass_through");
 | 
			
		||||
 | 
			
		||||
sub handled_commands {
 | 
			
		||||
     return {
 | 
			
		||||
            packimage => "packimage",
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
sub process_request {
 | 
			
		||||
   my $sitetab = xCAT::Table->new('site');
 | 
			
		||||
   my $request = shift;
 | 
			
		||||
   my $callback = shift;
 | 
			
		||||
   my $doreq = shift;
 | 
			
		||||
   my $ent = $sitetab->getAttribs({key=>'installdir'},['value']);
 | 
			
		||||
   my $installroot = "/install";
 | 
			
		||||
 | 
			
		||||
   if ($ent and $ent->{value}) {
 | 
			
		||||
      $installroot = $ent->{value};
 | 
			
		||||
   }
 | 
			
		||||
   @ARGV = @{$request->{arg}};
 | 
			
		||||
    my $osver;
 | 
			
		||||
    my $arch;
 | 
			
		||||
    my $profile;
 | 
			
		||||
    my $method='cpio';
 | 
			
		||||
   GetOptions(
 | 
			
		||||
      "profile|p=s" => \$profile,
 | 
			
		||||
      "arch|a=s" => \$arch,
 | 
			
		||||
      "osver|o=s" => \$osver,
 | 
			
		||||
      "method|m=s" => \$method
 | 
			
		||||
      );
 | 
			
		||||
   my $distname = $osver;
 | 
			
		||||
   $distname =~ s/\d+$//;
 | 
			
		||||
    unless ($installroot) {
 | 
			
		||||
        $callback->({error=>["No installdir defined in site table"],errorcode=>[1]});
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    my $oldpath=cwd();
 | 
			
		||||
    my $exlistloc;
 | 
			
		||||
    if (-r "$::XCATROOT/share/xcat/netboot/$distname/$profile.$osver.$arch.exlist") {
 | 
			
		||||
       $exlistloc = "$::XCATROOT/share/xcat/netboot/$distname/$profile.$osver.$arch.exlist";
 | 
			
		||||
    } elsif (-r "$::XCATROOT/share/xcat/netboot/$distname/$profile.$arch.exlist") {
 | 
			
		||||
       $exlistloc = "$::XCATROOT/share/xcat/netboot/$distname/$profile.$arch.exlist";
 | 
			
		||||
    } elsif (-r "$::XCATROOT/share/xcat/netboot/$distname/$profile.$osver.exlist") {
 | 
			
		||||
       $exlistloc = "$::XCATROOT/share/xcat/netboot/$distname/$profile.$osver.exlist";
 | 
			
		||||
    } elsif (-r "$::XCATROOT/share/xcat/netboot/$distname/$profile.exlist") {
 | 
			
		||||
       $exlistloc = "$::XCATROOT/share/xcat/netboot/$distname/$profile.exlist";
 | 
			
		||||
    } else {
 | 
			
		||||
       $callback->({error=>["Unable to finde file exclusion list under $::XCATROOT/share/xcat/netboot/$distname/ for $profile/$arch/$osver"],errorcode=>[1]});
 | 
			
		||||
       next;
 | 
			
		||||
    }
 | 
			
		||||
    my $exlist;
 | 
			
		||||
    open($exlist,"<",$exlistloc);
 | 
			
		||||
    my $excludestr = "find . ";
 | 
			
		||||
    while (<$exlist>) {
 | 
			
		||||
       chomp $_;
 | 
			
		||||
       $excludestr .= "'!' -wholename '".$_."' -a ";
 | 
			
		||||
    }
 | 
			
		||||
    close($exlist);
 | 
			
		||||
    $callback->({data=>["Packing contents of $installroot/netboot/$osver/$arch/$profile/rootimg"]});
 | 
			
		||||
    my $temppath;
 | 
			
		||||
    if ($method =~ /cpio/) {
 | 
			
		||||
       $excludestr =~ s!-a \z!|cpio -H newc -o | gzip -c - > ../rootimg.gz!;
 | 
			
		||||
    } elsif ($method =~ /squashfs/) {
 | 
			
		||||
      $temppath = mkdtemp("/tmp/packimage.$$.XXXXXXXX");
 | 
			
		||||
      $excludestr =~ s!-a \z!|cpio -dump $temppath!; 
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (! -d "$installroot/netboot/$osver/$arch/$profile/rootimg") {
 | 
			
		||||
       $callback->({error=>["$installroot/netboot/$osver/$arch/$profile/rootimg does not exist, run genimage -o $osver -p $profile on a server with matching architecture"]});
 | 
			
		||||
       return;
 | 
			
		||||
    }
 | 
			
		||||
    chdir("$installroot/netboot/$osver/$arch/$profile/rootimg");
 | 
			
		||||
    system($excludestr);
 | 
			
		||||
    if ($method =~ /squashfs/) {
 | 
			
		||||
       my $flags;
 | 
			
		||||
       if ($arch =~ /x86/) {
 | 
			
		||||
          $flags="-le";
 | 
			
		||||
       } elsif ($arch =~ /ppc/) {
 | 
			
		||||
          $flags="-be";
 | 
			
		||||
       }
 | 
			
		||||
       system("mksquashfs $temppath ../rootimg.sfs $flags");
 | 
			
		||||
       chmod(0644,"../rootimg.sfs");
 | 
			
		||||
    }
 | 
			
		||||
    chdir($oldpath);
 | 
			
		||||
}
 | 
			
		||||
@@ -9,4 +9,5 @@
 | 
			
		||||
./usr/share/info*
 | 
			
		||||
./usr/share/omf*
 | 
			
		||||
./usr/lib/locale*
 | 
			
		||||
./usr/lib/perl5*
 | 
			
		||||
./boot*
 | 
			
		||||
 
 | 
			
		||||
@@ -16,6 +16,7 @@ my %libhash;
 | 
			
		||||
my @filestoadd;
 | 
			
		||||
my $profile;
 | 
			
		||||
my $osver;
 | 
			
		||||
my $pathtofiles=dirname($0);
 | 
			
		||||
GetOptions(
 | 
			
		||||
   #'a=s' => \$architecture,
 | 
			
		||||
   'p=s' => \$profile,
 | 
			
		||||
@@ -48,14 +49,26 @@ unless ( -d $srcdir."/repodata" ) {
 | 
			
		||||
   print "Need $installroot/$osver/$arch/repodata available from a system that has ran copycds on $osver $arch";
 | 
			
		||||
   exit 1;
 | 
			
		||||
}
 | 
			
		||||
my $pathtofiles=dirname($0);
 | 
			
		||||
my $yumconfig;
 | 
			
		||||
open($yumconfig,">","/tmp/genimage.$$.yum.conf");
 | 
			
		||||
print $yumconfig "[$osver-$arch]\nname=$osver-$arch\nbaseurl=file://$srcdir\ngpgpcheck=0\n";
 | 
			
		||||
close($yumconfig);
 | 
			
		||||
my $yumcmd = "yum -y -c /tmp/genimage.$$.yum.conf --installroot=$installroot/netboot/$osver/$arch/$profile/rootimg/ --disablerepo=* --enablerepo=$osver-$arch install ";
 | 
			
		||||
mkpath("$installroot/netboot/$osver/$arch/$profile/rootimg/var/lib/yum");
 | 
			
		||||
open($yumconfig,"<","$pathtofiles/$profile.pkglist");
 | 
			
		||||
my $pkglist;
 | 
			
		||||
if (-r "$pathtofiles/$profile.$osver.$arch.pkglist") {
 | 
			
		||||
   $pkglist = "$pathtofiles/$profile.$osver.$arch.pkglist";
 | 
			
		||||
} elsif (-r "$pathtofiles/$profile.$arch.pkglist") {
 | 
			
		||||
   $pkglist = "$pathtofiles/$profile.$arch.pkglist";
 | 
			
		||||
} elsif (-r "$pathtofiles/$profile.$osver.pkglist") {
 | 
			
		||||
   $pkglist = "$pathtofiles/$profile.$osver.pkglist";
 | 
			
		||||
} elsif (-r "$pathtofiles/$profile.$arch.pkglist") {
 | 
			
		||||
   $pkglist = "$pathtofiles/$profile.pkglist";
 | 
			
		||||
} else {
 | 
			
		||||
   print "Unable to find package list for $profile!";
 | 
			
		||||
   return 1;
 | 
			
		||||
}
 | 
			
		||||
open($yumconfig,"<","$pkglist");
 | 
			
		||||
while (<$yumconfig>) {
 | 
			
		||||
   chomp;
 | 
			
		||||
   $yumcmd .= $_ . " ";
 | 
			
		||||
@@ -149,13 +162,28 @@ sub mkinitrd {
 | 
			
		||||
   print $inifile "cd /\n";
 | 
			
		||||
   print $inifile "for i in `cat /proc/cmdline`; do\n";
 | 
			
		||||
   print $inifile "   KEY=`echo \$i |awk -F= '{print \$1}'`\n";
 | 
			
		||||
   print $inifile "   if [ \"\$KEY\" = 'imgurl' ]; then\n";
 | 
			
		||||
   print $inifile "      wget http://`echo \$i | awk -F= '{print \$2}'`\n";
 | 
			
		||||
   print $inifile "   if [ \"\$KEY\" == 'imgurl' ]; then\n";
 | 
			
		||||
   print $inifile "      VALUE=`echo \$i |awk -F= '{print \$2}'`\n";
 | 
			
		||||
   print $inifile "      if [ \"http\" == \"`echo \$VALUE|awk -F: '{print \$1}'`\" ]; then\n";
 | 
			
		||||
   print $inifile "        wget \$VALUE\n";
 | 
			
		||||
   print $inifile "     fi\n";
 | 
			
		||||
   print $inifile "   fi\n";
 | 
			
		||||
   print $inifile "done\n";
 | 
			
		||||
   print $inifile "mount -t tmpfs rootfs /sysroot\n";
 | 
			
		||||
   print $inifile "cd /sysroot\n";
 | 
			
		||||
   print $inifile "if [ ! -r /rootimg.gz ]; then\n";
 | 
			
		||||
   print $inifile "if [ -r /rootimg.sfs ]; then\n";
 | 
			
		||||
   print $inifile "  echo Setting up squashfs with ram overlay\n";
 | 
			
		||||
   print $inifile "  mknod /dev/loop0 b 7 0\n";
 | 
			
		||||
   print $inifile "  mkdir -p /ro\n";
 | 
			
		||||
   print $inifile "  mkdir -p /rw\n";
 | 
			
		||||
   print $inifile "  mount -t squashfs /rootimg.sfs /ro\n";
 | 
			
		||||
   print $inifile "  mount -t tmpfs rw /rw\n";
 | 
			
		||||
   print $inifile "  mount -t aufs -o dirs=/rw:/ro mergedroot  /sysroot\n";
 | 
			
		||||
   print $inifile "elif [ -r /rootimg.gz ]; then\n";
 | 
			
		||||
   print $inifile "  mount -t tmpfs rootfs /sysroot\n";
 | 
			
		||||
   print $inifile "  cd /sysroot\n";
 | 
			
		||||
   print $inifile "  echo -n \"Extracting root filesystem:\"\n";
 | 
			
		||||
   print $inifile "  zcat /rootimg.gz |cpio -idum\n";
 | 
			
		||||
   print $inifile "  echo Done";
 | 
			
		||||
   print $inifile "else\n";
 | 
			
		||||
   print $inifile "  echo -n Failed to download image, panicing in 5...\n";
 | 
			
		||||
   print $inifile "  for i in 4 3 2 1 0; do\n";
 | 
			
		||||
   print $inifile "    /bin/sleep 1\n";
 | 
			
		||||
@@ -164,9 +192,6 @@ sub mkinitrd {
 | 
			
		||||
   print $inifile "  echo\n";
 | 
			
		||||
   print $inifile "  exit\n";
 | 
			
		||||
   print $inifile "fi\n";
 | 
			
		||||
   print $inifile "echo -n \"Extracting root filesystem:\"\n";
 | 
			
		||||
   print $inifile "zcat /rootimg.gz |cpio -idum\n";
 | 
			
		||||
   print $inifile "echo Done";
 | 
			
		||||
   print $inifile "cd /\n";
 | 
			
		||||
   print $inifile "cp /var/lib/dhclient/dhclient.leases /sysroot/dev/.dhclient-eth0.leases\n";
 | 
			
		||||
   print $inifile "mknod /sysroot/dev/console c 5 1\n";
 | 
			
		||||
@@ -179,6 +204,11 @@ sub mkinitrd {
 | 
			
		||||
	chmod(0755,"/tmp/xcatinitrd.$$/init");
 | 
			
		||||
	chmod(0755,"/tmp/xcatinitrd.$$/bin/netstart");
 | 
			
		||||
   @filestoadd=();
 | 
			
		||||
   foreach (@ndrivers) {
 | 
			
		||||
      if (-f "$pathtofiles/$_") {
 | 
			
		||||
         push @filestoadd,[$_,"lib/$_"];
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
   foreach ("sbin/nash","sbin/busybox.anaconda","sbin/rmmod") {
 | 
			
		||||
      getlibs($_);
 | 
			
		||||
      push @filestoadd,$_;
 | 
			
		||||
@@ -187,10 +217,18 @@ sub mkinitrd {
 | 
			
		||||
   find(\&isnetdriver, <$installroot/netboot/$osver/$arch/$profile/rootimg/lib/modules/*>);
 | 
			
		||||
   foreach (@filestoadd) {
 | 
			
		||||
      if (ref($_)) {
 | 
			
		||||
         copy("$installroot/netboot/$osver/$arch/$profile/rootimg/".$_->[0],"/tmp/xcatinitrd.$$/".$_->[1]);
 | 
			
		||||
         my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/".$_->[0];
 | 
			
		||||
         if (-f "$pathtofiles/".$_->[0]) {
 | 
			
		||||
            $srcpath="$pathtofiles/".$_->[0];
 | 
			
		||||
         }
 | 
			
		||||
         copy($srcpath,"/tmp/xcatinitrd.$$/".$_->[1]);
 | 
			
		||||
         chmod 0755,"/tmp/xcatinitrd.$$/".$_->[1];
 | 
			
		||||
      } else {
 | 
			
		||||
         copy("$installroot/netboot/$osver/$arch/$profile/rootimg/$_","/tmp/xcatinitrd.$$/$_");
 | 
			
		||||
         my $srcpath = "$installroot/netboot/$osver/$arch/$profile/rootimg/$_";
 | 
			
		||||
         if (-f "$pathtofiles/$_") {
 | 
			
		||||
            $srcpatch = "$pathtofiles/$_";
 | 
			
		||||
         }
 | 
			
		||||
         copy("$srcpath","/tmp/xcatinitrd.$$/$_");
 | 
			
		||||
         chmod 0755,"/tmp/xcatinitrd.$$/".$_;
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user