# listPoolSnap.pl # # by Vijayababu Dandi # Version 1.0 # Jan 17, 2008 ############################################################################################## # Perl must be installed and running on the Linux server where this utility will be used. # NSS must be installed to get the VFS support. # (The SDK for this API set can be downloaded from http://developer.novell.com/wiki/index.php/# Virtual_File_Services_for_NetWare.) ############################################################################################## # # This is used to list the snapshots taken on particular pool. # ############################################################################################## sub lowerToUpper($) { my $string = $_[0]; $string =~ tr/[a-z]/[A-Z]/; return $string; } sub SetDataStream($*) { my $fh = $_[0]; my $datastream = $_[1]; my $command; my $result; my $error; $command = ""; seek $fh, 0, 0; if (!syswrite($fh, $command, length($command))) { $result .= "Unable to send datastream command to NDS management. "; seek $fh, 0, 0; if (sysread($fh,$error, 1000)) { $result .= $error; } $result .= "\n"; } return $result; } sub WriteCommand($*) { my $fh = $_[0]; my $result; my $reply; my $error; my $command = $_[1]; seek $fh, 0, 0; if (!syswrite($fh, $command, length($command))) { $result .= "Unable to send command to virtual file. "; seek $fh, 0, 0; if (sysread($fh, $error, 1000)) { $result .= $error; } $result .= "\n"; } else { seek $fh, 0, 0; my $readLen = 999; while ($readLen) { $readLen = sysread($fh, $reply, 1000); $result .= $reply; } } return $result; } sub ListSnapshots($*) { my $command = $_[0]; my $showdetails = $_[1]; my $result; my @poolss = (); my $ret; my $nssResult; $command = "$command"; if (!($ret = SetDataStream(FILE, "command"))) { $result .= $ret; $nssResult = WriteCommand(FILE,"$command"); } ($result,@poolss) = parseResult ($nssResult,$showdetails); return ($result,@poolss); } sub ListPools { my $result; my $ret; if (!($ret = SetDataStream(FILE, "command"))) { $result .= $ret; my $nssResult = WriteCommand(FILE, "". ""); $result .= ParseListPools($nssResult); } return $result; } sub ParseListPools($) { my $xml = $_[0]; my $result; my @xml; my $ret; my $poolName; my $poolState; my $totalBytes; my $freeBytes; my $enabledAttributes; my $size; my $usedSize; my $freeableSize; my $description; my $reporter; my $type; @xml = $xml =~ /(.*?)<\/poolSimpleInfo>/gs; $ret =''; foreach $result (@xml) { if ($result =~ //s) { if ($result =~ /(.*?)<\/description>/gs) { $description = $1; } if ($result =~ /(.*?)<\/reporter>/gs) { $reporter = $1; } if ($1 != 0) { return "-----------------------------------------------------------\n". "Error No : $1\n". "Description : $description\n". "Reporter : $reporter\n"; } } $poolName = ""; $poolState = ""; if ($result =~ /(.*?)<\/poolName>/s) { $poolName = $1; } $ret .= "$poolName\n"; } return $ret; } sub parseResult($*) { my $xml = $_[0]; my $showdetails = $_[1]; my $result; my @xml; my $ret; my $state; my $size; my $mount; my $name = ""; my $poolName = ""; my @poolss = (); my $numpools = -1; @xml = $xml =~ /(.*?)<\/poolSnapshotInfo>/gs; foreach $result (@xml) { if ($result =~ //s) { if ($1 != 0) { return "Error $1 getting Snapshot Info\n"; } } if ($result =~ /(.*?)<\/snapName>/s) { $name = $1; $poolss[++$numpools] = $name; } if ($result =~ /(.*?)<\/allocatedSize>/s) { $size = $1; $size = $size/(2*1024); } if ($result =~ /(.*?)<\/mountPoint>/s) { $mount = $1; } if ($result =~ /(.*?)<\/state>/s) { $state = $1; } if ($result =~ /(.*?)<\/poolName>/s) { $poolName = $1; } if (($showdetails =~ /^yes$/i) || ($showdetails =~ /^y$/i)) { $ret .= "Snapshot Name : $name\n". "Pool Name : $poolName\n". "Storage size(in MB) : $size\n". "State : $state\n". "Mount point : $mount\n". "------------------------------------------------------------\n"; } else { $ret .= "Snapshot Name : $name\n". "-----------------------------------------------------\n"; } } return ($ret,@poolss); } sub errorHandle($$) { my $xml = $_[0]; my $snapName = $_[1]; my $result; my @xml; my $ret; my $state; my $size; my $mount; my $name = ""; my $description; my $reporter = ""; if (@xml = $xml =~ /(.*?)<\/poolSnapshotInfo>/gs) { foreach $result (@xml) { if ($result =~ /(.*?)<\/description>/gs) { $description = $1; } if ($result =~ /(.*?)<\/reporter>/gs) { $reporter = $1; } if ($result =~ //s) { if ($1 != 0) { return "----------------------------------------\n". "Error No :$1 \n". "Description :$description \n". "Reporter :$reporter \n". "----------------------------------------\n"; } else { return 0; } } } } } sub getEvmsPools() { my $nssResult; my $result; $command=""; if (!($ret = SetDataStream(FILE, "command"))) { $result .= $ret; $nssResult = WriteCommand(FILE,"$command"); } $result .= parseEvmsPools($nssResult); return $result; } sub parseEvmsPools($) { my $xml = $_[0]; my $result; my @xml; my $ret; my $state; my $size; my $mount; my $name = ""; @xml = $xml =~ /(.*?)<\/poolSimpleInfo>/gs; foreach $result (@xml) { if ($result =~ //s) { if ($1 != 0) { return "Error $1 getting Snapshot Info\n"; } } if ($result =~ /(.*?)<\/poolName>/s) { $name = $1; } $ret .="$name\n"; } return $ret; } sub listPoolSS { my @poolss = (); my $result; my $poolTag; my $poolName; print "Pools Existing:\n"; print ListPools; print "Enter the Pool Name: "; chomp($poolName = ); $poolName = lowerToUpper($poolName); $poolTag = "$poolName"; my $command = "$poolTag"; my $option = ""; ($result,@poolss) = ListSnapshots($command,$option); if ( $#poolss+1 == 0 ) { print "--------------------------------------------------\n". "$poolName does not contain snapshot\n". "--------------------------------------------------\n"; return; } print "----------------------------------------------\n". "Snapshots taken on $poolName\n". "----------------------------------------------\n"; foreach my $snapshot (@poolss) { print "$snapshot\n"; } print "----------------------------------------------\n"; } my $command = $_[1]; open(FILE,"+>", "/_admin/Manage_NSS/manage.cmd") or die "Error opening NSS management file ($!) on server"; MAIN :while (1) { my $action; do { print "1.To list the snapshots taken on particular pool\n". "2.Exit\n". "Select Action: "; chomp($action = ); }while ($action != 0 && ($action < 1 || $action > 2)); if ($action == 1) { listPoolSS; } else { exit(0); } } close(FILE);