fogproject  1.5.9
About: FOG is a Linux-based network computer cloning solution for Windows, Mac OSX and various Linux distributions that ties together a few open-source tools with a PHP-based web interface. FOG doesn’t use any boot disks, or CDs; everything is done via TFTP and PXE.
  Fossies Dox: fogproject-1.5.9.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

storagenode.class.php
Go to the documentation of this file.
1 <?php
23 {
29  protected $databaseTable = 'nfsGroupMembers';
35  protected $databaseFields = array(
36  'id' => 'ngmID',
37  'name' => 'ngmMemberName',
38  'description' => 'ngmMemberDescription',
39  'isMaster' => 'ngmIsMasterNode',
40  'storagegroupID' => 'ngmGroupID',
41  'isEnabled' => 'ngmIsEnabled',
42  'isGraphEnabled' => 'ngmGraphEnabled',
43  'path' => 'ngmRootPath',
44  'ftppath' => 'ngmFTPPath',
45  'bitrate' => 'ngmMaxBitrate',
46  'helloInterval' => 'ngmHelloInterval',
47  'snapinpath' => 'ngmSnapinPath',
48  'sslpath' => 'ngmSSLPath',
49  'ip' => 'ngmHostname',
50  'maxClients' => 'ngmMaxClients',
51  'user' => 'ngmUser',
52  'pass' => 'ngmPass',
53  'key' => 'ngmKey',
54  'interface' => 'ngmInterface',
55  'bandwidth' => 'ngmBandwidthLimit',
56  'webroot' => 'ngmWebroot'
57  );
63  protected $databaseFieldsRequired = array(
64  'ip',
65  'path',
66  'ftppath',
67  'user',
68  'pass'
69  );
75  protected $additionalFields = array(
76  'images',
77  'snapinfiles',
78  'logfiles',
79  'usedtasks',
80  'storagegroup',
81  'online'
82  );
89  'StorageGroup' => array(
90  'id',
91  'storagegroupID',
92  'storagegroup'
93  )
94  );
102  public function get($key = '')
103  {
104  $pathvars = array(
105  'path',
106  'ftppath',
107  'snapinpath',
108  'sslpath',
109  'webroot'
110  );
111  if (in_array($key, $pathvars)) {
112  if (trim(parent::get($key)) === '/') {
113  return parent::get($key);
114  }
115  return rtrim(parent::get($key), '/');
116  }
117  if ($key === 'pass') {
118  return htmlspecialchars_decode(parent::get($key), ENT_QUOTES | ENT_HTML401);
119  }
120  $loaders = array(
121  'snapinfiles' => 'getSnapinfiles',
122  'images' => 'getImages',
123  'logfiles' => 'getLogfiles'
124  );
125  if (in_array($key, array_keys($loaders))
126  && !$this->isLoaded($key)
127  ) {
128  $func = $loaders[$key];
129  $this->{$func}();
130  }
131 
132  return parent::get($key);
133  }
139  public function getStorageGroup()
140  {
141  return $this->get('storagegroup');
142  }
148  public function loadOnline()
149  {
150  $test = self::$FOGURLRequests->isAvailable($this->get('ip'), 1);
151  $this->set('online', array_shift($test));
152  }
160  public function getNodeFailure($Host)
161  {
162  foreach ((array)self::getClass('NodeFailureManager')
163  ->find(
164  array(
165  'storagenodeID' => $this->get('id'),
166  'hostID' => $Host,
167  )
168  ) as &$Failed
169  ) {
170  $curr = self::niceDate();
171  $prev = $Failed->get('failureTime');
172  $prev = self::niceDate($prev);
173  if ($curr < $prev) {
174  return $Failed;
175  }
176  unset($Failed);
177  }
178 
179  return $Failed;
180  }
186  public function getLogfiles()
187  {
188  $paths = array_values(
189  array_filter(
190  $this->_getData('logfiles')
191  )
192  );
193  natcasesort($paths);
194  $this->set('logfiles', (array)$paths);
195  }
202  private function _getData($item)
203  {
204  if (!$this->get('online')) {
205  return;
206  }
207  $logpaths = array(
208  '/var/log/nginx',
209  '/var/log/httpd',
210  '/var/log/apache2',
211  '/var/log/fog',
212  '/var/log/php7.0-fpm',
213  '/var/log/php-fpm',
214  '/var/log/php5-fpm',
215  '/var/log/php5.6-fpm',
216  );
217  $items = array(
218  'images' => urlencode($this->get('path')),
219  'snapinfiles' => urlencode($this->get('snapinpath')),
220  'logfiles' => urlencode(implode(':', $logpaths))
221  );
222  if (!array_key_exists($item, $items)) {
223  return;
224  }
225  $url = sprintf(
226  '%s://%s/fog/status/getfiles.php?path=%s',
227  self::$httpproto,
228  $this->get('ip'),
229  $items[$item]
230  );
231  $response = self::$FOGURLRequests->process($url);
232  return preg_grep(
233  '#dev|postdownloadscripts|ssl#',
234  json_decode($response[0], true),
235  PREG_GREP_INVERT
236  );
237  }
243  public function getSnapinfiles()
244  {
245  $response = $this->_getData('snapinfiles');
246  $values = array_map('basename', (array)$response);
247  $this->set('snapinfiles', $values);
248  }
254  public function getImages()
255  {
256  $response = $this->_getData('images');
257  $values = array_map('basename', (array)$response);
258  $values = self::getSubObjectIDs(
259  'Image',
260  array('path' => $values)
261  );
262  $this->set('images', $values);
263  }
269  public function getClientLoad()
270  {
271  if ($this->getUsedSlotCount() + $this->getQueuedSlotCount() < 0) {
272  return 0;
273  }
274  if ($this->get('maxClients') < 1) {
275  return 0;
276  }
277  return (float)(
278  $this->getUsedSlotCount() + $this->getQueuedSlotCount()
279  ) / $this->get('maxClients');
280  }
286  protected function loadUsedtasks()
287  {
288  $used = explode(',', self::getSetting('FOG_USED_TASKS'));
289  if (count($used) < 1) {
290  $used = array(
291  1,
292  15,
293  17,
294  );
295  }
296  $this->set('usedtasks', (array)$used);
297  }
303  public function getUsedSlotCount()
304  {
305  $countTasks = 0;
306  $usedtasks = $this->get('usedtasks');
307  $findTasks = array(
308  'stateID' => self::getProgressState(),
309  'storagenodeID' => $this->get('id'),
310  'typeID' => $usedtasks,
311  );
312  $countTasks = self::getClass('TaskManager')->count($findTasks);
313  $index = array_search(8, $usedtasks);
314  if ($index === false) {
315  return $countTasks;
316  }
317  $MulticastCount = self::getSubObjectIDs(
318  'MulticastSession',
319  array(
320  'stateID' => self::getProgressState()
321  ),
322  'msID'
323  );
324 
325  $countTasks += count($MulticastCount);
326  return $countTasks;
327  }
333  public function getQueuedSlotCount()
334  {
335  $countTasks = 0;
336  $usedtasks = $this->get('usedtasks');
337  $findTasks = array(
338  'stateID' => self::getQueuedStates(),
339  'storagenodeID' => $this->get('id'),
340  'typeID' => $usedtasks,
341  );
342  $countTasks = self::getClass('TaskManager')->count($findTasks);
343  $index = array_search(8, $usedtasks);
344  if ($index === false) {
345  return $countTasks;
346  }
347  $MulticastCount = self::getSubObjectIDs(
348  'MulticastSession',
349  array('stateID' => self::getQueuedStates()),
350  'msID'
351  );
352  $countTasks += count($MulticastCount);
353  return $countTasks;
354  }
355 }
FOGBase\niceDate
static niceDate($date='now', $utc=false)
Definition: fogbase.class.php:1105
StorageNode\$additionalFields
$additionalFields
Definition: storagenode.class.php:75
StorageNode\getSnapinfiles
getSnapinfiles()
Definition: storagenode.class.php:243
StorageNode\$databaseFields
$databaseFields
Definition: storagenode.class.php:35
FOGBase\getClass
static getClass($class, $data='', $props=false)
Definition: fogbase.class.php:439
$response
$response
Definition: logtoview.php:185
StorageNode\_getData
_getData($item)
Definition: storagenode.class.php:202
StorageNode\$databaseFieldsRequired
$databaseFieldsRequired
Definition: storagenode.class.php:63
StorageNode\loadUsedtasks
loadUsedtasks()
Definition: storagenode.class.php:286
$test
$test
Definition: freespace.php:37
$items
$items
Definition: boot.php:24
StorageNode\getUsedSlotCount
getUsedSlotCount()
Definition: storagenode.class.php:303
StorageNode\getStorageGroup
getStorageGroup()
Definition: storagenode.class.php:139
StorageNode\$databaseTable
$databaseTable
Definition: storagenode.class.php:29
StorageNode\getClientLoad
getClientLoad()
Definition: storagenode.class.php:269
StorageNode\getNodeFailure
getNodeFailure($Host)
Definition: storagenode.class.php:160
StorageNode
Definition: storagenode.class.php:23
FOGController
Definition: fogcontroller.class.php:29
StorageNode\getLogfiles
getLogfiles()
Definition: storagenode.class.php:186
$paths
$paths
Definition: getfiles.php:37
FOGBase\getSubObjectIDs
static getSubObjectIDs( $object='Host', $findWhere=array(), $getField='id', $not=false, $operator='AND', $orderBy='name', $groupBy=false, $filter='array_unique')
Definition: fogbase.class.php:2006
StorageNode\getImages
getImages()
Definition: storagenode.class.php:254
FOGBase\$Host
static $Host
Definition: fogbase.class.php:312
StorageNode\$databaseFieldClassRelationships
$databaseFieldClassRelationships
Definition: storagenode.class.php:88
StorageNode\loadOnline
loadOnline()
Definition: storagenode.class.php:148
FOGBase\isLoaded
isLoaded($key)
Definition: fogbase.class.php:969
$url
$url
Definition: kernelvers.php:27
StorageNode\getQueuedSlotCount
getQueuedSlotCount()
Definition: storagenode.class.php:333