11
11
-p Profile (compute,service)
12
12
-a Architecture (ppc64,x86_64,etc)
13
13
-m Method (default cpio)
14
+ -s Compute MD5 checksum of image
15
+ -u Use uftp for copying image
16
+ -d uftp delay in seconds (default is 30)
14
17
15
18
=cut
16
19
@@ -82,7 +85,7 @@ sub process_request {
82
85
@ARGV = @{$args };
83
86
}
84
87
if (scalar (@ARGV ) == 0) {
85
- $callback -> ({ info => [" Usage:\n packimage [-m| --method=cpio|tar] [-c| --compress=gzip|pigz|xz] <imagename>\n packimage [-h| --help]\n packimage [-v| --version]" ] });
88
+ $callback -> ({ info => [" Usage:\n packimage [-m| --method=cpio|tar] [-c| --compress=gzip|pigz|xz] <imagename>\n packimage [-h| --help]\n packimage [-v| --version]\n packimage [-s| --sum] \n packimage [-u| --uftp] \n packimage [-d| --delay=<uftp delay in seconds> " ] });
86
89
return 0;
87
90
}
88
91
@@ -97,10 +100,17 @@ sub process_request {
97
100
my $destdir ;
98
101
my $imagename ;
99
102
my $dotorrent ;
103
+ my $domd5sum ;
104
+ my $douftp ;
105
+ my $uftpdelay ;
106
+ my $default_uftpdelay =30;
107
+ my $addkcmdline ;
100
108
my $provmethod ;
101
109
my $help ;
102
110
my $version ;
103
111
my $lock ;
112
+ my $newaddkcmdline ;
113
+ my $linuximagetab ;
104
114
105
115
GetOptions(
106
116
" profile|p=s" => \$profile ,
@@ -109,6 +119,9 @@ sub process_request {
109
119
" method|m=s" => \$method ,
110
120
" compress|c=s" => \$compress ,
111
121
" tracker=s" => \$dotorrent ,
122
+ " sum|s" => \$domd5sum ,
123
+ " uftp|u" => \$douftp ,
124
+ " delay|d=s" => \$uftpdelay ,
112
125
" help|h" => \$help ,
113
126
" version|v" => \$version
114
127
);
@@ -122,7 +135,7 @@ sub process_request {
122
135
return 0;
123
136
}
124
137
if ($help ) {
125
- $callback -> ({ info => [" Usage:\n packimage [-m| --method=cpio|tar] [-c| --compress=gzip|pigz|xz] <imagename>\n packimage [-h| --help]\n packimage [-v| --version]" ] });
138
+ $callback -> ({ info => [" Usage:\n packimage [-m| --method=cpio|tar] [-c| --compress=gzip|pigz|xz] <imagename>\n packimage [-h| --help]\n packimage [-v| --version]\n packimage [-s| --sum] \n packimage [-u| --uftp] \n packimage [-d| --delay=<uftp delay in seconds> " ] });
126
139
return 0;
127
140
}
128
141
@@ -146,7 +159,7 @@ sub process_request {
146
159
$callback -> ({ error => [" The osimage table cannot be opened." ], errorcode => [1] });
147
160
return 1;
148
161
}
149
- my $linuximagetab = xCAT::Table-> new(' linuximage' , -create => 1);
162
+ $linuximagetab = xCAT::Table-> new(' linuximage' , -create => 1);
150
163
unless ($linuximagetab ) {
151
164
$callback -> ({ error => [" The linuximage table cannot be opened." ], errorcode => [1] });
152
165
return 1;
@@ -156,7 +169,7 @@ sub process_request {
156
169
$callback -> ({ error => [" Cannot find image \' $imagename \' from the osimage table." ], errorcode => [1] });
157
170
return 1;
158
171
}
159
- (my $ref1 ) = $linuximagetab -> getAttribs({ imagename => $imagename }, ' exlist' , ' rootimgdir' );
172
+ (my $ref1 ) = $linuximagetab -> getAttribs({ imagename => $imagename }, ' exlist' , ' rootimgdir' , ' addkcmdline ' );
160
173
unless ($ref1 ) {
161
174
$callback -> ({ error => [" Cannot find $imagename from the linuximage table." ], errorcode => [1] });
162
175
return 1;
@@ -178,8 +191,9 @@ sub process_request {
178
191
return 1;
179
192
}
180
193
181
- $exlistloc = $ref1 -> {' exlist' };
182
- $destdir = $ref1 -> {' rootimgdir' };
194
+ $exlistloc = $ref1 -> {' exlist' };
195
+ $destdir = $ref1 -> {' rootimgdir' };
196
+ $addkcmdline = $ref1 -> {' addkcmdline' };
183
197
} else {
184
198
$provmethod = " netboot" ;
185
199
unless ($osver ) {
@@ -537,6 +551,62 @@ sub process_request {
537
551
system (" rm -rf $xcat_packimg_tmpfile " );
538
552
return 1;
539
553
}
554
+ $newaddkcmdline = $addkcmdline ;
555
+ if ($domd5sum ) { # if true, pass md5sum of root image as a boot parameter
556
+ my $md5 = Digest::MD5-> new;
557
+ open (my $iorootimg , ' <' , " $destdir /rootimg.$suffix " );
558
+ binmode ($iorootimg );
559
+ $md5 -> addfile($iorootimg );
560
+ my $md5sum = $md5 -> hexdigest;
561
+ if ($addkcmdline =~ m / md5sum/ ) {
562
+ $newaddkcmdline =~ s / md5sum=\w {32}/ md5sum=$md5sum / ;
563
+ } else {
564
+ $newaddkcmdline = $newaddkcmdline . " md5sum=" . $md5sum ;
565
+ }
566
+ $linuximagetab -> setAttribs({imagename => $imagename }, {addkcmdline => $newaddkcmdline });
567
+ } else { # -s was not given, so remove any pre-existing md5sum since it will be invalid
568
+ if ($newaddkcmdline =~ m / md5sum/ ) {
569
+ $newaddkcmdline =~ s / md5sum=\w {32}// ;
570
+ $newaddkcmdline =~ s / ^md5sum=\w {32} // ;
571
+ $newaddkcmdline =~ s / ^md5sum=\w {32}// ;
572
+ $linuximagetab -> setAttribs({imagename => $imagename }, {addkcmdline => $newaddkcmdline });
573
+ }
574
+ }
575
+
576
+ if ($douftp ) { # if true, pass uftp=true as a boot parameter
577
+ if (!($newaddkcmdline =~ m / uftp=true/ )) {
578
+ $newaddkcmdline = $newaddkcmdline . " uftp=true" ;
579
+ $linuximagetab -> setAttribs({imagename => $imagename }, {addkcmdline => $newaddkcmdline });
580
+ }
581
+ } else { # -u was not given, so remove any pre-existing uftp boot parameters
582
+ if ($newaddkcmdline =~ m / uftp=true/ ) {
583
+ $newaddkcmdline =~ s / uftp=true// ;
584
+ $newaddkcmdline =~ s / ^uftp=true // ;
585
+ $newaddkcmdline =~ s / ^uftp=true// ;
586
+ }
587
+ if ($newaddkcmdline =~ m / uftpdelay=\d */ ) {
588
+ $newaddkcmdline =~ s / uftpdelay=\d *// ;
589
+ $newaddkcmdline =~ s / ^uftpdelay=\d * // ;
590
+ $newaddkcmdline =~ s / ^uftpdelay=\d *// ;
591
+ }
592
+ $linuximagetab -> setAttribs({imagename => $imagename }, {addkcmdline => $newaddkcmdline });
593
+ }
594
+
595
+ if (($uftpdelay ) && ($douftp )) { # if true, pass uftpdelay as a boot parameter
596
+ if ($newaddkcmdline =~ m / uftpdelay/ ) { # if there is a pre-existing uftpdelay, replace
597
+ $newaddkcmdline =~ s / uftpdelay=\d */ uftpdelay=$uftpdelay / ;
598
+ } else { # otherwise, add supplied value
599
+ $newaddkcmdline = $newaddkcmdline . " uftpdelay=$uftpdelay " ;
600
+ }
601
+ $linuximagetab -> setAttribs({imagename => $imagename }, {addkcmdline => $newaddkcmdline });
602
+ } elsif ($douftp ) { # no uftpdelay was given, so use the default of $default_uftpdelay
603
+ if ($newaddkcmdline =~ m / uftpdelay/ ) { # if there is a pre-existing uftpdelay, replace
604
+ $newaddkcmdline =~ s / uftpdelay=\d */ uftpdelay=$default_uftpdelay / ;
605
+ } else { # otherwise, add default value
606
+ $newaddkcmdline = $newaddkcmdline . " uftpdelay=$default_uftpdelay " ;
607
+ }
608
+ $linuximagetab -> setAttribs({imagename => $imagename }, {addkcmdline => $newaddkcmdline });
609
+ }
540
610
541
611
if ($method =~ / cpio/ ) {
542
612
chmod 0644, " $destdir /rootimg.$suffix " ;
0 commit comments