mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-30 19:02:27 +00:00 
			
		
		
		
	osimage phase3: use osimage table settings updatenode (otherpkgs)
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4290 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -1,5 +1,10 @@ | ||||
| # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html | ||||
| package xCAT::Postage; | ||||
| BEGIN | ||||
| { | ||||
|     $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; | ||||
| } | ||||
| use lib "$::XCATROOT/lib/perl"; | ||||
| use xCAT::Table; | ||||
| use xCAT::MsgUtils; | ||||
| use xCAT::NodeRange; | ||||
| @@ -8,11 +13,7 @@ use xCAT::SvrUtils; | ||||
| use Data::Dumper; | ||||
| use File::Basename; | ||||
| use strict; | ||||
| BEGIN | ||||
| { | ||||
|     $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : -d '/opt/xcat' ? '/opt/xcat' : '/usr'; | ||||
| } | ||||
| use lib "$::XCATROOT/lib/perl"; | ||||
|  | ||||
|  | ||||
| #------------------------------------------------------------------------------- | ||||
|  | ||||
| @@ -160,7 +161,7 @@ sub makescript { | ||||
|   push @scriptd, "NODE=$node\n"; | ||||
|   push @scriptd, "export NODE\n"; | ||||
|   | ||||
|   my $et = $typetab->getNodeAttribs($node,['os','arch','profile']); | ||||
|   my $et = $typetab->getNodeAttribs($node,['os','arch','profile','provmethod']); | ||||
|   if ($^O =~ /^linux/i) { | ||||
| 	unless ($et and $et->{'os'} and $et->{'arch'}) { | ||||
| 		my %rsp; | ||||
| @@ -179,6 +180,7 @@ sub makescript { | ||||
|   my $os; | ||||
|   my $profile; | ||||
|   my $arch; | ||||
|   my $provmethod=$et->{'provmethod'}; | ||||
|   if ($et->{'os'}) { | ||||
|         $os=$et->{'os'}; | ||||
|   	push @scriptd, "OSVER=".$et->{'os'}."\n"; | ||||
| @@ -258,54 +260,84 @@ sub makescript { | ||||
|   } | ||||
|  | ||||
|   #get packge names for extra rpms | ||||
|   my $stat="install"; | ||||
|   if ($profile) { | ||||
|     my $platform="rh"; | ||||
|     if ($os) { | ||||
|       if ($os =~ /rh.*/)    { $platform = "rh"; } | ||||
|       elsif ($os =~ /centos.*/) { $platform = "centos"; } | ||||
|       elsif ($os =~ /fedora.*/) { $platform = "fedora"; } | ||||
|       elsif ($os =~ /sles.*/) { $platform = "sles"; } | ||||
|       elsif ($os =~ /aix.*/) { $platform = "aix"; } | ||||
|     } | ||||
|     if (($nodesetstate) && ($nodesetstate eq "netboot")) { $stat="netboot";} | ||||
|     my $pkglist=xCAT::SvrUtils->get_otherpkgs_pkglist_file_name("/install/custom/$stat/$platform", $profile,  $os, $arch); | ||||
|     if (!$pkglist) { $pkglist=xCAT::SvrUtils->get_otherpkgs_pkglist_file_name("$::XCATROOT/share/xcat/$stat/$platform", $profile, $os, $arch); } | ||||
|   my $otherpkgdir; | ||||
|   my $pkglist; | ||||
|   if (($^O =~ /^linux/i) && ($provmethod) && ( $provmethod ne "install") && ($provmethod ne "netboot")) { | ||||
|       #this is the case where image from the osimage table is used | ||||
|       my $linuximagetab=xCAT::Table->new('linuximage', -create=>1); | ||||
|       (my $ref1) = $linuximagetab->getAttribs({imagename => $provmethod}, 'otherpkglist', 'otherpkgdir'); | ||||
|       if ($ref1) { | ||||
| 	  if ($ref1->{'otherpkglist'}) { | ||||
| 	      $pkglist=$ref1->{'otherpkglist'}; | ||||
| 	      if ($ref1->{'otherpkgdir'}) { | ||||
| 		  push @scriptd, "OTHERPKGDIR=". $ref1->{'otherpkgdir'} . "\n"; | ||||
| 		  push @scriptd, "export OTHERPKGDIR\n"; | ||||
| 	      } | ||||
| 	  } | ||||
|       } | ||||
|   } else { | ||||
|       my $stat="install"; | ||||
|       if ($profile) { | ||||
| 	  my $platform="rh"; | ||||
| 	  if ($os) { | ||||
| 	      if ($os =~ /rh.*/)    { $platform = "rh"; } | ||||
| 	      elsif ($os =~ /centos.*/) { $platform = "centos"; } | ||||
| 	      elsif ($os =~ /fedora.*/) { $platform = "fedora"; } | ||||
| 	      elsif ($os =~ /sles.*/) { $platform = "sles"; } | ||||
| 	      elsif ($os =~ /aix.*/) { $platform = "aix"; } | ||||
| 	  } | ||||
| 	  if (($nodesetstate) && ($nodesetstate eq "netboot")) { $stat="netboot";} | ||||
| 	  $pkglist=xCAT::SvrUtils->get_otherpkgs_pkglist_file_name("/install/custom/$stat/$platform", $profile,  $os, $arch); | ||||
| 	  if (!$pkglist) { $pkglist=xCAT::SvrUtils->get_otherpkgs_pkglist_file_name("$::XCATROOT/share/xcat/$stat/$platform", $profile, $os, $arch); } | ||||
|       } | ||||
|   } | ||||
|   print "pkglist=$pkglist\n"; | ||||
|  | ||||
|     if ($pkglist) { | ||||
|   if ($pkglist) { | ||||
|       my @otherpkgs=(); | ||||
|       if (open(FILE1, "<$pkglist")) { | ||||
|         while (readline(FILE1)) { | ||||
| 	  chomp($_); #remove newline | ||||
|           s/\s+$//;  #remove trailing spaces | ||||
|           next if /^\s*$/; #-- skip empty lines | ||||
|           push(@otherpkgs,$_); | ||||
|         } | ||||
|         close(FILE1); | ||||
| 	  while (readline(FILE1)) { | ||||
| 	      chomp($_); #remove newline | ||||
| 	      s/\s+$//;  #remove trailing spaces | ||||
| 	      next if /^\s*$/; #-- skip empty lines | ||||
| 	      push(@otherpkgs,$_); | ||||
| 	  } | ||||
| 	  close(FILE1); | ||||
|       }  | ||||
|       if ( @otherpkgs > 0) { | ||||
|         my $pkgtext=join(',',@otherpkgs); | ||||
|        | ||||
|         #handle the #INLCUDE# tag recursively | ||||
|         my $idir = dirname($pkglist); | ||||
|         my $doneincludes=0; | ||||
| 	while (not $doneincludes) { | ||||
| 	    $doneincludes=1; | ||||
| 	    if ($pkgtext =~ /#INCLUDE:[^#]+#/) { | ||||
| 		$doneincludes=0; | ||||
| 		$pkgtext =~ s/#INCLUDE:([^#]+)#/includefile($1,$idir)/eg; | ||||
| 	    } | ||||
| 	} | ||||
|   | ||||
|         push @scriptd, "OTHERPKGS=$pkgtext\n"; | ||||
|         push @scriptd, "export OTHERPKGS\n"; | ||||
| 	  my $pkgtext=join(',',@otherpkgs); | ||||
| 	   | ||||
| 	  #handle the #INLCUDE# tag recursively | ||||
| 	  my $idir = dirname($pkglist); | ||||
| 	  my $doneincludes=0; | ||||
| 	  while (not $doneincludes) { | ||||
| 	      $doneincludes=1; | ||||
| 	      if ($pkgtext =~ /#INCLUDE:[^#]+#/) { | ||||
| 		  $doneincludes=0; | ||||
| 		  $pkgtext =~ s/#INCLUDE:([^#]+)#/includefile($1,$idir)/eg; | ||||
| 	      } | ||||
| 	  } | ||||
| 	   | ||||
| 	  push @scriptd, "OTHERPKGS=$pkgtext\n"; | ||||
| 	  push @scriptd, "export OTHERPKGS\n"; | ||||
|  | ||||
|       }     | ||||
|     } | ||||
|   } | ||||
|  | ||||
|    | ||||
|   # check if there are sync files to be handled | ||||
|   my $syncfile = xCAT::SvrUtils->getsynclistfile(undef, $os, $arch, $profile, $nodesetstate); | ||||
|   my $syncfile; | ||||
|   if (($provmethod) && ( $provmethod ne "install") && ($provmethod ne "netboot")) { | ||||
|       my $osimagetab=xCAT::Table->new('osimage', -create=>1); | ||||
|       if ($osimagetab) { | ||||
| 	  (my $ref) = $osimagetab->getAttribs({imagename => $provmethod}, 'osvers', 'osarch', 'profile', 'provmethod', 'synclists'); | ||||
| 	  if ($ref) { | ||||
| 	      $syncfile=$ref->{'synclists'} | ||||
| 	  } | ||||
|       } | ||||
|   } else { | ||||
|       $syncfile = xCAT::SvrUtils->getsynclistfile(undef, $os, $arch, $profile, $nodesetstate); | ||||
|   } | ||||
|   if (! defined ($syncfile)) { | ||||
|       push @scriptd, "NOSYNCFILES=1\n"; | ||||
|       push @scriptd, "export NOSYNCFILES\n"; | ||||
|   | ||||
| @@ -208,7 +208,6 @@ sub get_nodeset_state | ||||
| #----------------------------------------------------------------------------- | ||||
|  | ||||
|  | ||||
|  | ||||
| sub getsynclistfile() | ||||
| { | ||||
|   my $nodes = shift; | ||||
| @@ -231,13 +230,18 @@ sub getsynclistfile() | ||||
|     unless ($nodetype_t) { | ||||
|       return ; | ||||
|     } | ||||
|     my $nodetype_v = $nodetype_t->getNodesAttribs($nodes, ['profile']); | ||||
|     my $nodetype_v = $nodetype_t->getNodesAttribs($nodes, ['profile', 'provmethod']); | ||||
|  | ||||
|     # the vaule of profile for AIX node is the osimage name | ||||
|     foreach my $node (@$nodes) { | ||||
|       my $profile = $nodetype_v->{$node}->[0]->{'profile'}; | ||||
|       my $provmethod=$nodetype_v->{$node}->[0]->{'provmethod'}; | ||||
|       if ($provmethod) { | ||||
| 	  $profile=$provmethod; | ||||
|       } | ||||
| 	   | ||||
|       $node_syncfile{$node} = $profile; | ||||
|  | ||||
|        | ||||
|       if (! grep /$profile/, @profiles) { | ||||
|         push @profiles, $profile; | ||||
|       } | ||||
| @@ -281,38 +285,50 @@ sub getsynclistfile() | ||||
|     unless ($nodetype_t) { | ||||
|       return ; | ||||
|     } | ||||
|     my $nodetype_v = $nodetype_t->getNodesAttribs($nodes, ['profile','os','arch']); | ||||
|     my $nodetype_v = $nodetype_t->getNodesAttribs($nodes, ['profile','os','arch','provmethod']); | ||||
|  | ||||
|     foreach my $node (@$nodes) { | ||||
|       $inst_type = $node_insttype{$node}; | ||||
|       if ($inst_type eq "netboot" || $inst_type eq "diskless") { | ||||
|         $inst_type = "netboot"; | ||||
|       my $provmethod=$nodetype_v->{$node}->[0]->{'provmethod'}; | ||||
|       if (($provmethod) && ( $provmethod ne "install") && ($provmethod ne "netboot")) { | ||||
| 	  # get the syncfiles base on the osimage | ||||
| 	  my $osimage_t = xCAT::Table->new('osimage'); | ||||
| 	  unless ($osimage_t) { | ||||
| 	      return ; | ||||
| 	  } | ||||
| 	  my $synclist = $osimage_t->getAttribs({imagename=>$provmethod}, 'synclists'); | ||||
| 	  if ($synclist && $synclist->{'synclists'}) { | ||||
| 	      $node_syncfile{$node} = $synclist->{'synclists'}; | ||||
| 	  }   | ||||
|       } else { | ||||
|         $inst_type = "install"; | ||||
|       } | ||||
| 	  $inst_type = $node_insttype{$node}; | ||||
| 	  if ($inst_type eq "netboot" || $inst_type eq "diskless") { | ||||
| 	      $inst_type = "netboot"; | ||||
| 	  } else { | ||||
| 	      $inst_type = "install"; | ||||
| 	  } | ||||
| 	   | ||||
| 	  $profile = $nodetype_v->{$node}->[0]->{'profile'}; | ||||
| 	  $os = $nodetype_v->{$node}->[0]->{'os'}; | ||||
| 	  $arch = $nodetype_v->{$node}->[0]->{'arch'}; | ||||
| 	  my $platform = ""; | ||||
| 	  if ($os) { | ||||
| 	      if ($os =~ /rh.*/)    { $platform = "rh"; } | ||||
| 	      elsif ($os =~ /centos.*/) { $platform = "centos"; } | ||||
| 	      elsif ($os =~ /fedora.*/) { $platform = "fedora"; } | ||||
| 	      elsif ($os =~ /sles.*/) { $platform = "sles"; } | ||||
| 	      elsif ($os =~ /AIX.*/) { $platform = "AIX"; } | ||||
| 	  } | ||||
|  | ||||
|       $profile = $nodetype_v->{$node}->[0]->{'profile'}; | ||||
|       $os = $nodetype_v->{$node}->[0]->{'os'}; | ||||
|       $arch = $nodetype_v->{$node}->[0]->{'arch'}; | ||||
|  | ||||
|       my $platform = ""; | ||||
|       if ($os) { | ||||
|         if ($os =~ /rh.*/)    { $platform = "rh"; } | ||||
|         elsif ($os =~ /centos.*/) { $platform = "centos"; } | ||||
|         elsif ($os =~ /fedora.*/) { $platform = "fedora"; } | ||||
|         elsif ($os =~ /sles.*/) { $platform = "sles"; } | ||||
|         elsif ($os =~ /AIX.*/) { $platform = "AIX"; } | ||||
|       } | ||||
|  | ||||
|       my $base =  "/install/custom/$inst_type/$platform"; | ||||
|       if (-r "$base/$profile.$os.$arch.synclist") { | ||||
|         $node_syncfile{$node} = "$base/$profile.$os.$arch.synclist"; | ||||
|       } elsif (-r "$base/$profile.$arch.synclist") { | ||||
|         $node_syncfile{$node} = "$base/$profile.$arch.synclist"; | ||||
|       } elsif (-r "$base/$profile.$os.synclist") { | ||||
|         $node_syncfile{$node} = "$base/$profile.$os.synclist"; | ||||
|       } elsif (-r "$base/$profile.synclist") { | ||||
|         $node_syncfile{$node} = "$base/$profile.synclist"; | ||||
| 	  my $base =  "/install/custom/$inst_type/$platform"; | ||||
| 	  if (-r "$base/$profile.$os.$arch.synclist") { | ||||
| 	      $node_syncfile{$node} = "$base/$profile.$os.$arch.synclist"; | ||||
| 	  } elsif (-r "$base/$profile.$arch.synclist") { | ||||
| 	      $node_syncfile{$node} = "$base/$profile.$arch.synclist"; | ||||
| 	  } elsif (-r "$base/$profile.$os.synclist") { | ||||
| 	      $node_syncfile{$node} = "$base/$profile.$os.synclist"; | ||||
| 	  } elsif (-r "$base/$profile.synclist") { | ||||
| 	      $node_syncfile{$node} = "$base/$profile.synclist"; | ||||
| 	  } | ||||
|       } | ||||
|     } | ||||
|  | ||||
| @@ -478,7 +494,7 @@ sub  update_tables_with_templates | ||||
|     my $osname=$osver;;  #like sles, rh, centos, windows | ||||
|     my $ostype="Linux";  #like Linux, Windows | ||||
|     my $imagetype="linux"; | ||||
|     if ($osver =~ /^win/) { | ||||
|     if (($osver =~ /^win/) || ($osver =~ /^imagex/)) { | ||||
| 	$osname="windows"; | ||||
| 	$ostype="Windows"; | ||||
|         $imagetype="windows"; | ||||
| @@ -632,7 +648,7 @@ sub  update_tables_with_diskless_image | ||||
|     my $osname=$osver;;  #like sles, rh, centos, windows | ||||
|     my $ostype="Linux";  #like Linux, Windows | ||||
|     my $imagetype="linux"; | ||||
|     if ($osver =~ /^win/) { | ||||
|     if (($osver =~ /^win/) || ($osver =~ /^imagex/)) { | ||||
| 	$osname="windows"; | ||||
| 	$ostype="Windows"; | ||||
| 	$imagetype="windows"; | ||||
|   | ||||
| @@ -35,7 +35,7 @@ sub process_request { | ||||
|    @ARGV = @{$request->{arg}}; | ||||
|    my $argc = scalar @ARGV; | ||||
|    if ($argc == 0) { | ||||
|        $callback->({info=>["packimage -h \npackimage -v \npackimage [-p profile] [-a architecture] [-o OS] [-m method]\n"]}); | ||||
|        $callback->({info=>["packimage -h \npackimage -v \npackimage [-p profile] [-a architecture] [-o OS] [-m method]\npackimage imagename"]}); | ||||
|        return; | ||||
|    } | ||||
|    my $osver; | ||||
| @@ -62,7 +62,7 @@ sub process_request { | ||||
|       return; | ||||
|    } | ||||
|    if ($help) { | ||||
|       $callback->({info=>["packimage -h \npackimage -v \npackimage [-p profile] [-a architecture] [-o OS] [-m method]\n"]}); | ||||
|       $callback->({info=>["packimage -h \npackimage -v \npackimage [-p profile] [-a architecture] [-o OS] [-m method]\npackimage imagename"]}); | ||||
|       return; | ||||
|    } | ||||
|  | ||||
|   | ||||
| @@ -42,20 +42,28 @@ if [[ -z "$NFSSERVER" ]]; then | ||||
|     NFSSERVER=$MASTER | ||||
| fi | ||||
|  | ||||
| if [[ -z "$INSTALLDIR" ]]; then | ||||
|     INSTALLDIR="/install" | ||||
| fi | ||||
|  | ||||
| #check if /install is mounted on the server, we may need to add code to conver NFSSERVER to ip  | ||||
| mounted=0; | ||||
| result=`mount |grep /install |grep $NFSSERVER` | ||||
| if [ $? -eq 0 ]; then | ||||
|     if [[ -z "$INSTALLDIR" ]]; then | ||||
|         NFSSERVER="/install" | ||||
|     else | ||||
|         NFSSERVER=$INSTALLDIR | ||||
|     fi | ||||
|     NFSSERVER=$INSTALLDIR | ||||
|     mounted=1  | ||||
| fi | ||||
|  | ||||
| #echo NFSSERVER=$NFSSERVER | ||||
| if [[ -z "$OTHERPKGDIR" ]]; then | ||||
|     OTHERPKGDIR="$NFSSERVER/post/otherpkgs/$OSVER/$ARCH" | ||||
| fi | ||||
|  | ||||
| if [ $mounted -eq 0 ]; then | ||||
|     OTHERPKGDIR=${OTHERPKGDIR/#$INSTALLDIR/$NFSSERVER/} | ||||
| fi | ||||
|  | ||||
| echo NFSSERVER=$NFSSERVER | ||||
| echo OTHERPKGDIR=$OTHERPKGDIR | ||||
|  | ||||
| #check if the node has yum or zypper installed, it will try yum first, then zypper and last rpm | ||||
| hasyum=0   | ||||
| @@ -95,7 +103,7 @@ do | ||||
| 	 | ||||
|    fn=`basename $x` | ||||
|    path=`dirname $x` | ||||
|    whole_path=$NFSSERVER/post/otherpkgs/$OSVER/$ARCH/$path | ||||
|    whole_path=$OTHERPKGDIR/$path | ||||
|  | ||||
|    #find out if this path has already handled | ||||
|    try_repo=1 | ||||
| @@ -196,22 +204,23 @@ fi | ||||
| #Handle the rest with rpm | ||||
| if [ "$plain_pkgs" != "" ]; then  | ||||
|     if [ $mounted -eq 0 ]; then | ||||
|         mkdir -p /xcatpost/post/otherpkgs/$OSVER/$ARCH;  | ||||
|         rm -f -R /xcatpost/post/otherpkgs/* | ||||
| 	dir_no_ftproot=${OTHERPKGDIR#$INSTALLDIR/} | ||||
|         mkdir -p /xcatpost/$dir_no_ftproot  | ||||
|         rm -f -R /xcatpost/$dir_no_ftproot/* | ||||
|         mkdir -p /tmp/postage/ | ||||
|         rm -f -R /tmp/postage/* | ||||
|         cd /tmp/postage | ||||
|      | ||||
|         for x in `echo "$plain_pkgs" | tr " " "\n"` | ||||
|         do | ||||
| 	    wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -t 0 -T 60 ftp://$NFSSERVER/post/otherpkgs/$OSVER/$ARCH/$x 2> /tmp/wget.log   | ||||
| 	    wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -t 0 -T 60 ftp://$OTHERPKGDIR/$x 2> /tmp/wget.log   | ||||
|         done | ||||
|      | ||||
|         mv $NFSSERVER/post/otherpkgs/* /xcatpost/post/otherpkgs;  | ||||
|         mv $dir_no_ftproot/* /xcatpost/$dir_no_ftproot;  | ||||
|         rm -rf $NFSSERVER | ||||
|         cd /xcatpost/post/otherpkgs/$OSVER/$ARCH | ||||
|         cd /xcatpost/$dir_no_ftproot | ||||
|     else | ||||
|         cd $NFSSERVER/post/otherpkgs/$OSVER/$ARCH | ||||
|         cd $OTHERPKGDIR | ||||
|     fi | ||||
|  | ||||
|     echo "rpm -Uvh --replacepkgs $plain_pkgs"  | ||||
| @@ -223,7 +232,9 @@ if [ "$plain_pkgs" != "" ]; then | ||||
|     fi | ||||
|      | ||||
|     if [ $mounted -eq 0 ]; then | ||||
|         rm -f -R /xcatpost/post/otherpkgs/* | ||||
| 	cd /xcatpost | ||||
| 	dir_no_ftproot=${OTHERPKGDIR#$INSTALLDIR/} | ||||
|         rm -f -R $dir_no_ftproot | ||||
|     fi | ||||
| fi | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user