Example #1
0
 public function save()
 {
     $this->reservation = new Reservation();
     $this->reservation->type = Reservation::TYPE_NORMAL;
     $this->reservation->name = $this->name;
     $this->reservation->date = DateUtils::now();
     $this->reservation->bandwidth = $this->bandwidth;
     $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();
     if ($this->reservation->save()) {
         for ($i = 0; $i < count($this->path['port']); $i++) {
             $path = new ReservationPath();
             $path->reservation_id = $this->reservation->id;
             if ($this->path['mode'][$i] == 'normal') {
                 $path->port_urn = Port::find()->where(['id' => $this->path['port'][$i]])->one()->urn;
             } else {
                 $path->port_urn = str_replace('urn:ogf:network:', '', $this->path['urn'][$i]);
             }
             $path->path_order = $i;
             $path->vlan = $this->path['vlan'][$i];
             if (!$path->save()) {
                 Yii::trace($path->getErrors());
             }
         }
         $this->reservation->createConnections($this->events);
     }
     Yii::trace($this->reservation->getErrors());
     return true;
 }
Example #2
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 #3
0
 public function getLastPath()
 {
     return ReservationPath::find()->where(['reservation_id' => $this->id, 'path_order' => ReservationPath::find()->where(['reservation_id' => $this->id])->max('path_order')]);
 }