# select b.node_id,b.bs_id,b.bsidx,a.attrvalue from blockstores as b,blockstore_attributes as a where b.bsidx=a.bsidx and b.role='element' and a.attrkey='serialnum' and a.attrvalue='$sn';
# to get HD info from node_id
# select b.node_id,b.bs_id,b.bsidx,a.attrvalue from blockstores as b,blockstore_attributes as a where b.bsidx=a.bsidx and b.role='element' and a.attrkey='serialnum' and b.node_id='pc510';
#
# to get bsidx from serial number
# db_bsidx=$(mysql -B -N -e "select b.bsidx from blockstores as b,blockstore_attributes as a where b.bsidx=a.bsidx and b.role='element' and a.attrkey='serialnum' and a.attrvalue='$sn';" tbdb)
# to get serial number from bsidx
# db_sn=$(mysql -B -N -e "select a.attrvalue from blockstores as b,blockstore_attributes as a where b.bsidx=a.bsidx and b.role='element' and a.attrkey='serialnum' and b.bsidx=$bsidx;" tbdb);
get_bsidx_from_sn(){
echo$(mysql -B-N-e"select b.bsidx from blockstores as b,blockstore_attributes as a where b.bsidx=a.bsidx and b.role='element' and a.attrkey='serialnum' and a.attrvalue='$1';" tbdb)
}
get_sn_from_bsidx(){
echo$(mysql -B-N-e"select a.attrvalue from blockstores as b,blockstore_attributes as a where b.bsidx=a.bsidx and b.role='element' and a.attrkey='serialnum' and b.bsidx=$1;" tbdb);
}
get_host_from_bsidx(){
echo$(mysql -B-N-e"select node_id from blockstores where bsidx=$1;" tbdb);
}
get_drive_from_bsidx(){
echo$(mysql -B-N-e"select bs_id from blockstores where bsidx=$1;" tbdb);
}
gentbsql_main(){
set-u
local sn="UNK"hdtype="UNK"secsize="UNK"sectors="UNK"wspeed="UNK"rspeed="UNK"
projdir=/proj/emulab-ops/nodecheck
cd$projdir
if(($# ));then
...
...
@@ -62,32 +87,118 @@ gentbsql_main() {
allnodes=$(ls-d pc* pg* dbox*)
fi
# unique BlockStore number based on first mac address
bsidx_base=$(mysql -B-N-e"select idx from emulab_indicies where name='next_bsidx';" tbdb)
printf"mysql -e \"delete from DISKUNIT where node_id='%s' and %s;\" tbdb\n""$host""$toadd"
if [ "$i" == "UNKNOWN" ] ; then
echo "# Missing Serial Number for disk${hdnum} on $host"
((++hdnum))
else
toadd="SN=\"$i\""
printf "mysql -e \"delete from blockstore_attributes where attrkey='%s';\" tbdb\n""$sn"
printf "mysql -e \"delete from blockstores where node_id='%s' and %s;\" tbdb\n""$host""$toadd"
fi
fi
done
listofnics=$(grep'NICs:' diff)
...
...
@@ -95,18 +206,22 @@ gentbsql_main() {
for i in $listofnics ; do
toadd=$(grep$i node)
if [ -n "$toadd" ] ; then
toadd=${toadd/NETUNIT}
printf"mysql -e \"insert into NETUNIT set node_id='%s' %s;\" tbdb\n""$host""$toadd"
toadd=${toadd/*ID=\"}
toadd=${toadd/\"}
uuid=$(uuidgen)
printf "#BYHAND mysql -e \"insert into interfaces set node_id='%s',mac='%s',card=X,port=X,interface_type='?',iface='ethX',role='?',uuid='$uuid';\" tbdb\n""$host""$toadd"
else
toadd="ID=\"$i\""
printf"mysql -e \"delete from NETUNIT where node_id='%s' and %s;\" tbdb\n""$host""$toadd"
printf "#BYHAND mysql -e \"delete from interfaces where node_id='%s' and %s;\" tbdb\n""$host""$toadd"
fi
done
else
echo "No record of node id \"$host\"."
fi
done
if [ $keep_bsidx_base -ne $bsidx_base ] ; then
printf "mysql -e \"update emulab_indicies set idx=%d where name='next_bsidx';\" tbdb\n""$bsidx_base"