Example #1
0
 public function save()
 {
     $this->reservation = new Reservation();
     $this->reservation->type = Reservation::TYPE_TEST;
     $this->reservation->name = Test::AT_PREFIX;
     $this->reservation->date = DateUtils::now();
     $this->reservation->start = DateUtils::now();
     $this->reservation->finish = DateUtils::now();
     $this->reservation->bandwidth = 10;
     $this->reservation->requester_nsa = CircuitsPreference::findOneValue(CircuitsPreference::MEICAN_NSA);
     $this->reservation->provider_nsa = CircuitsPreference::findOneValue(CircuitsPreference::CIRCUITS_DEFAULT_PROVIDER_NSA);
     $this->reservation->request_user_id = Yii::$app->user->getId();
     //Confere se usuário tem permissão para testar na origem OU no destino
     $source = Port::findOne(['id' => $this->src_port]);
     $destination = Port::findOne(['id' => $this->dst_port]);
     $permission = false;
     if ($source) {
         $source = $source->getDevice()->one();
         if ($source) {
             $domain = $source->getDomain()->one();
             if ($domain && RbacController::can('test/create', $domain->name)) {
                 $permission = true;
             }
         }
     }
     if ($destination) {
         $destination = $destination->getDevice()->one();
         if ($destination) {
             $domain = $destination->getDomain()->one();
             if ($domain && RbacController::can('test/create', $domain->name)) {
                 $permission = true;
             }
         }
     }
     if (!$permission) {
         Yii::$app->getSession()->addFlash("warning", Yii::t("circuits", "You are not allowed to create a automated test involving these selected domains"));
         return false;
     }
     if ($this->reservation->save()) {
         $this->reservation->name .= $this->reservation->id;
         $this->reservation->save();
         $path = new ReservationPath();
         $path->reservation_id = $this->reservation->id;
         $path->port_urn = Port::findOne($this->src_port)->urn;
         $path->path_order = 0;
         $path->vlan = $this->src_vlan;
         if (!$path->save()) {
             Yii::trace($path->getErrors());
             return false;
         }
         $path = new ReservationPath();
         $path->reservation_id = $this->reservation->id;
         $path->port_urn = Port::findOne($this->dst_port)->urn;
         $path->path_order = 1;
         $path->vlan = $this->dst_vlan;
         if (!$path->save()) {
             Yii::trace($path->getErrors());
             return false;
         }
         $task = new ScheduledTask();
         $task->freq = $this->cron_value;
         $task->obj_class = 'meican\\tester\\models\\Test';
         $task->obj_data = $this->reservation->id;
         if (!$task->save()) {
             Yii::trace($task->getErrors());
             return false;
         }
     } else {
         Yii::trace($this->reservation->getErrors());
         return false;
     }
     return true;
 }
Example #2
0
 public function isScheduled()
 {
     return ScheduledTask::findOne(['obj_data' => $this->id, 'obj_class' => 'meican\\topology\\models\\DiscoveryTask']) != null;
 }
Example #3
0
 function getScheduledTask()
 {
     return ScheduledTask::findOne(['obj_class' => 'meican\\tester\\models\\Test', 'obj_data' => $this->id]);
 }
Example #4
0
 public function afterSave($insert, $changedAttributes)
 {
     $task = ScheduledTask::findOne(['obj_data' => $this->id, 'obj_class' => 'meican\\topology\\models\\DiscoveryTask']);
     if ($this->freq_enabled) {
         if (!$task) {
             $task = new ScheduledTask();
             $task->obj_class = 'meican\\topology\\models\\DiscoveryTask';
             $task->obj_data = $this->id;
         }
         $task->freq = $this->freq;
         $task->save();
     } else {
         if ($task) {
             $task->delete();
         }
     }
 }