mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-08-11 14:00:17 +00:00
update hwinv table by updatenode -P geinv
This commit is contained in:
68
xCAT-server/lib/xcat/plugins/updatehwinv.pm
Normal file
68
xCAT-server/lib/xcat/plugins/updatehwinv.pm
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/perl
|
||||
# IBM(c) 2018 EPL license http://www.eclipse.org/legal/epl-v10.html
|
||||
|
||||
package xCAT_plugin::updatehwinv;
|
||||
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use strict;
|
||||
use warnings "all";
|
||||
use xCAT::Table;
|
||||
use xCAT::Utils;
|
||||
|
||||
#-------------------------------------------------------
|
||||
|
||||
=head3 handled_commands
|
||||
|
||||
Return list of commands handled by this plugin
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------
|
||||
sub handled_commands {
|
||||
return {
|
||||
updatehwinv => 'updatehwinv',
|
||||
};
|
||||
}
|
||||
|
||||
sub process_request {
|
||||
my $req = shift;
|
||||
my $callback = shift;
|
||||
|
||||
if ($req->{command}->[0] eq "updatehwinv") {
|
||||
update_hw_inv($req);
|
||||
}
|
||||
}
|
||||
|
||||
sub update_hw_inv {
|
||||
my $request = shift;
|
||||
my $node = $request->{'_xcat_clienthost'}->[0];
|
||||
|
||||
my @nodefs;
|
||||
my $basicdata;
|
||||
|
||||
my @hwinv_info = ("cpucount", "cputype", "memory", "disksize");
|
||||
|
||||
foreach my $hwinv_type (@hwinv_info) {
|
||||
if (defined($request->{$hwinv_type}) and $request->{$hwinv_type}->[0]) {
|
||||
$basicdata->{$hwinv_type} = $request->{$hwinv_type}->[0];
|
||||
} else {
|
||||
push @nodefs, $hwinv_type;
|
||||
}
|
||||
}
|
||||
|
||||
if ($basicdata) {
|
||||
my $hwinv_tab = xCAT::Table->new("hwinv", -create => 1);
|
||||
xCAT::MsgUtils->message("S", "xcat.hwinv: Update hwinv for $node");
|
||||
$hwinv_tab->setNodeAttribs($node, $basicdata);
|
||||
}
|
||||
if (@nodefs) {
|
||||
my $nodef = join(",", @nodefs);
|
||||
xCAT::MsgUtils->message("E", "xcat.hwinv: No valid hwinv info $nodef received from $node");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
@@ -1360,6 +1360,8 @@ sub initDB
|
||||
"$::XCATROOT/sbin/chtab priority=4.8 policy.commands=litetree policy.rule=allow;";
|
||||
$chtabcmds .=
|
||||
"$::XCATROOT/sbin/chtab priority=4.9 policy.commands=getadapter policy.rule=allow;";
|
||||
$chtabcmds .=
|
||||
"$::XCATROOT/sbin/chtab priority=4.10 policy.commands=updatehwinv policy.rule=allow;";
|
||||
}
|
||||
my $outref = xCAT::Utils->runcmd("$chtabcmds", 0);
|
||||
if ($::RUNCMD_RC != 0)
|
||||
|
46
xCAT/postscripts/getinv
Executable file
46
xCAT/postscripts/getinv
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ -z "$XCATDEST" ]; then
|
||||
XCATDEST=$1
|
||||
fi
|
||||
|
||||
if [ -z "$XCATDEST" ]; then
|
||||
XCATDEST=$MASTER_IP:$XCATDPORT
|
||||
fi
|
||||
|
||||
tmp_file=/tmp/invinfo.xml
|
||||
|
||||
CPUCOUNT=`lscpu | grep "^CPU(s)" | awk -F':' '{print $2}' | sed 's/^[ \t]*//g'`
|
||||
CPUTYPE=`lscpu | grep "Model name" | awk -F':' '{print $2}' | sed 's/^[ \t]*//g'`
|
||||
MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{printf "%.0fMB\n", $2/1024}'`
|
||||
DISKSIZE="$(grep -v name /proc/partitions |sort -g -k 1,2 |awk 'BEGIN{sep=""} /[^0-9]$/{printf("%s%s:%.0fGB", sep, $4, $3/1024^2) ; sep=","}')"
|
||||
|
||||
echo "<xcatrequest>" > $tmp_file
|
||||
echo "<command>updatehwinv</command>" >> $tmp_file
|
||||
echo "<cpucount>$CPUCOUNT</cpucount>" >> $tmp_file
|
||||
echo "<cputype>$CPUTYPE</cputype>" >> $tmp_file
|
||||
echo "<memory>$MEMORY</memory>" >> $tmp_file
|
||||
echo "<disksize>$DISKSIZE</disksize>" >> $tmp_file
|
||||
echo "</xcatrequest>" >> $tmp_file
|
||||
|
||||
xml_file=/tmp/hwinv.xml
|
||||
rm -f $xml_file
|
||||
|
||||
while [ ! -f $xml_file ] || grep error $xml_file; do
|
||||
if [ -f $xml_file ]; then
|
||||
timer=60
|
||||
while [ $timer -gt 0 ]; do
|
||||
sleep 1
|
||||
echo -en "Retrying in $timer seconds \r"
|
||||
timer=$(($timer-1));
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -f /etc/xcat/cert.pem -a -f /etc/xcat/certkey.pem ]; then
|
||||
cat $tmp_file | openssl s_client -key /etc/xcat/certkey.pem -cert /etc/xcat/cert.pem -connect $XCATDEST -quiet 2> /dev/null > $xml_file
|
||||
else
|
||||
cat $tmp_file | openssl s_client -connect $XCATDEST -quiet 2> /dev/null > $xml_file
|
||||
fi
|
||||
done
|
||||
|
||||
rm $tmp_file
|
Reference in New Issue
Block a user