diff --git a/xCAT-server/lib/xcat/plugins/updatehwinv.pm b/xCAT-server/lib/xcat/plugins/updatehwinv.pm new file mode 100644 index 000000000..552634a9b --- /dev/null +++ b/xCAT-server/lib/xcat/plugins/updatehwinv.pm @@ -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; diff --git a/xCAT-server/sbin/xcatconfig b/xCAT-server/sbin/xcatconfig index be5e512ca..448dea05d 100755 --- a/xCAT-server/sbin/xcatconfig +++ b/xCAT-server/sbin/xcatconfig @@ -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) diff --git a/xCAT/postscripts/getinv b/xCAT/postscripts/getinv new file mode 100755 index 000000000..55c95fff4 --- /dev/null +++ b/xCAT/postscripts/getinv @@ -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 "" > $tmp_file +echo "updatehwinv" >> $tmp_file +echo "$CPUCOUNT" >> $tmp_file +echo "$CPUTYPE" >> $tmp_file +echo "$MEMORY" >> $tmp_file +echo "$DISKSIZE" >> $tmp_file +echo "" >> $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