コード例 #1
0
 public function multicast_post()
 {
     try {
         // Error Checking
         if (!trim($_REQUEST['name'])) {
             throw new Exception(_('Please input a session name'));
         }
         if (!$_REQUEST['image']) {
             throw new Exception(_('Please choose an image'));
         }
         if ($this->getClass('MulticastSessionsManager')->exists(trim($_REQUEST['name']))) {
             throw new Exception(_('Session with that name already exists'));
         }
         if ($this->getClass('HostManager')->exists(trim($_REQUEST['name']))) {
             throw new Exception(_('Session name cannot be the same as an existing hostname'));
         }
         if (is_numeric($_REQUEST['timeout']) && $_REQUEST['timeout'] > 0) {
             $this->FOGCore->setSetting('FOG_UDPCAST_MAXWAIT', $_REQUEST['timeout']);
         }
         $countmc = $this->getClass('MulticastSessionsManager')->count(array('stateID' => array(0, 1, 2, 3)));
         $countmctot = $this->FOGCore->getSetting('FOG_MULTICAST_MAX_SESSIONS');
         $Image = new Image($_REQUEST['image']);
         $StorageGroup = new StorageGroup($Image->getStorageGroup());
         $StorageNode = $StorageGroup->getMasterStorageNode();
         if ($countmc >= $countmctot) {
             throw new Exception(_('Please wait until a slot is open<br/>There are currently ' . $countmc . ' tasks in queue<br/>Your server only allows ' . $countmctot));
         }
         $MulticastSession = new MulticastSessions(array('name' => trim($_REQUEST['name']), 'port' => $this->FOGCore->getSetting('FOG_UDPCAST_STARTINGPORT'), 'image' => $Image->get('id'), 'stateID' => 0, 'sessclients' => $_REQUEST['count'], 'isDD' => $Image->get('imageTypeID'), 'starttime' => $this->formatTime('now', 'Y-m-d H:i:s'), 'interface' => $StorageNode->get('interface'), 'logpath' => $Image->get('path')));
         if (!$MulticastSession->save()) {
             $this->FOGCore->setMessage(_('Failed to create Session'));
         }
         // Sets a new port number so you can create multiple Multicast Tasks.
         $randomnumber = mt_rand(24576, 32766) * 2;
         while ($randomnumber == $MulticastSession->get('port')) {
             $randomnumber = mt_rand(24576, 32766) * 2;
         }
         $this->FOGCore->setSetting('FOG_UDPCAST_STARTINGPORT', $randomnumber);
         $this->FOGCore->setMessage(_('Multicast session created') . '<br />' . $MulticastSession->get('name') . ' has been started on port ' . $MulticastSession->get('port'));
     } catch (Exception $e) {
         $this->FOGCore->setMessage($e->getMessage());
     }
     $this->FOGCore->redirect('?node=' . $this->node . '&sub=multicast');
 }
コード例 #2
0
     $Task->get('typeID') == 8 ? $MultiSess->set('clients', $MultiSess->get('clients') + 1)->save() : null;
 }
 // Get the count of total associations.
 $Task->get('typeID') == 8 ? $MSAs = $FOGCore->getClass('MulticastSessionsAssociationManager')->count(array('msID' => $MultiSess->get('id'))) : null;
 // Set the task state for this host as in-progress.
 $Task->set('stateID', 3);
 if ($Task->get('typeID') == 8) {
     // If client count is equal, place session task in-progress as it will likely start soon.
     if ($MSAs == $MultiSess->get('clients') || $MultiSess->get('sessclients') > 0 && $MultiSess->get('clients') > 0) {
         $MultiSess->set('stateID', 3);
     } else {
         $MultiSess->set('stateID', 1);
     }
 }
 // Save the info.
 if ($Task->save() && ($Task->get('typeID') == 8 ? $MultiSess->save() : true)) {
     if ($MultiSess && $MultiSess->isValid()) {
         $Host->set('imageID', $MultiSess->get('image'));
     }
     // Log it
     $ImagingLogs = $FOGCore->getClass('ImagingLogManager')->find(array('hostID' => $Host->get('id'), 'type' => $_REQUEST['type'], 'complete' => '0000-00-00 00:00:00'));
     foreach ($ImagingLogs as $ImagingLog) {
         $id[] = $ImagingLog->get('id');
     }
     if (!$id) {
         $il = new ImagingLog(array('hostID' => $Host->get('id'), 'start' => $FOGCore->nice_date()->format('Y-m-d H:i:s'), 'image' => $Task->getImage()->get('name'), 'type' => $_REQUEST['type']));
     } else {
         $il = new ImagingLog(max($id));
         $il->set('start', $FOGCore->nice_set()->format('Y-m-d H:i:s'));
     }
     $il->save();