From 2f17a10f924116be7565624dd0eb187e8277ac5f Mon Sep 17 00:00:00 2001 From: linggao Date: Thu, 19 Dec 2013 08:25:41 -0500 Subject: [PATCH] added capacity table to store cpu, memory and disk sizes for nodes --- perl-xCAT/xCAT/Schema.pm | 35 +++++++++++++++++++- xCAT-genesis-scripts/bin/dodiscovery | 13 +++++++- xCAT-server/lib/xcat/plugins/nodediscover.pm | 21 ++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/perl-xCAT/xCAT/Schema.pm b/perl-xCAT/xCAT/Schema.pm index 9f530b20b..61ae40ebf 100755 --- a/perl-xCAT/xCAT/Schema.pm +++ b/perl-xCAT/xCAT/Schema.pm @@ -1500,6 +1500,20 @@ mic => { disable => "Do not use. tabprune will not work if set to yes or 1", }, }, +capacity => { + cols => [qw(node cputype cpucount memory disksize comments disable)], + keys => [qw(node)], + table_desc => 'The basic node capacity.', + descriptions => { + node => 'The node name or group name.', + cputype => 'The cpu model name for the node.', + cpucount => 'The number of cpus for the node.', + memory => 'The size of the memory for the node.', + disksize => 'The size of the disks for the node.', + comments => 'Any user-provided notes.', + disable => "Set to 'yes' or '1' to comment out this row.", + }, +}, ); # end of tabspec definition @@ -2478,7 +2492,26 @@ my @nodeattrs = ( tabentry => 'mic.powermgt', access_tabentry => 'mic.node=attr:node', }, - +##################### +## capacity table # +##################### + {attr_name => 'cputype', + tabentry => 'capacity.cputype', + access_tabentry => 'capacity.node=attr:node', + }, + {attr_name => 'cpucount', + tabentry => 'capacity.cpucount', + access_tabentry => 'capacity.node=attr:node', + }, + {attr_name => 'memory', + tabentry => 'capacity.memory', + access_tabentry => 'capacity.node=attr:node', + }, + {attr_name => 'disksize', + tabentry => 'capacity.disksize', + access_tabentry => 'capacity.node=attr:node', + }, + ); # end of @nodeattrs that applies to both nodes and groups diff --git a/xCAT-genesis-scripts/bin/dodiscovery b/xCAT-genesis-scripts/bin/dodiscovery index 7085bacdb..e4c8dd6c0 100755 --- a/xCAT-genesis-scripts/bin/dodiscovery +++ b/xCAT-genesis-scripts/bin/dodiscovery @@ -75,7 +75,17 @@ elif [ -r /proc/device-tree/model ]; then #POWER MTM=`cat /proc/device-tree/model |awk -F, '{print $2}'` fi CPUCOUNT=`cat /proc/cpuinfo |grep "model name"|wc -l` -MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{print $2}'` + +# The MEMORY will look like this: 32868920 +MEMORY=`cat /proc/meminfo |grep MemTotal|awk '{printf "%.0fMB\n", $2/1024}'` +# The MEMORY will look like this: 32GiB +#MEMORY=`lshw -C memory -short |grep "System Memory"|awk -F' ' '{print $3}'` + +# The DISKSIZE will look like this: /dev/sda:250GB,/dev/sdb:250GB +#DISKSIZE=`lshw -C disk -short |grep disk |awk -F' ' '{print $2":"$4}'|sed 'N;s/\n/,/'` +# The DISKSIZE will look like this: sdb:250GB,sda:250GB +DISKSIZE=`cat /proc/partitions |grep -e "sd.\>" |awk -F' ' '{printf "%s:%.0fGB\n", $4, $3*0.000001024}' |sed 'N;s/\n/,/'` + UUID=`sed -e 's/\(..\)\(..\)\(..\)\(..\)-\(..\)\(..\)-\(..\)\(..\)/\4\3\2\1-\6\5-\8\7/' /sys/devices/virtual/dmi/id/product_uuid` grep "model name" /proc/cpuinfo | while read line; do #to avoid pulling in tail, we do a goofy thing echo $line > /tmp/cpumod @@ -90,6 +100,7 @@ fi echo "$CPUCOUNT" >> /tmp/discopacket echo "$CPUTYPE" >> /tmp/discopacket echo "$MEMORY" >> /tmp/discopacket +echo "$DISKSIZE" >> /tmp/discopacket echo "$UUID" >> /tmp/discopacket if [ "$MTM" != "unknown" ]; then echo "$MTM" >> /tmp/discopacket diff --git a/xCAT-server/lib/xcat/plugins/nodediscover.pm b/xCAT-server/lib/xcat/plugins/nodediscover.pm index 34724164b..61268fc9b 100644 --- a/xCAT-server/lib/xcat/plugins/nodediscover.pm +++ b/xCAT-server/lib/xcat/plugins/nodediscover.pm @@ -153,6 +153,27 @@ sub process_request { $vpdtab->setNodeAttribs($node,{serial=>$request->{serial}->[0]}); } } + + # save basic capacities in the capacity table + if (defined($request->{cpucount}) or defined($request->{cputype}) or defined($request->{memory}) or defined($request->{disksize})) { + my $basicdata; + my $cap_tab = xCAT::Table->new("capacity",-create=>1); + if ($request->{memory}->[0]) { + $basicdata->{memory} = $request->{memory}->[0]; + } + if ($request->{disksize}->[0]) { + $basicdata->{disksize} = $request->{disksize}->[0]; + } + if ($request->{cpucount}->[0]) { + $basicdata->{cpucount} = $request->{cpucount}->[0]; + } + if ($request->{cputype}->[0]) { + $basicdata->{cputype} = $request->{cputype}->[0]; + } + $cap_tab->setNodeAttribs($node, $basicdata); + } + + my $nrtab; my @discoverynics; my @forcenics; #list of 'eth' style interface names to require to come up on post-discovery client dhcp restart