This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/application/classes/model/node.php
Deon George 58ddb97d87 Added volumes for a node
Added schedules
Added management classes for a node
Added clientopts to nodes
Added schedule and event information
2011-05-25 13:13:15 +10:00

193 lines
5.2 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
*
* @package PTA
* @subpackage Nodes
* @category Models
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Model_NODE extends ORMTSM {
protected $_table_name = 'NODES';
protected $_primary_key = 'NODE_NAME';
protected $_sorting = array(
'NODE_NAME'=>'ASC',
);
protected $_has_many = array(
'FILESPACE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
'VOLUMEUSAGE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
'ASSOCIATION'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
'MGMTCLASS'=>array('foreign_key'=>'DOMAIN_NAME','far_key'=>'DOMAIN_NAME'),
'CLIENTOPT'=>array('foreign_key'=>'OPTIONSET_NAME','far_key'=>'OPTION_SET'),
'SUMMARY'=>array('foreign_key'=>'ENTITY','far_key'=>'NODE_NAME'),
'EVENT'=>array('foreign_key'=>'NODE_NAME','far_key'=>'NODE_NAME'),
);
protected $_display_filters = array(
'REG_TIME'=>array(
array('ORMTSM::date',array(':value','d-M-Y')),
),
'PWSET_TIME'=>array(
array('ORMTSM::date',array(':value','d-M-Y')),
),
'LASTACC_TIME'=>array(
array('ORMTSM::date',array(':value','d-M-Y')),
),
'LASTSESS_SENT'=>array(
array('number_format',array(':value',0)),
),
'LASTSESS_RECVD'=>array(
array('number_format',array(':value',0)),
),
'LASTSESS_DURATION'=>array(
array('number_format',array(':value',2)),
),
'LASTSESS_IDLEWAIT'=>array(
array('number_format',array(':value',2)),
),
'LASTSESS_COMMWAIT'=>array(
array('number_format',array(':value',2)),
),
'LASTSESS_MEDIAWAIT'=>array(
array('number_format',array(':value',2)),
),
);
// Pools used by a node.
private $pools = array();
public function tsmclientversion() {
return sprintf('%s.%s.%s.%s',$this->CLIENT_VERSION,$this->CLIENT_RELEASE,$this->CLIENT_LEVEL,$this->CLIENT_SUBLEVEL);
}
// @todo This needs to return the global configuration.
public function passexp() {
if ($this->PASSEXP)
return 'TBA';
else
return _('No Set');
}
public function lasttransferpercent() {
return 100-($this->LASTSESS_IDLEWAIT+$this->LASTSESS_COMMWAIT+$this->LASTSESS_MEDIAWAIT);
}
public function lasttransfertime() {
if ($this->LASTSESS_DURATION)
return $this->LASTSESS_DURATION*($this->lasttransferpercent()/100);
else
return 0;
}
public function lastsendperformance() {
if ($this->lasttransfertime())
return $this->LASTSESS_SENT/$this->lasttransfertime()/1024/1024;
else
return 0;
}
public function lastreceiveperformance() {
if ($this->lasttransfertime())
return $this->LASTSESS_RECVD/$this->lasttransfertime()/1024/1024;
else
return 0;
}
public function lastsendaggperformance() {
if ((real)$this->LASTSESS_DURATION)
return $this->LASTSESS_SENT/$this->LASTSESS_DURATION/1024/1024;
else
return 0;
}
public function lastreceiveaggperformance() {
if ((real)$this->LASTSESS_DURATION)
return $this->LASTSESS_RECVD/$this->LASTSESS_DURATION/1024/1024;
else
return 0;
}
// @todo This should return the system setting (cloptset), if the node setting is not configured.
public function txngroupmax() {
return $this->TXNGROUPMAX;
}
// Work out all the storage pools used by a node.
// $dtype is BACKUP or ARCHIVE
public function getStoragePools($dtype) {
return isset($this->pools[$dtype]) ? $this->pools[$dtype] : $this->_getpools($dtype);
}
private function _getpools($dtype) {
$this->pools[$dtype] = array();
foreach ($this->FILESPACE->find_all() as $fso)
foreach ($fso->storagepools($dtype) as $po)
if (! isset($this->pools[$dtype][$po->POOLTYPE]) OR ! in_array($po->STGPOOL_NAME,$this->pools[$dtype][$po->POOLTYPE]))
$this->pools[$dtype][$po->POOLTYPE][] = $po;
return $this->pools[$dtype];
}
// Return the storage pools used for a backup type
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStoragePoolsType($dtype,$ptype) {
if (! isset($this->pools[$dtype]))
$this->_getpools($dtype);
return isset($this->pools[$dtype][$ptype]) ? $this->pools[$dtype][$ptype] : array();
}
// @todo This routine should be cached.
public function getStorageTypeFiles($type) {
$count = 0;
foreach ($this->FILESPACE->find_all() as $fo)
foreach ($fo->OCCUPANCY->find_all() as $oa)
if ($oa->STGPOOL->POOLTYPE == $type)
$count += $oa->NUM_FILES;
return $count;
}
// @todo This routine should be cached.
public function getStorageTypeData($type) {
$count = 0;
foreach ($this->FILESPACE->find_all() as $fo)
foreach ($fo->OCCUPANCY->find_all() as $oa)
if ($oa->STGPOOL->POOLTYPE == $type)
$count += $oa->LOGICAL_MB;
return $count;
}
// Return the volumes that this node uses
// $dtype is BACKUP or ARCHIVE
// @todo Cache this data
public function volumes($dtype) {
$volumes = array();
foreach ($this->VOLUMEUSAGE->where('COPY_TYPE','=',$dtype)->order_by('STGPOOL_NAME,FILESPACE_NAME')->find_all() as $vol)
$volumes[$vol->STGPOOL_NAME][] = $vol->VOLUME;
return $volumes;
}
/**
* Get all the nodes by OS
*/
public function byos() {
$a = $this->select('count(*) AS node_name,platform_name')
->group_by('platform_name')
->order_by('platform_name');
return $a->find_all();
}
}
?>