From 8934efbdea6a011442ebee7b68a588e62a4caa5d Mon Sep 17 00:00:00 2001 From: Robert Ricci <ricci@cs.utah.edu> Date: Sat, 30 Oct 2004 00:07:09 +0000 Subject: [PATCH] Add two new functions, TBNodeType (to get the type and class of a node), and TBNodeTypeProcInfo (to get the processor and speed for a given node type.) --- db/libdb.pm.in | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/db/libdb.pm.in b/db/libdb.pm.in index 07efe4565b..5475817a3f 100644 --- a/db/libdb.pm.in +++ b/db/libdb.pm.in @@ -165,6 +165,8 @@ use vars qw(@ISA @EXPORT); TBLeaderMailList ExpGroup TBExptSetSwapUID TBExptSetThumbNail TBNodeAllocCheck TBPlabNodeUsername MarkPhysNodeDown + TBNodeType TBNodeTypeProcInfo + TBExptRemoveVirtualState TBExptBackupVirtualState TBExptRestoreVirtualState @@ -2960,6 +2962,51 @@ sub TBExptClearBackupState($$) if (-e $vstateDir); } +# +# Return a node's type and class, in a two-element array +# If the caller asked for a scalar, give them only the type +# Returns undef if the node doesn't exist +# +sub TBNodeType($) +{ + my ($node) = @_; + my $result = DBQueryFatal("SELECT n.type, class FROM nodes AS n " . + "LEFT JOIN node_types " . + " AS nt ON n.type = nt.type " . + "WHERE n.node_id='$node'"); + if ($result->num_rows() != 1) { + return undef; + } + + my ($type, $class) = $result->fetchrow(); + if (!$class) { + return undef; + } + + if (wantarray) { + return ($type, $class); + } else { + return $type; + } +} + +# +# Return a node's type CPU type and speed, in a two-element array +# Returns undef if the type can't be found +# +sub TBNodeTypeProcInfo($) +{ + my ($type) = @_; + my $result = DBQueryFatal("SELECT proc, speed FROM node_types " . + "WHERE type='$type'"); + if ($result->num_rows() != 1) { + return undef; + } + + my ($proc, $speed) = $result->fetchrow(); + return ($proc, $speed); +} + # # Remove the virtual state of an experiment from the DB, # returning the number of queries which didn't work. -- GitLab