Added Library Info

This commit is contained in:
Deon George 2011-06-24 11:27:21 +10:00
parent 529d70d2bb
commit 279eacd4ab
17 changed files with 520 additions and 65 deletions

View File

@ -0,0 +1,73 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides information on TSM attached Libraries.
*
* @package PTA
* @subpackage Libraries
* @category Controllers
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Controller_LIBRARY extends Controller_TemplateDefault {
/**
* Default Index for Controller
*/
public function action_index() {
$lo = ORM::factory('library');
$output = '';
$output .= sprintf(_('This server has <b>%s</b> libraries.'),$lo->count_all());
$output .= '<br/>';
$output .= '<br/>';
$select = array();
$select[NULL] = '';
foreach ($lo->find_all() as $library)
$select[$library->LIBRARY_NAME] = $library->LIBRARY_NAME;
$output .= Form::open('/library/detail',array('id'=>'library_detail'));
$output .= sprintf('%s: %s',_('Choose a storage pool to view'),Form::select('library_name',$select,NULL,array('id'=>'library_name')));
$output .= Form::submit('form_submit',_('Go'));
$output .= Form::close();
Block::add(array(
'title'=>_('TSM Libraries'),
'body'=>$output,
));
}
public function action_detail($library=NULL) {
if (is_null($library) AND (empty($_POST['library_name']) OR ! $library = $_POST['library_name'])) {
SystemMessage::add(array(
'title'=>_('LIBRARY_NAME is required'),
'type'=>'error',
'body'=>_('The library pool name is required.'),
));
Request::current()->redirect('library');
}
$lo = ORM::factory('library',$library);
if (! $lo->loaded()) {
SystemMessage::add(array(
'title'=>_('Unknown LIBRARY_NAME'),
'type'=>'error',
'body'=>sprintf(_('The library pool [%s] does not exist?.'),$library),
));
Request::current()->redirect('library');
}
$slots = DB::query(Database::SHOW,'SHOW SLOTS '.$lo)->execute();
Block::add(array(
'title'=>sprintf(_('Library Information for %s'),$lo->LIBRARY_NAME),
'body'=>View::factory('library/detail')
->set('lo',$lo)
->set('slots',$slots)
));
}
}
?>

View File

@ -31,6 +31,14 @@ class Controller_Tree extends Controller_lnApp_Tree {
'attr_href'=>URL::Site('domain'),
));
array_push($data,array(
'id'=>'library',
'name'=>'Library Info',
'state'=>'none',
'attr_id'=>'1',
'attr_href'=>URL::Site('library'),
));
array_push($data,array(
'id'=>'node',
'name'=>'Node Info',

View File

@ -0,0 +1,17 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's Database
*
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class Database extends Kohana_Database {
// Enable TSM SHOW commands
const SHOW = 5;
}
?>

View File

@ -0,0 +1,63 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* TSM database show result. See [Results](/database/results) for usage and examples.
*
* @package PTA
* @subpackage TSM
* @category Query/Show
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
abstract class Database_Result extends Kohana_Database_Result {
protected $_internal_row = 0;
protected $_rows;
// Required Abstract Classes
public function __destruct() {}
public function seek($offset) {
if ($this->offsetExists($offset)) {
// Set the current row to the offset
$this->_current_row = $this->_internal_row = $offset;
return TRUE;
} else {
return FALSE;
}
}
public function current() {
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
return FALSE;
// Return an stdClass
if ($this->_as_object === TRUE) {
return $this;
} elseif (is_string($this->_as_object)) {
// Return an object of given class name
$o = new $this->_as_object;
return $o->load_object($this->_rows[$this->_current_row]);
// Return an array of the row
} else {
return $this->_rows[$this->_current_row];
}
}
/**
* Get a row value from the query
*
* TSM returns all columns in upper case
*/
public function get($name, $default = NULL) {
$name = strtoupper($name);
return parent::get($name,$default);
}
}
?>

View File

@ -187,6 +187,8 @@ class Database_TSM extends Database {
return new Database_TSM_Result($result, $sql, $as_object, $params);
elseif ($type === Database::INSERT)
throw new Kohana_Exception('Database INSERTS are not supported');
elseif ($type === Database::SHOW)
return new Database_TSM_Show($result, $sql, $as_object, $params);
}
public function list_tables($like = NULL) {

View File

@ -11,12 +11,7 @@
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM_Result extends Database_Result {
protected $_internal_row = 0;
private $_rows;
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL)
{
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL) {
parent::__construct($result, $sql, $as_object, $params);
$start = FALSE;
@ -37,60 +32,5 @@ class Database_TSM_Result extends Database_Result {
$this->_total_rows = $this->_internal_row;
$this->_internal_row = 0;
}
public function __destruct()
{
return;
}
public function seek($offset)
{
if ($this->offsetExists($offset))
{
// Set the current row to the offset
$this->_current_row = $this->_internal_row = $offset;
return TRUE;
}
else
{
return FALSE;
}
}
public function current()
{
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
return FALSE;
if ($this->_as_object === TRUE)
{
// Return an stdClass
return $this;
}
elseif (is_string($this->_as_object))
{
// Return an object of given class name
$o = new $this->_as_object;
return $o->load_object($this->_rows[$this->_current_row]);
}
else
{
// Return an array of the row
return $this->_rows[$this->_current_row];
}
}
/**
* Get a row value from the query
*
* TSM returns all columns in upper case
*/
public function get($name, $default = NULL) {
$name = strtoupper($name);
return parent::get($name,$default);
}
} // End Database_TSM_Result
}
?>

View File

@ -0,0 +1,61 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* TSM database show result. See [Results](/database/results) for usage and examples.
*
* @package PTA
* @subpackage TSM
* @category Query/Show
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM_Show extends Database_Result {
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL) {
parent::__construct($result, $sql, $as_object, $params);
$sql = strtolower($sql);
$start = FALSE;
foreach ($result as $line) {
if (! trim($line))
continue;
if (preg_match('/^show slots /',$sql))
if (preg_match('/^Slot /',$line)) {
if ($start)
$this->_internal_row++;
$slot = array();
foreach ((preg_split('/,\s*/',$line,-1)) as $slotkey => $val)
if (preg_match('/^element number\s+/',$val))
$slot['element'] = preg_replace('/^element number\s+/','',$val);
elseif (preg_match('/^Slot\s+/',$val))
$slot['slot'] = preg_replace('/^Slot\s+/','',$val);
elseif (preg_match('/^status\s+/',$val))
$slot['status'] = preg_replace('/^status\s+/','',$val);
elseif (preg_match('/^barcode value </',$val))
$slot['barcodelabel'] = preg_replace('/^barcode value <(.*)>/',"$1",$val);
elseif (preg_match('/^barcode\s+/',$val))
$slot['barcode'] = preg_replace('/^barcode /','',$val);
$slot['library'] = preg_replace('/^show slots /','',$sql);
$this->_rows[$this->_internal_row] = new Slot($slot);
$start = TRUE;
} elseif (preg_match('/busy.$/',$line)) {
SystemMessage::add(array(
'title'=>_('Library is Busy'),
'type'=>'info',
'body'=>_('The library appears busy at the moment.'),
));
return;
}
}
$this->_total_rows = $this->_internal_row;
$this->_internal_row = 0;
}
}
?>

View File

@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class HTML extends lnApp_HTML {}
?>

View File

@ -0,0 +1,21 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class extends Kohana's HTML
*
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class lnApp_HTML extends Kohana_HTML {
public static function nbsp($string) {
if (strlen((string)$string))
return $string;
else
return '&nbsp;';
}
}
?>

View File

@ -0,0 +1,24 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package PTA
* @subpackage Library
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Model_LIBRARY extends ORMTSM {
protected $_table_name = 'LIBRARIES';
protected $_primary_key = 'LIBRARY_NAME';
protected $_sorting = array(
'LIBRARY_NAME'=>'ASC',
);
protected $_has_one = array(
);
protected $_has_many = array(
);
}
?>

View File

@ -0,0 +1,81 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package PTA
* @subpackage Library Volumes
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Model_LIBVOLUME extends ORMTSM {
protected $_table_name = 'LIBVOLUMES';
protected $_primary_key = 'VOLUME_NAME';
protected $_sorting = array(
'VOLUME_NAME'=>'ASC',
);
protected $_has_one = array(
'VOLUME'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
);
protected $_has_many = array(
'VOLHISTORY'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
);
public function usage() {
switch (strtolower($this->STATUS)) {
case 'scratch': return strtolower($this->STATUS);
case 'private':
switch (strtolower($this->LAST_USE)) {
case 'dbbackup':
case 'data':
return strtolower($this->LAST_USE);
default: return 'unknown';
}
}
}
public function volusage() {
switch ($this->usage()) {
case 'scratch': return _('Scratch');
case 'dbbackup': return $this->VOLHISTORY->lastuse()->TYPE;
case 'data': return $this->VOLUME->STGPOOL_NAME;
default: return _('Unknown');
}
}
public function status() {
switch ($this->usage()) {
case 'data': return sprintf('%s/%s',$this->VOLUME->display('STATUS'),$this->VOLUME->display('ACCESS'));
case 'dbbackup': return $this->VOLHISTORY->lastuse()->backupid();
default: return '';
}
}
public function access() {
switch ($this->usage()) {
case 'data':
case 'dbbackup':
return sprintf('%s/%s',$this->display('STATUS'),$this->display('OWNER'));
default: return '';
}
}
public function lastwrite() {
switch ($this->usage()) {
case 'data':
return $this->VOLUME->display('LAST_WRITE_DATE');
case 'dbbackup':
return $this->VOLHISTORY->lastuse()->display('DATE_TIME');
default: return '';
}
}
}
?>

View File

@ -0,0 +1,41 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package PTA
* @subpackage Volume History
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Model_VOLHISTORY extends ORMTSM {
protected $_table_name = 'VOLHISTORY';
protected $_primary_key = 'VOLUME_NAME';
protected $_sorting = array(
'DATE_TIME'=>'ASC',
);
protected $_has_one = array(
'VOLUME'=>array('foreign_key'=>'VOLUME_NAME','far_key'=>'VOLUME_NAME'),
);
protected $_has_many = array(
);
protected $_display_filters = array(
'DATE_TIME'=>array(
array('ORMTSM::date',array(':value','d-M-Y')),
),
);
public function lastuse() {
// We'll find the last record
foreach ($this->order_by('DATE_TIME DESC')->find_all() as $r)
return $r;
}
public function backupid() {
return sprintf('%s.%s.%s',$this->BACKUP_SERIES,$this->BACKUP_OPERATION,$this->VOLUME_SEQ);
}
}
?>

View File

@ -63,7 +63,7 @@ class ORM extends Kohana_ORM {
if (isset($this->_object_formated[$column]))
return $this->_object_formated[$column];
else
return strlen((string)$value) ? $value : '&nbsp;';
return HTML::nbsp($value);
}
}
?>

View File

@ -0,0 +1,38 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* PTA Show Slot Item.
*
* @package PTA
* @subpackage TSM
* @category Helpers
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Slot {
private $data = array();
private $objects = array(
'VOLUME'=>'barcodelabel',
'LIBVOLUME'=>'barcodelabel',
);
public function __construct(array $slot) {
$this->data = $slot;
}
public function __get($key) {
if (isset($this->data[$key]))
return $this->data[$key];
// @todo Volume names may not be unique if there is more than 1 library.
elseif (isset($this->objects[$key]))
return ORM::factory($key,$this->__get($this->objects[$key]));
else
throw new Kohana_Exception('Undefined property :class:::property',array(':class'=>get_class($this),':property'=>$key));
}
public function __toString() {
return $this->slot;
}
}
?>

View File

@ -47,20 +47,26 @@ return array
'DOMAINS' => 1200,
'EVENTS' => 1200,
'FILESPACES' => 1200,
'LIBRARIES' => 1200,
'LIBVOLUMES' => 1200,
'MGMTCLASSES' => 1200,
'NODES' => 1200,
'OCCUPANCY' => 1200,
'SCHEMA' => 604800,
'STGPOOLS' => 1200,
'SUMMARY' => 180,
'VOLHISTORY' => 1200,
'VOLUMES' => 1200,
'VOLUMEUSAGE' => 1200,
),
'cachepreload' => array(
'DEVCLASSES' => 1200,
'DOMAINS' => 1200,
'LIBVOLUMES' => 1200,
'LIBRARIES' => 1200,
'NODES' => 1200,
'STGPOOLS' => 1200,
'VOLHISTORY' => 1200,
'VOLUMES' => 1200,
),
'profiling' => TRUE,

View File

@ -0,0 +1,76 @@
<table width="100%">
<tr>
<td style="width: 50%; vertical-align: top;">
<table class="box-full">
<tr>
<td class="head" colspan="5">Information for this Library</td>
</tr>
<tr>
<td class="spacer">&nbsp;</td>
</tr>
<tr>
<td style="width: 40%;">Name</td>
<td style="width: 60%;" class="data"><?php echo $lo->display('LIBRARY_NAME'); ?></td>
<tr>
<td>Serial Number</td>
<td class="data"><?php echo $lo->display('LIBRARY_SERIAL'); ?></td>
</tr>
<tr>
<td>Type</td>
<td class="data"><?php echo $lo->display('LIBRARY_TYPE'); ?></td>
</tr>
<tr>
<td>Shared</td>
<td class="data"><?php echo $lo->display('SHARED'); ?></td>
</tr>
<tr>
<td>LAN Free</td>
<td class="data"><?php echo $lo->display('LANFREE'); ?></td>
</tr>
<tr>
<td>Auto Label</td>
<td class="data"><?php echo $lo->display('AUTOLABEL'); ?></td>
</tr>
</table>
</td>
<td style="width: 50%; vertical-align: top;">
&nbsp;
</td>
</tr>
<tr>
<td style="width: 100%; vertical-align: top;" colspan="2">
<table class="box-full">
<tr>
<td class="head" colspan="5">Volumes in this Library</td>
</tr>
<tr>
<td class="spacer">&nbsp;</td>
</tr>
<tr>
<td>Slot</td>
<td>Barcode</td>
<td>Usage</td>
<td>Status/Access</td>
<td>Library Access</td>
<td>Utilisation</td>
<td>Reclaim</td>
<td>Last Read</td>
<td>Last Write</td>
</tr>
<?php $i=0; foreach ($slots as $slot) { ?>
<tr class="<?php echo $i++%2 ? 'odd' : 'even'; ?>">
<td class="data"><acronym title="<?php printf('%s: %s',_('Element'),$slot->element); ?>"><?php echo $slot; ?></acronym></td>
<td class="data"><?php echo $slot->barcodelabel; ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->volusage(); ?></td>
<td class="data"><?php echo HTML::nbsp($slot->LIBVOLUME->status()); ?></td>
<td class="data"><?php echo HTML::nbsp($slot->LIBVOLUME->access()); ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->VOLUME->display('PCT_UTILIZED'); ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->VOLUME->display('PCT_RECLAIM'); ?></td>
<td class="data"><?php echo $slot->LIBVOLUME->VOLUME->display('LAST_READ_DATE'); ?></td>
<td class="data"><?php echo HTML::nbsp($slot->LIBVOLUME->lastwrite()); ?></td>
</tr>
<?php } ?>
</table>
</td>
</tr>
</table>

View File

@ -79,10 +79,10 @@
<?php $i=0;foreach ($node->EVENT->find_all() as $eo) { ?>
<tr class="<?php echo $i++%2 ? 'odd' : 'even'; ?>">
<td class="data"><?php echo $eo->display('SCHEDULED_START'); ?></td>
<td class="data"><?php echo $eo->ACTUAL_START ? $eo->display('ACTUAL_START') : '&nbsp;'; ?></td>
<td class="data"><?php echo HTML::nbsp($eo->display('ACTUAL_START')); ?></td>
<td class="data"><?php echo $eo->display('SCHEDULE_NAME'); ?></td>
<td class="data"><?php echo $eo->display('STATUS'); ?></td>
<td class="data"><?php echo $eo->COMPLETED ? $eo->display('COMPLETED') : '&nbsp;'; ?></td>
<td class="data"><?php echo HTML::nbsp($eo->display('COMPLETED')); ?></td>
<td class="data"><?php printf('%s %s',$eo->RESULT,$eo->display('REASON')); ?></td>
</tr>
<?php } ?>