From e01936a73e75350a40fafd80995b1525a11c9da1 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 09:46:32 +0100 Subject: add commentaries, update error management and correct some mistakes in Image.php, resolve conflict in AppTestClass.php --- server/Test/AppTestClass.php | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index b398088..5e8efc7 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -1,24 +1,12 @@ >>>>>> Stashed changes -======= -include_once("../core/ErrorManagement.php"); - -use OpenStack\Common\Error\BadResponseError; -use OpenStack\Common\Error\BaseError; -use OpenStack\Common\Error\NotImplementedError; -use OpenStack\Common\Error\UserInputError; ->>>>>>> develop class AppTest{ -- cgit v1.2.3 From fe0eb3a9e259b4fe09df364f0660ebc62185f9dd Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 11:34:56 +0100 Subject: add exception management, correct mistakes in error management in Image.php and add function to simplify parameters using in tests --- server/Test/AppTestClass.php | 8 +- server/Test/imageTests.php | 68 ++--- server/core/ErrorManagement.php | 4 + server/core/Image.php | 549 ++++++++++++++++++++++------------------ 4 files changed, 339 insertions(+), 290 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 5e8efc7..e1631c5 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -89,10 +89,16 @@ class AppTest{ } public function getPostParam($name){ - + return $this->postParams[$name]; } + + public function setPostParam($name, $value){ + + $this->postParams[$name] = $value; + + } public function setOutput($key, $out){ diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 3af12fc..883387d 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -14,55 +14,39 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$new_image = $image->createImage($opt); +//$App->setPostParam('id', 'sdfihlus154dfhj'); +$err = $image->action("createImage"); + //Liste des images $image->action("listImage"); -//$images = $image->listImage(); $im = $App->show(); -$images = json_decode($im, true)["Images"]; -if(isset($images)){ - echo "Images présentes :"; - echo "
"; - foreach($images as $i){ - echo $i['name']; - echo "
"; - } +$images = json_decode($im, true)["Images"]; +$recup; + +echo "Images présentes :"; +echo "
"; +foreach($images as $i){ + $recup = $i; + echo $recup['name']; echo "
"; + //echo $recup['id']; + } +echo "
"; +echo "Erreur capturée: "; +echo "
"; + + /* + //$App->setPostParam('id', $recup['id']); + $App->setPostParam('id', 'sdfihlus154dfhj'); + $err = $image->action("detailsImage"); + $temp = $App->show(); + $ret = json_decode($temp, true)["Images"]; + echo $ret['id']; + */ + //$App->getPostParam("id"); - if(isset($list)){ - foreach ($list as $l) { - echo $l; - echo "
"; - } -} -} -else{ - echo "Aucune image présente\n"; -} - - - -// Détails Image -//$details = $image->imageDetails($id_image); - -//$image->deleteImage('123456'); - -//$image->desactivateImage($id_image); -//$image->reactivateImage($id_image); - -//$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso"; -//$image->uploadImage($id_image, $file_name); - -//$image->downloadImage($id_image); -/* -$opt_update = Array(); -$opt_update['name'] = "Test"; -$opt_update['tags'] = null; -$update = $image->updateImage($id_image, $opt_update); -echo $update->name; -*/ ?> \ No newline at end of file diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index 4ba3493..ff66339 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -32,6 +32,10 @@ Class errorManagement{ public function UserInputHandler($error){ } + + public function OtherException($error){ + $this->app->setOutput("Error", $error->getMessage); + } } diff --git a/server/core/Image.php b/server/core/Image.php index f309943..71e19ce 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -131,6 +131,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $image); @@ -156,6 +158,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $result); @@ -171,26 +175,33 @@ class image implements Core{ */ private function detailsImage(){ $id = $this->app->getPostParam("id"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); - } - 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"); - } - $this->app->setOutput("Images", $image); - }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); - } + 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"); + } + else{ + echo 'toto'; + $this->app->setOutput("Images", $image); + } + }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); + } + } } /** @@ -209,50 +220,53 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($opt)){ + else if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect opt parameter"); } + else{ + try{ + //vérifier existence image + $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"); + } - try{ - //vérifier existence image - $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"); - } - - $options = Array(); + $options = Array(); - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); - }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); - } - $this->app->setOutput("Images", $image); + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }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); + } + $this->app->setOutput("Images", $image); + } } /** @@ -269,23 +283,26 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } - - try{ - $service = $this->libClass; - $image = $this->libClass->getImage($id); - if($image == null){ // if the image doesn't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->delete(); - }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); - } + else{ + try{ + $service = $this->libClass; + $image = $this->libClass->getImage($id); + if($image == null){ // if the image doesn't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->delete(); + }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); + } + } } /** @@ -301,22 +318,27 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - 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"); - } - $image->reactivate(); - }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); - } + 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"); + } + $image->reactivate(); + }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); + } + } } /** @@ -332,23 +354,28 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - // vérifier existence image - $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"); - } - $image->deactivate(); - }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); - } + else + { + try{ + // vérifier existence image + $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"); + } + $image->deactivate(); + }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); + } + } } /** @@ -367,26 +394,30 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($file_name)){ + else if(!isset($file_name)){ $this->app->setOutput("Error", "Incorrect file name parameter"); } - try{ - // vérifier existence image - $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"); - } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); - $image->uploadData($stream); - }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); + else{ + try{ + // vérifier existence image + $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"); + } + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $image->uploadData($stream); + }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); + } } } @@ -403,24 +434,28 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - try{ - // vérifier existence image - $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"); - } - $stream = $image->downloadData(); - }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); - } - $this->app->setOutput("Images", $stream); + else{ + try{ + // vérifier existence image + $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"); + } + $stream = $image->downloadData(); + }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); + } + $this->app->setOutput("Images", $stream); + } } /** @@ -438,27 +473,31 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + 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_id = $image->addMember($member_id); - $this->app->setOutput("Images", $member_id); - }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); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member_id = $image->addMember($member_id); + $this->app->setOutput("Images", $member_id); + }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); + } + } } @@ -476,30 +515,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($image_id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $members = $image->listMembers(); - if($members == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "No member"); - } - }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); - } - $this->app->setOutput("Images", $members); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $members = $image->listMembers(); + if($members == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "No member"); + } + }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); + } + $this->app->setOutput("Images", $members); + } } /** @@ -517,31 +560,35 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + 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"); - } + $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"); - } - }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); - } - $this->app->setOutput("Images", $member); + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + }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); + } + $this->app->setOutput("Images", $member); + } } /** @@ -559,30 +606,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - 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 image don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->delete(); - }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); - } + 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 image don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->delete(); + }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); + } + } } /** @@ -602,30 +653,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + 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); - } + $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); + } + } } } -- cgit v1.2.3 From db2c1490b3e7a9be5ce8cbee37f772a1bd4f2268 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 23 Mar 2016 15:44:06 +0100 Subject: auth correction in AppTestClass.php --- server/Test/AppTestClass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index e1631c5..3f8abbe 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -22,7 +22,7 @@ class AppTest{ $this->tokenPost = NULL; $this->tokenClass = new genTokenOptions($args); - $this->openstack = new OpenStack\OpenStack([]); + $this->openstack = new OpenStack\OpenStack(['authUrl' => $args["authUrl"]]); $this->pluginsApi = plugin_api::getInstance(); $this->errorClass = new errorManagement($this); $this->output = array(); -- cgit v1.2.3 From e9c7477ff0acedf9b49e508e1543395bbcbf7533 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 27 Mar 2016 19:24:03 +0200 Subject: Modifications in error management and correct error in Image.php --- server/Test/AppTestClass.php | 8 ++-- server/Test/imageTests.php | 95 +++++++++++++++++++++++++++++++---------- server/core/App.php | 15 ++++--- server/core/ErrorManagement.php | 37 ++++++++++++++-- server/core/Image.php | 8 ++-- 5 files changed, 124 insertions(+), 39 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 3f8abbe..a663514 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -89,9 +89,11 @@ class AppTest{ } public function getPostParam($name){ - - return $this->postParams[$name]; - + if(isset($this->postParams[$name])){ + return $this->postParams[$name]; + }else{ + $this->setOutput("Error", "Missing parameter ".$name); + } } public function setPostParam($name, $value){ diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index d86c664..4adec08 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -6,6 +6,9 @@ include_once("../core/Compute.php"); $image = new Image($App); $compute = new Compute($App); +// Création image +/* +echo "Création image :
"; $opt = Array(); $opt['name'] = "Test"; $opt['tags'] = ['test', 'openstack']; @@ -16,28 +19,86 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$App->setPostParam('id', 'sdfihlus154dfhj'); -//$err = $image->action("createImage"); +$App->setPostParam('opt', $opt); +$image->action("createImage"); +$retCreate = json_decode($App->show(), true)["Images"]; +$idNew = $retCreate['id']; +*/ +/* +// Delete Image +$App->setPostParam('id', $idNew); +$image->action("deleteImage"); +*/ -//Liste des images +// Liste images $image->action("listImage"); $im = $App->show(); $images = json_decode($im, true)["Images"]; -echo "Images présentes :"; -echo "
"; +echo "List images :
"; foreach($images as $i){ - $recup = $i; - echo $recup['name']; + echo $i['name']."
"; // Nom + echo $i['status']."
"; // Status + $id = $i['id']; // Id + echo $id."
"; + foreach ($i['tags'] as $tag) { // Tags + echo $tag."
"; + } echo "
"; - //echo $recup['id']; - } + } + + +// Details images +echo "Détail image :
"; +$App->setPostParam('id', $id); +$image->action("detailsImage"); +$retDetails = json_decode($App->show(), true)["Images"]; +echo $retDetails['id']."
"; +echo "
"; + + +/* +// Download image +$App->setPostParam('id', $id); +$image->action("downloadImage"); +*/ + + +// Desactivate Images +echo "Desactivate image :
"; +echo $id."
"; +$App->setPostParam('id', $id); +$err = $image->action("desactivateImage"); echo "
"; + +/* +// Resactivate Images +echo $id."
"; +$App->setPostParam('id', $id); +$err = $image->action("resactivateImage"); +*/ + + +/* +// Details images +echo "Update image :
"; +$optUpdate = Array(); +$optUpdate['tags'] = ['ciros', 'testUpdate']; +$App->setPostParam('id', $id); +$App->setPostParam('opt', $optUpdate); +$image->action("updateImage"); +$retDetails = json_decode($App->show(), true)["Images"]; +foreach ($retDetails['tags'] as $tag) { // Tags + echo $tag."
"; +} +*/ + + +/* echo "Flavors: "; echo "
"; - $compute->action("listFlavors"); $flavors = json_decode($App->show(), true)["Flavors"]; @@ -49,17 +110,5 @@ foreach($flavors as $f){ echo "vcpus=".$f['vcpus']; echo "
"; } - -/* -$App->setPostParam('id', 354); -$err = $image->action("deleteImage"); -$temp = $App->show(); -$ret = json_decode($temp, true)["Images"]; -echo $ret['id']; -*/ - - - - - +*/ ?> \ No newline at end of file diff --git a/server/core/App.php b/server/core/App.php index 10813bd..48bb9ab 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -112,15 +112,20 @@ class App{ } public function getPostParam($name){ - - return $this->postParams[$name]; + + if(isset($this->postParams[$name])){ + return $this->postParams[$name]; + }else{ + $this->setOutput("Error", "Missing parameter ".$name); + } } - public function setPostParam($name, $value){ - - $this->postParams[$name]= $value; + + public function setPostParam($param, $value){ + $this->postParams[$param] = $value; + } public function setOutput($key, $out){ diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index 3257dd3..e7cb83e 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -18,19 +18,48 @@ Class errorManagement{ } public function BaseErrorHandler($error){ - + $this->app->setOutput("Error", "BaseError"); } public function BadResponseHandler($error){ - $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!"); + $statusCode = $error->getResponse()->getStatusCode(); + switch ($statusCode) { + case 400: + $this->app->setOutput("Error", "Invalid input."); + break; + + case 401: + $this->app->setOutput("Error", "Authentification failed."); + break; + + case 403: + $this->app->setOutput("Error", "Operation forbidden."); + break; + + case 404: + $this->app->setOutput("Error", "Ressource not found."); + break; + + case 500: + $this->app->setOutput("Error", "Internal server error, please contact an administrator."); + break; + + case 503: + $this->app->setOutput("Error", "Service unvailable for the moment."); + break; + + default: + $this->app->setOutput("Error", "Unknow error, please contact an administrator."); + break; + } } public function NotImplementedHandler($error){ - $this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!"); + $this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator"); } public function UserInputHandler($error){ - + $this->app->setOutput("Error", "UserInputError"); } public function OtherException($error){ diff --git a/server/core/Image.php b/server/core/Image.php index 71e19ce..e9736a2 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -76,7 +76,7 @@ class image implements Core{ // Check the image name if(isset($opt['name'])){ - $imagesList = listImage(); + $imagesList = $this->listImage(); if(isset($imagesList)){ foreach($imagesList as $image){ if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error @@ -84,7 +84,7 @@ class image implements Core{ } } } - + $options['name'] = $opt['name']; } else{ $this->app->setOutput("Error", "Missing parameter 'name' for the new image"); @@ -118,7 +118,7 @@ class image implements Core{ if(isset($opt['protected'])){ // boolean $options['protected'] = $opt['protected']; } - if(isset($opt['properties'])){ // type dict ? + if(isset($opt['properties'])){ // type dict $options['properties'] = $opt['properties']; } @@ -187,7 +187,6 @@ class image implements Core{ $this->app->setOutput("Error", "Image doesn't exist"); } else{ - echo 'toto'; $this->app->setOutput("Images", $image); } }catch(BadResponseError $e){ @@ -326,6 +325,7 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } + $image->reactivate(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); -- cgit v1.2.3 From 3795d05a97dd144073d466be1ed0fd144683d8df Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Tue, 19 Apr 2016 18:00:37 +0200 Subject: trying test floatingip --- server/Test/AppTestClass.php | 5 +++++ server/Test/automatingTests.php | 22 ++++++++++-------- server/core/FloatingIp.php | 50 ++++++++++++++++++++++++++++------------- 3 files changed, 53 insertions(+), 24 deletions(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index a663514..eaea7f6 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -63,6 +63,11 @@ class AppTest{ $opt = $this->tokenClass->getOptions($service); return $this->openstack->networkingV2($opt); break; + case "FloatingIp": + if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken(); + $opt = $this->tokenClass->getOptions($service); + return $this->openstack->networkingV2ExtLayer3($opt); + break; } } diff --git a/server/Test/automatingTests.php b/server/Test/automatingTests.php index 5cdee26..6de4de5 100644 --- a/server/Test/automatingTests.php +++ b/server/Test/automatingTests.php @@ -2,23 +2,27 @@ include('InitTest.php'); include_once("../core/Image.php"); include_once("../core/Compute.php"); -include_once("../core/Network.php"); +//include_once("../core/Network.php"); +//include_once("../core/Automating.php"); include_once("../core/FloatingIp.php"); -include_once("../core/Automating.php"); $image = new Image($App); $compute = new Compute($App); -$network = new Network($App); +//$network = new Network($App); $floatingIp = new FloatingIp($App); -$automating = new Automating($App); - - -$compute->listServers(); +//$automating = new Automating($App); +// Liste des serveurs +$compute->action("listServers"); $servers = json_decode($App->show(), true)["Servers"]; - foreach($servers as $server){ - echo $server->name." ".$server->id."
"; + echo $server['name']." ".$server['id']."
"; } +// liste des floatingip +$floatingIp->action("listFloatingIp"); +$listFloatingIp = json_decode($App->show(), true)["FloatingIp"]; +foreach ($listFloatingIp as $floatIp){ + echo $floatIp['floating_ip_address']." ".$floatIp['id']." ".$floatIp["status"]."
"; +} ?> \ No newline at end of file diff --git a/server/core/FloatingIp.php b/server/core/FloatingIp.php index c5a947e..bbcd888 100755 --- a/server/core/FloatingIp.php +++ b/server/core/FloatingIp.php @@ -14,7 +14,7 @@ use OpenCloud\Common\Error\BaseError; use OpenCloud\Common\Error\NotImplementedError; use OpenCloud\Common\Error\UserInputError; -include("CoreInterface.php"); +//include("CoreInterface.php"); /** * Image Class of the back-end application @@ -22,7 +22,7 @@ include("CoreInterface.php"); * Management of images * */ -class floatingIp implements Core{ +class floatingIp { /** @var App $app protected, contains the main app object */ protected $app; @@ -31,11 +31,11 @@ class floatingIp implements Core{ protected $libClass; /** - * Image constructor + * floatingip constructor * * @param App $app the main app object * - * @return Image + * @return floatingip */ public function __construct($app){ if(!isset($app)){ @@ -57,6 +57,36 @@ class floatingIp implements Core{ $this->{$action.""}(); } + + /** + * List floatingip + * + * @return list of the floatingip + */ + private function listFloatingIp(){ + try{ + $result = array(); + $l = $this->libClass->getFloatingIps(); + + + + foreach ($l as $tmp) { + $serult[] = $tmp; + } + $this->app->setOutput("FloatingIp", $result); + }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); + } + } + /** * Create a new floating IP adress * @@ -72,7 +102,7 @@ class floatingIp implements Core{ } try{ $floatingip = $this->libClass->create($opt); - if(!isset){ + if(!isset($floatingip)){ $this->app->setOutput("Error", "Unknowing error during floating ip creation"); } else{ @@ -118,9 +148,6 @@ class floatingIp implements Core{ $floatingip->update(); - if(!isset){ - $this->app->setOutput("Error", "Unknowing error during floating ip creation"); - } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -161,9 +188,6 @@ class floatingIp implements Core{ $floatingip->delete(); - if(!isset){ - $this->app->setOutput("Error", "Unknowing error during floating ip creation"); - } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -203,10 +227,6 @@ class floatingIp implements Core{ } $floatingip->retrieve(); - - if(!isset){ - $this->app->setOutput("Error", "Unknowing error during floating ip creation"); - } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ -- cgit v1.2.3 From 6a3f770c762de4decfbb483bb8212ea44ffc44d1 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Tue, 19 Apr 2016 18:27:27 +0200 Subject: add init FloatingIp --- server/Test/AppTestClass.php | 2 +- server/core/App.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index eaea7f6..d8a02ca 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -65,7 +65,7 @@ class AppTest{ break; case "FloatingIp": if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken(); - $opt = $this->tokenClass->getOptions($service); + $opt = $this->tokenClass->getOptions('Network'); return $this->openstack->networkingV2ExtLayer3($opt); break; } diff --git a/server/core/App.php b/server/core/App.php index 48bb9ab..a4be6ec 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -64,6 +64,11 @@ class App{ $opt = $this->tokenClass->getOptions($service); return $this->openstack->computeV2($opt); break; + case "FloatingIp": + if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken(); + $opt = $this->tokenClass->getOptions('Network'); + return $this->openstack->networkingV2ExtLayer3($opt); + break; } } -- cgit v1.2.3 From 3f6af0b6446725462362de94f09daf9a723b130d Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 21 Apr 2016 21:51:46 +0200 Subject: modification in structure for ip and routers --- server/Test/AppTestClass.php | 2 +- server/Test/NetworkLayer3Tests.php | 88 ++++++++++ server/Test/automatingTests.php | 40 +---- server/Test/floatingIpTests.php | 88 ---------- server/core/App.php | 2 +- server/core/Automating.php | 5 +- server/core/FloatingIp.php | 326 ------------------------------------- server/core/NetworkLayer3.php | 326 +++++++++++++++++++++++++++++++++++++ server/index.php | 6 +- 9 files changed, 427 insertions(+), 456 deletions(-) create mode 100644 server/Test/NetworkLayer3Tests.php delete mode 100644 server/Test/floatingIpTests.php delete mode 100755 server/core/FloatingIp.php create mode 100755 server/core/NetworkLayer3.php (limited to 'server/Test/AppTestClass.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index d8a02ca..972d9b4 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -63,7 +63,7 @@ class AppTest{ $opt = $this->tokenClass->getOptions($service); return $this->openstack->networkingV2($opt); break; - case "FloatingIp": + case "NetworkLayer3": if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken(); $opt = $this->tokenClass->getOptions('Network'); return $this->openstack->networkingV2ExtLayer3($opt); diff --git a/server/Test/NetworkLayer3Tests.php b/server/Test/NetworkLayer3Tests.php new file mode 100644 index 0000000..b827a51 --- /dev/null +++ b/server/Test/NetworkLayer3Tests.php @@ -0,0 +1,88 @@ +"; +$compute->action("listServers"); +$servers = json_decode($App->show(), true)["Servers"]; +$id = null; +foreach($servers as $server){ + echo $server['name']." ".$server['id']." ".$server['ipv4']."
"; + if(strcmp($server['name'], "bob")){ + $id = $server['id']; + } +} +echo "
"; + + +// Liste des networks +echo "Liste des network :
"; +$network->action("list_network_ids"); +$servers = json_decode($App->show(), true)["ListNetworkIds"]; +$id = null; +foreach($servers as $server){ + echo $server."
"; +} +echo "
"; + + +// Liste des floatingip +echo "Liste des floatingip :
"; +$networkLayer3->action("listFloatingIp"); +$listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"]; +$id = null; +foreach ($listFloatingIp as $floatIp){ + echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
"; + $id = $floatIp['id']; +} +echo "
"; + + +// Liste des floatingip +echo "Get floatingip :
"; +$App->setPostParam('id', $id); +$networkLayer3->action("getFloatingIp"); +$getFloatingIp = json_decode($App->show(), true)["NetworkLayer3"]; +echo $getFloatingIp['id']."
"; +echo "
"; + + +/* +// Création d'une ip flotante +$opt = array(); +$opt['floatingNetworkId'] = "251b4641-20ff-4a72-8549-1758788b51ce"; + +$App->setPostParam('opt', $opt); +$networkLayer3->action("createFloatingIp"); +$float = json_decode($App->show(), true)["NetworkLayer3"]; +if(!isset($float)){ + echo "Erreur pendant la création
"; +} +echo "
"; +*/ + +/* +// Suppression d'une ip flotante +$App->setPostParam('id', $id); +$networkLayer3->action("deleteFloatingIp"); +*/ + +// Liste des floatingip +echo "Liste des floatingip :
"; +$networkLayer3->action("listFloatingIp"); +$listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"]; +foreach ($listFloatingIp as $floatIp){ + echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
"; +} + + +?> \ No newline at end of file diff --git a/server/Test/automatingTests.php b/server/Test/automatingTests.php index 3f32d02..e8e8475 100755 --- a/server/Test/automatingTests.php +++ b/server/Test/automatingTests.php @@ -4,12 +4,11 @@ include_once("../core/Image.php"); include_once("../core/Compute.php"); include_once("../core/Network.php"); //include_once("../core/Automating.php"); -include_once("../core/FloatingIp.php"); +include_once("../core/NetworkLayer3.php"); $image = new Image($App); $compute = new Compute($App); -$network = new Network($App); -$floatingIp = new FloatingIp($App); +$networkLayer3 = new NetworkLayer3($App); //$automating = new Automating($App); // Liste des serveurs @@ -25,15 +24,7 @@ foreach($servers as $server){ } echo "
"; -/* -// Liste des ports -echo "Liste des ports :
"; -$network->action("listPorts"); -$ports = json_decode($App->show(), true)["Network"]; -foreach ($ports as $p) { - echo $p["fixedIps"]."
"; -} -*/ + //Liste des networks echo "Liste des network :
"; $network->action("list_network_ids"); @@ -44,32 +35,11 @@ foreach($servers as $server){ } echo "
"; -/* -// Création d'une ip flotante -$opt = array(); -//$opt['floatingNetworkId'] = $id; !!!!! TOTALEMENT FAUX ici tu passe en parametre l id du serveur et non du network -//$opt['floatingip'] = $ip; !!!! il n y a pas d objet floatingip a passer en param, celui ci est compose, regarde bien les exemples de l api OpenStack -//$opt['tenantId'] = "fbf5f920a7954b61b352bc09ce5ae803 "; -//$opt['fixedIpAddress'] = "10.0.0.52"; -//$opt['floatingIpAddress'] = "148.60.11.116"; -//$opt['portId'] = "10.0.0.52"; -$opt['floatingNetworkId'] = "251b4641-20ff-4a72-8549-1758788b51ce"; - -$App->setPostParam('opt', $opt); -$floatingIp->action("createFloatingIp"); -$float = json_decode($App->show(), true)["FloatingIp"]; -if(!isset($float)){ - echo "Erreur pendant la création
"; -} -echo "
"; -*/ - - // liste des floatingip echo "Liste des floatingip :
"; -$floatingIp->action("listFloatingIp"); -$listFloatingIp = json_decode($App->show(), true)["FloatingIp"]; +$networkLayer3->action("listFloatingIp"); +$listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"]; foreach ($listFloatingIp as $floatIp){ echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
"; } diff --git a/server/Test/floatingIpTests.php b/server/Test/floatingIpTests.php deleted file mode 100644 index 191de46..0000000 --- a/server/Test/floatingIpTests.php +++ /dev/null @@ -1,88 +0,0 @@ -"; -$compute->action("listServers"); -$servers = json_decode($App->show(), true)["Servers"]; -$id = null; -foreach($servers as $server){ - echo $server['name']." ".$server['id']." ".$server['ipv4']."
"; - if(strcmp($server['name'], "bob")){ - $id = $server['id']; - } -} -echo "
"; - - -// Liste des networks -echo "Liste des network :
"; -$network->action("list_network_ids"); -$servers = json_decode($App->show(), true)["ListNetworkIds"]; -$id = null; -foreach($servers as $server){ - echo $server."
"; -} -echo "
"; - - -// Liste des floatingip -echo "Liste des floatingip :
"; -$floatingIp->action("listFloatingIp"); -$listFloatingIp = json_decode($App->show(), true)["FloatingIp"]; -$id = null; -foreach ($listFloatingIp as $floatIp){ - echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
"; - $id = $floatIp['id']; -} -echo "
"; - - -// Liste des floatingip -echo "Get floatingip :
"; -$App->setPostParam('id', $id); -$floatingIp->action("getFloatingIp"); -$getFloatingIp = json_decode($App->show(), true)["FloatingIp"]; -echo $getFloatingIp['id']."
"; -echo "
"; - - -/* -// Création d'une ip flotante -$opt = array(); -$opt['floatingNetworkId'] = "251b4641-20ff-4a72-8549-1758788b51ce"; - -$App->setPostParam('opt', $opt); -$floatingIp->action("createFloatingIp"); -$float = json_decode($App->show(), true)["FloatingIp"]; -if(!isset($float)){ - echo "Erreur pendant la création
"; -} -echo "
"; -*/ - -/* -// Suppression d'une ip flotante -$App->setPostParam('id', $id); -$floatingIp->action("deleteFloatingIp"); -*/ - -// Liste des floatingip -echo "Liste des floatingip :
"; -$floatingIp->action("listFloatingIp"); -$listFloatingIp = json_decode($App->show(), true)["FloatingIp"]; -foreach ($listFloatingIp as $floatIp){ - echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
"; -} - - -?> \ No newline at end of file diff --git a/server/core/App.php b/server/core/App.php index a4be6ec..32ad016 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -64,7 +64,7 @@ class App{ $opt = $this->tokenClass->getOptions($service); return $this->openstack->computeV2($opt); break; - case "FloatingIp": + case "NetworkLayer3": if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken(); $opt = $this->tokenClass->getOptions('Network'); return $this->openstack->networkingV2ExtLayer3($opt); diff --git a/server/core/Automating.php b/server/core/Automating.php index 69a2773..4e212e7 100755 --- a/server/core/Automating.php +++ b/server/core/Automating.php @@ -14,6 +14,7 @@ include("CoreInterface.php"); include("Image.php"); include("Network.php"); include("Compute.php"); +include("NetworkLayer3"); class automating implements Core{ @@ -22,7 +23,7 @@ class automating implements Core{ protected $appImage; protected $appNetwork; protected $appIdentity; - protected $appFloatingIp; + protected $appNetworkLayer3; protected $app; /** @@ -40,7 +41,7 @@ class automating implements Core{ $this->appImage = $appImage; $this->appNetwork = $appNetwork; $this->appIdentity = $appIdentity; - $this->appFloatingIp = $appFloatingIp; + $this->appNetworkLayer3 = $appNetworkLayer3; $this->app = $app; } diff --git a/server/core/FloatingIp.php b/server/core/FloatingIp.php deleted file mode 100755 index cdbb64b..0000000 --- a/server/core/FloatingIp.php +++ /dev/null @@ -1,326 +0,0 @@ -app->setOutput("Error", "Incorrect parameter app"); - } - $this->app = $app; - $this->libClass = $app->getLibClass("FloatingIp"); - } - - - /** - * Execute an action - * - * @param String $action name of another function of this class - * - * @return void - */ - public function action($action){ - $this->{$action.""}(); - } - - - /** - * List floatingip - * - * @return list of the floatingip - */ - private function listFloatingIp(){ - try{ - $result = array(); - $l = $this->libClass->listFloatingIps(); - error_log(var_export($l, true), 0); - foreach ($l as $tmp) { - $result[] = $tmp; - } - - $this->app->setOutput("FloatingIp", $result); - }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); - } - } - - /** - * Create a new floating IP adress - * - * @param array $opt Options for the floating ip creation (floatingipo and floating network id are required, others are optionals) - * - * @return floatingip - */ - private function createFloatingIp(){ - $opt = $this->app->getPostParam("opt"); - - if(!isset($opt)){ - $this->app->setOutput("Error", "Incorrect parameter opt"); - } - try{ - $floatingip = $this->libClass->createFloatingIp($opt); - - if(!isset($floatingip)){ - $this->app->setOutput("Error", "Unknowing error during floating ip creation"); - }else{ - $this->app->setOutput("FloatingIp", $floatingip); - } - }catch(BadResponseError $e){ - echo $e."
"; - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - echo $e."
"; - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - echo $e."
"; - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - echo $e."
"; - $this->app->getErrorInstance()->NotImplementedHandler($e); - }catch(Exception $e){ - echo $e->getMessage()."
"; - $this->app->getErrorInstance()->OtherException($e); - } - } - - - /** - * Show floatingip details - * - * @param String id the id of the floatingip - * - * @return floatingip details - */ - private function getFloatingIp(){ - $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->listFloatingIps(); - foreach ($l as $tmp) { - $res[] = $tmp; - } - - // Verification if id exists - $result = null; - foreach ($res as $f) { - if(strcmp($res['id'], $id)){ - $result = $f; - - } - } - - if(!isset($result)){ // If id doesn't exists - $this->app->setOutput("Error", "Unknow id"); - }else{ // If id exists - $res = $this->libClass->getFloatingIp($id); - $this->app->setOutput("FloatingIp", $res); - } - - }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 floating ip - * - * @param id the id of the floatingip to update - * - * @return Image - */ - private function updateFloatingIp(){ - $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->listFloatingIps(); - foreach ($l as $tmp) { - $res[] = $tmp; - } - - // Verification if id exists - $result = null; - foreach ($res as $f) { - if(strcmp($res['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); - } - } - - /** - * Delete a floating ip - * - * @param string floatingip_id the floating-ip id to delete - * - * @return void - */ - private function deleteFloatingIp(){ - $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->listFloatingIps(); - foreach ($l as $tmp) { - $res[] = $tmp; - } - - // Verification if id exists - $result = null; - foreach ($res as $f) { - if(strcmp($res['id'], $id)){ - $result = $f; - - } - } - - if(!isset($result)){ // If id doesn't exists - $this->app->setOutput("Error", "Unknowing floatingip id"); - }else{ - $result->delete(); - } - }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); - } - } - - - /** - * Retrieve a floating ip - * - * @param string floatingip_id the floating-ip id to retrieve - * - * @return void - */ - private function retrieveFloatingIp(){ - $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->listFloatingIps(); - foreach ($l as $tmp) { - $res[] = $tmp; - } - - // Verification if id exists - $result = null; - foreach ($res as $f) { - if(strcmp($res['id'], $id)){ - $result = $f; - - } - } - - if(!isset($result)){ // If id doesn't exists - $this->app->setOutput("Error", "Unknowing floatingip id"); - }else{ - $result->retrieve(); - } - }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); - } - } -} diff --git a/server/core/NetworkLayer3.php b/server/core/NetworkLayer3.php new file mode 100755 index 0000000..28d27b4 --- /dev/null +++ b/server/core/NetworkLayer3.php @@ -0,0 +1,326 @@ +app->setOutput("Error", "Incorrect parameter app"); + } + $this->app = $app; + $this->libClass = $app->getLibClass("NetworkLayer3"); + } + + + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + $this->{$action.""}(); + } + + + /** + * List floatingip + * + * @return list of the floatingip + */ + private function listFloatingIp(){ + try{ + $result = array(); + $l = $this->libClass->listFloatingIps(); + error_log(var_export($l, true), 0); + foreach ($l as $tmp) { + $result[] = $tmp; + } + + $this->app->setOutput("NetworkLayer3", $result); + }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); + } + } + + /** + * Create a new floating IP adress + * + * @param array $opt Options for the floating ip creation (floatingipo and floating network id are required, others are optionals) + * + * @return floatingip + */ + private function createFloatingIp(){ + $opt = $this->app->getPostParam("opt"); + + if(!isset($opt)){ + $this->app->setOutput("Error", "Incorrect parameter opt"); + } + try{ + $floatingip = $this->libClass->createFloatingIp($opt); + + if(!isset($floatingip)){ + $this->app->setOutput("Error", "Unknowing error during floating ip creation"); + }else{ + $this->app->setOutput("NetworkLayer3", $floatingip); + } + }catch(BadResponseError $e){ + echo $e."
"; + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + echo $e."
"; + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + echo $e."
"; + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + echo $e."
"; + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + echo $e->getMessage()."
"; + $this->app->getErrorInstance()->OtherException($e); + } + } + + + /** + * Show floatingip details + * + * @param String id the id of the floatingip + * + * @return floatingip details + */ + private function getFloatingIp(){ + $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->listFloatingIps(); + foreach ($l as $tmp) { + $res[] = $tmp; + } + + // Verification if id exists + $result = null; + foreach ($res as $f) { + if(strcmp($res['id'], $id)){ + $result = $f; + + } + } + + if(!isset($result)){ // If id doesn't exists + $this->app->setOutput("Error", "Unknow id"); + }else{ // If id exists + $res = $this->libClass->getFloatingIp($id); + $this->app->setOutput("NetworkLayer3", $res); + } + + }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 floating ip + * + * @param id the id of the floatingip to update + * + * @return Image + */ + private function updateFloatingIp(){ + $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->listFloatingIps(); + foreach ($l as $tmp) { + $res[] = $tmp; + } + + // Verification if id exists + $result = null; + foreach ($res as $f) { + if(strcmp($res['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); + } + } + + /** + * Delete a floating ip + * + * @param string floatingip_id the floating-ip id to delete + * + * @return void + */ + private function deleteFloatingIp(){ + $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->listFloatingIps(); + foreach ($l as $tmp) { + $res[] = $tmp; + } + + // Verification if id exists + $result = null; + foreach ($res as $f) { + if(strcmp($res['id'], $id)){ + $result = $f; + + } + } + + if(!isset($result)){ // If id doesn't exists + $this->app->setOutput("Error", "Unknowing floatingip id"); + }else{ + $result->delete(); + } + }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); + } + } + + + /** + * Retrieve a floating ip + * + * @param string floatingip_id the floating-ip id to retrieve + * + * @return void + */ + private function retrieveFloatingIp(){ + $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->listFloatingIps(); + foreach ($l as $tmp) { + $res[] = $tmp; + } + + // Verification if id exists + $result = null; + foreach ($res as $f) { + if(strcmp($res['id'], $id)){ + $result = $f; + + } + } + + if(!isset($result)){ // If id doesn't exists + $this->app->setOutput("Error", "Unknowing floatingip id"); + }else{ + $result->retrieve(); + } + }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); + } + } +} diff --git a/server/index.php b/server/index.php index ac66c95..53a24c4 100755 --- a/server/index.php +++ b/server/index.php @@ -53,9 +53,9 @@ $App->show(); break; - case "floatingip": - include_once("core/FloatingIp.php"); - $computeObject = new floatingIp($App); + case "networkLayer3": + include_once("core/NetworkLayer3.php"); + $computeObject = new networkLayer3($App); $computeObject->action($action); $App->show(); break; -- cgit v1.2.3