2011-06-24 01:27:21 +00:00
|
|
|
<?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
|
|
|
|
*/
|
2012-11-26 05:57:18 +00:00
|
|
|
class Model_LIBRARY extends TSM_ORM {
|
2011-06-24 01:27:21 +00:00
|
|
|
protected $_table_name = 'LIBRARIES';
|
|
|
|
protected $_primary_key = 'LIBRARY_NAME';
|
|
|
|
protected $_sorting = array(
|
|
|
|
'LIBRARY_NAME'=>'ASC',
|
|
|
|
);
|
|
|
|
|
2011-06-26 12:20:12 +00:00
|
|
|
// Store our show slots data
|
|
|
|
private $slots;
|
|
|
|
private $storagepools = array();
|
|
|
|
|
2011-06-24 01:27:21 +00:00
|
|
|
protected $_has_many = array(
|
2011-06-24 23:46:26 +00:00
|
|
|
'DRIVE'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'),
|
2011-06-26 12:20:12 +00:00
|
|
|
'PATH'=>array('foreign_key'=>'DESTINATION_NAME','far_key'=>'LIBRARY_NAME'),
|
|
|
|
'DEVCLASSES'=>array('foreign_key'=>'LIBRARY_NAME','far_key'=>'LIBRARY_NAME'),
|
2011-06-24 01:27:21 +00:00
|
|
|
);
|
2011-06-26 12:20:12 +00:00
|
|
|
|
2012-12-04 00:52:10 +00:00
|
|
|
#zz
|
2011-06-26 12:20:12 +00:00
|
|
|
public function slots() {
|
2012-11-27 01:26:56 +00:00
|
|
|
return $this->slots ? $this->slots : $this->slots = DB::query(Database::SHOW,'SHOW SLOTS '.$this)->execute(Kohana::$config->load('config')->client_type);
|
2011-06-26 12:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of scratch volumes
|
2011-06-27 04:37:11 +00:00
|
|
|
public function scratchvol() {
|
2011-06-26 12:20:12 +00:00
|
|
|
$return = array();
|
|
|
|
|
|
|
|
foreach ($this->slots() as $slot)
|
|
|
|
if ($slot->status == 'Allocated' AND $slot->LIBVOLUME->usage() == 'scratch')
|
|
|
|
array_push($return,$slot->LIBVOLUME->VOLUME);
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of volumes that are readonly
|
2011-06-27 04:37:11 +00:00
|
|
|
public function readonlyvol() {
|
2011-06-26 12:20:12 +00:00
|
|
|
$return = array();
|
|
|
|
|
|
|
|
foreach ($this->slots() as $slot)
|
|
|
|
if ($slot->LIBVOLUME->VOLUME->ACCESS == 'READONLY')
|
|
|
|
array_push($return,$slot->LIBVOLUME->VOLUME);
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the number of slots that are empty.
|
|
|
|
public function numemptyslot() {
|
2012-11-29 22:58:15 +00:00
|
|
|
$return = array();
|
|
|
|
|
|
|
|
foreach ($this->slots() as $slot)
|
|
|
|
if ($slot->status == 'Empty')
|
|
|
|
array_push($return,$slot->LIBVOLUME->VOLUME);
|
|
|
|
|
|
|
|
return count($return);
|
|
|
|
//return $this->slots->Slots-$this->slots->Changers-count($this->slots);
|
2011-06-26 12:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the slots that are used, but not checked in.
|
2011-06-27 04:37:11 +00:00
|
|
|
public function notcheckedinvol() {
|
2011-06-26 12:20:12 +00:00
|
|
|
$return = array();
|
|
|
|
|
|
|
|
foreach ($this->slots() as $slot)
|
|
|
|
if ($slot->status == 'Full')
|
|
|
|
array_push($return,$slot);
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the device classes that use this library.
|
|
|
|
public function devclasses() {
|
|
|
|
return $this->DEVCLASSES->where('LIBRARY_NAME','=',$this)->find_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of storage pools that potentially use this library.
|
|
|
|
public function storagepools() {
|
|
|
|
if (! $this->storagepools)
|
|
|
|
foreach ($this->devclasses() as $dco)
|
|
|
|
foreach ($dco->STGPOOL->find_all() as $spo)
|
|
|
|
array_push($this->storagepools,$spo);
|
|
|
|
|
|
|
|
return $this->storagepools;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function storagepoolstype($type) {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($this->storagepools() as $spo)
|
|
|
|
if ($spo->POOLTYPE == $type)
|
|
|
|
array_push($result,$spo);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2011-06-27 04:37:11 +00:00
|
|
|
/**
|
|
|
|
* Return a list of volumes
|
|
|
|
*
|
|
|
|
* @param $ptype is pool type (PRIMARY,ACTIVE,COPY)
|
|
|
|
* @param $inout IN|OUT of the library
|
|
|
|
* @param $status volume status FULL|FILLING|PENDING|EMPTY
|
|
|
|
* @note This is an intensive method that needs caching.
|
|
|
|
*/
|
|
|
|
public function volstype($ptype,$inout,$status) {
|
2011-06-26 12:20:12 +00:00
|
|
|
static $CACHE = array();
|
2011-06-27 04:37:11 +00:00
|
|
|
$ainout = array('IN','OUT');
|
2011-06-26 12:20:12 +00:00
|
|
|
|
2011-06-27 04:37:11 +00:00
|
|
|
if (! isset($CACHE[__METHOD__][$ptype]))
|
|
|
|
foreach ($this->storagepoolstype($ptype) as $spo)
|
2011-06-26 12:20:12 +00:00
|
|
|
foreach ($ainout as $cinout)
|
2012-11-26 05:57:18 +00:00
|
|
|
foreach (Kohana::$config->load('config')->tsmvolstatus as $cstatus) {
|
2011-06-26 12:20:12 +00:00
|
|
|
if (! isset($CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus]))
|
|
|
|
$CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus] = array();
|
|
|
|
|
|
|
|
$CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus] =
|
|
|
|
array_merge($CACHE[__METHOD__][$spo->POOLTYPE][$cinout][$cstatus],$spo->libvolstype($cinout,$cstatus));
|
|
|
|
}
|
|
|
|
|
2011-06-27 04:37:11 +00:00
|
|
|
return isset($CACHE[__METHOD__][$ptype][$inout][$status]) ? $CACHE[__METHOD__][$ptype][$inout][$status] : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of DB volumes
|
|
|
|
*
|
|
|
|
* @param $inout IN|OUT of the library
|
|
|
|
* @note This is an intensive method that needs caching.
|
|
|
|
*/
|
|
|
|
public function dbvolsloc($inout) {
|
|
|
|
static $CACHE = array();
|
|
|
|
|
|
|
|
if (! isset($CACHE[__METHOD__]))
|
2012-11-27 01:26:56 +00:00
|
|
|
foreach (ORM::factory('VOLHISTORY')->where('TYPE','IN',Kohana::$config->load('config')->tsmdbtypes)->find_all() as $vho)
|
2011-06-27 05:11:32 +00:00
|
|
|
$CACHE[__METHOD__][$vho->LIBVOLUME->LIBRARY_NAME ? 'IN' : 'OUT'][] = $vho;
|
2011-06-27 04:37:11 +00:00
|
|
|
|
|
|
|
return isset($CACHE[__METHOD__][$inout]) ? $CACHE[__METHOD__][$inout] : array();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a list of DB volumes by type
|
|
|
|
// @param $inout IN|OUT of the library
|
|
|
|
// @param $dtype is DB vole type (BACKUPFULL,BACKUPINCR,DBSNAPSHOT)
|
|
|
|
public function dbvolstype($inout,$dtype) {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($this->dbvolsloc($inout) as $vho)
|
|
|
|
if ($vho->TYPE ==$dtype)
|
|
|
|
array_push($result,$vho);
|
|
|
|
|
|
|
|
return $result;
|
2011-06-26 12:20:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function volsnotinlib() {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($this->storagepools() as $spo)
|
|
|
|
foreach ($spo->VOLUME->find_all() as $vo)
|
2011-06-26 12:47:20 +00:00
|
|
|
if (! $vo->MEDIA->inlib())
|
2011-06-26 12:20:12 +00:00
|
|
|
array_push($result,$vo);
|
|
|
|
|
|
|
|
Sort::masort($result,'VOLUME_NAME');
|
|
|
|
return $result;
|
|
|
|
}
|
2011-06-27 04:37:11 +00:00
|
|
|
|
|
|
|
// Volumes that are stale
|
|
|
|
public function stalevol() {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($this->storagepools() as $spo)
|
|
|
|
foreach ($spo->VOLUME->find_all() as $vo)
|
|
|
|
if ($vo->recycle())
|
|
|
|
array_push($result,$vo);
|
|
|
|
|
|
|
|
Sort::masort($result,'VOLUME_NAME');
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removablelibvol() {
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($this->slots() as $slot)
|
|
|
|
if ($slot->LIBVOLUME->removable())
|
|
|
|
array_push($result,$slot->LIBVOLUME);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2011-06-24 01:27:21 +00:00
|
|
|
}
|
|
|
|
?>
|