/**
  * create a new server and associate a public ip
  *
  * @param String $networkId the id of the network where the server will be created
  * @param String $imageName name of the new image
  * @param String $serverName name ofthe new server
  * @param String $flavor kind of server
  *	
  * @return void
  */
 private function createPublicServer()
 {
     $networkId = $this->app->getPostParam('networkId');
     $imageName = $this->app->getPostParam('imageName');
     $serverName = $this->app->getPostParam('serverName');
     $flavor = $this->app->getPostParam('flavor');
     if (!isset($imageName)) {
         $this->app->setOutput("Error", "Incorrect imageName parameter");
     } else {
         if (!isset($serverName)) {
             $this->app->setOutput("Error", "Incorrect serverName parameter");
         } else {
             if (!isset($flavor)) {
                 $this->app->setOutput("Error", "Incorrect flavor parameter");
             } else {
                 // Création image
                 $opt = array();
                 $opt['name'] = $imageName;
                 $image->setPostParam('opt', $opt);
                 $image->action("createImage");
                 $image = json_decode($this->app->show(), true)["Images"];
                 // Création server
                 $compute->setPostParam('name', $serverName);
                 $compute->setPostParam('imageId', $image['id']);
                 $compute->setPostParam('flavorId', $flavor);
                 $compute->action("createServer");
                 $server = json_decode($this->app->show(), true)["Compute"];
                 // liste des adresses ip publiques diponibles
                 $networkLayer3->action("listFloatingIp");
                 $listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
                 $ip = null;
                 foreach ($listFloatingIp as $f) {
                     if (strcmp($f['status'], "DOWN")) {
                         $ip = $f;
                     }
                 }
                 // Si pas d'ip publique disponible on en créé une
                 if (!isset($ip)) {
                     // Ajout adresse IP public
                     $optIp = array();
                     $opt['floatingNetworkId'] = $networkId;
                     $floatingIp->setPostParam('opt', $optIp);
                     $networkLayer3->action("createFloatingIp");
                     $ip = json_decode($App->show(), true)["NetworkLayer3"];
                 }
                 // Association de l'ip publique au serveur
                 /*
                  * API non diponible pour le moment
                  */
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * retrieve a specific Security Groupe given
  *
  * @param securityGroupeId ID of security Groupe which we want to get
  *
  * @return void
  */
 private function getSecurityGroupe()
 {
     try {
         $securityGroupId = $this->app->getPostParam("securityGroupeId");
         $securityGroupe = $this->libClass->getSecurityGroupe($securityGroupId);
         $this->app->setOutput("securityGroupe", $securityGroupe);
     } catch (BadResponseError $e) {
         $this->app->getErrorInstance->BadResponseHandler($e);
     } catch (UserInputError $e) {
         $this->app->getErrorInstance->UserInputHandler($e);
     } catch (BaseError $e) {
         $this->app->getErrorInstance->BaseErrorHandler($e);
     } catch (NotImplementedError $e) {
         $this->app->getErrorInstance->NotImplementedHandler($e);
     }
 }
Esempio n. 3
0
 /**
  * Update a member of an image
  *
  * @param String $image_id Identifier of the image
  * @param String $member_id Identifier of the member
  * @param String $status New status for the member
  *
  * @return void
  **/
 private function updateMemberImage()
 {
     $image_id = $this->app->getPostParam("image_id");
     $member_id = $this->app->getPostParam("member_id");
     $status = $this->app->getPostParam("status");
     if (!isset($image_id)) {
         $this->app->setOutput("Error", "Incorrect image id parameter");
     } else {
         if (!isset($member_id)) {
             $this->app->setOutput("Error", "Incorrect member id parameter");
         } else {
             try {
                 $service = $this->libClass;
                 $image = $service->getImage($id);
                 if ($image == null) {
                     // if the image don't exists -> error
                     $this->app->setOutput("Error", "Image doesn't exist");
                 }
                 $member = $image->getMember($member_id);
                 if ($member == null) {
                     // if the member don't exists -> error
                     $this->app->setOutput("Error", "Member doesn't exist");
                 }
                 $member->updateStatus($status);
             } catch (BadResponseError $e) {
                 $this->app->getErrorInstance()->BadResponseHandler($e);
             } catch (UserInputError $e) {
                 $this->app->getErrorInstance()->UserInputHandler($e);
             } catch (BaseError $e) {
                 $this->app->getErrorInstance()->BaseErrorHandler($e);
             } catch (NotImplementedError $e) {
                 $this->app->getErrorInstance()->NotImplementedHandler($e);
             } catch (Exception $e) {
                 $this->app->getErrorInstance()->OtherException($e);
             }
         }
     }
 }
 /**
  * Update router
  *
  * @param id the id of the floatingip to update
  * 
  * @return void
  */
 private function updateRouter()
 {
     $id = $this->app->getPostParam("id");
     if (!isset($id)) {
         $this->app->setOutput("Error", "Incorrect parameter opt");
     }
     try {
         // List of floating IPs
         $res = array();
         $l = $this->libClass->listRouters();
         foreach ($l as $tmp) {
             $res[] = $tmp;
         }
         // Verification if id exists
         $result = null;
         foreach ($res as $f) {
             if (strcmp($f->id, $id)) {
                 $result = $f;
             }
         }
         if (!isset($result)) {
             // If id doesn't exists
             $this->app->setOutput("Error", "Unknowing floatingip id");
         } else {
             $result->update();
         }
     } catch (BadResponseError $e) {
         $this->app->getErrorInstance()->BadResponseHandler($e);
     } catch (UserInputError $e) {
         $this->app->getErrorInstance()->UserInputHandler($e);
     } catch (BaseError $e) {
         $this->app->getErrorInstance()->BaseErrorHandler($e);
     } catch (NotImplementedError $e) {
         $this->app->getErrorInstance()->NotImplementedHandler($e);
     } catch (Exception $e) {
         $this->app->getErrorInstance()->OtherException($e);
     }
 }
Esempio n. 5
0
 /**
  * List private and public addresses of a server
  *
  * @return void
  */
 public function listAddresses()
 {
     try {
         $serverId = $this->app->getPostParam("serverId");
         if (!isset($serverId)) {
             $this->app->setOutput("Error", "Server ID is missing!");
             return;
         }
         $opt = array('id' => $serverId);
         $server = $this->libClass->getServer($opt);
         $addresses = $server->listAddresses();
         $this->app->setOutput("Addresses", $addresses);
     } catch (BadResponseError $e) {
         $this->app->getErrorInstance()->BadResponseHandler($e);
     } catch (UserInputError $e) {
         $this->app->getErrorInstance()->UserInputHandler($e);
     } catch (BaseError $e) {
         $this->app->getErrorInstance()->BaseErrorHandler($e);
     } catch (NotImplementedError $e) {
         $this->app->getErrorInstance()->NotImplementedHandler($e);
     } catch (Exception $e) {
         $this->app->getErrorInstance()->OtherException($e);
     }
 }
 /**
  * Put an error message corresponding to an other error in the output
  *
  * @param Exception $error the exception triggered
  *
  * @return void
  */
 public function OtherException($error)
 {
     $this->app->setOutput("Error", $error->getMessage());
 }