diff options
| author | Yoggzo <yogg@epsina.com> | 2016-04-21 22:52:00 +0200 |
|---|---|---|
| committer | Yoggzo <yogg@epsina.com> | 2016-04-21 22:52:00 +0200 |
| commit | 7e5b9f3a729b676c4efcf40769ed1631bf9fc0ba (patch) | |
| tree | 53ba627b85c5c038ba330682a20610380c71ae16 | |
| parent | 3f6af0b6446725462362de94f09daf9a723b130d (diff) | |
add router functions
| -rw-r--r-- | server/Test/NetworkLayer3Tests.php | 60 | ||||
| -rwxr-xr-x | server/core/NetworkLayer3.php | 233 |
2 files changed, 278 insertions, 15 deletions
diff --git a/server/Test/NetworkLayer3Tests.php b/server/Test/NetworkLayer3Tests.php index b827a51..cb14e3a 100644 --- a/server/Test/NetworkLayer3Tests.php +++ b/server/Test/NetworkLayer3Tests.php @@ -47,7 +47,7 @@ foreach ($listFloatingIp as $floatIp){ echo "</br>"; -// Liste des floatingip +// get floatingip echo "Get floatingip : </br>"; $App->setPostParam('id', $id); $networkLayer3->action("getFloatingIp"); @@ -70,12 +70,14 @@ if(!isset($float)){ echo "</br>"; */ + /* // Suppression d'une ip flotante $App->setPostParam('id', $id); $networkLayer3->action("deleteFloatingIp"); */ + // Liste des floatingip echo "Liste des floatingip : </br>"; $networkLayer3->action("listFloatingIp"); @@ -83,6 +85,62 @@ $listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"]; foreach ($listFloatingIp as $floatIp){ echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."<br>"; } +echo "</br>"; + + +// Liste des routeurs +echo "Liste des routeurs : </br>"; +$networkLayer3->action("listRouters"); +$listRouters = json_decode($App->show(), true)["NetworkLayer3"]; +foreach ($listRouters as $router){ + echo $router['name']." ".$router['id']."<br>"; + if(strcmp($router['name'], "Test")){ + $id = $router['id']; + } +} +echo "</br>"; +// get floatingip +echo "Get router : </br>"; +$App->setPostParam('id', $id); +$networkLayer3->action("getRouter"); +$getRouter = json_decode($App->show(), true)["NetworkLayer3"]; +echo $getRouter['id']."<br>"; +echo "</br>"; + + +/* +// Création d'un routeur' +$opt = array(); +$optGate = array(); +$optGate['networkId'] = "251b4641-20ff-4a72-8549-1758788b51ce"; +$opt['externalGatewayInfo'] = $optGate; +$opt['name'] = "Test"; +$App->setPostParam('opt', $opt); +$networkLayer3->action("createRouter"); +$r = json_decode($App->show(), true)["NetworkLayer3"]; +if(!isset($r)){ + echo "Erreur pendant la création</br>"; +} +echo "</br>"; +*/ + + +/* +// Suppression d'un routeur +$App->setPostParam('id', $id); +$networkLayer3->action("deleteRouter"); +echo "</br>"; +*/ + + +// Liste des routeurs +echo "Liste des routeurs : </br>"; +$networkLayer3->action("listRouters"); +$listRouters = json_decode($App->show(), true)["NetworkLayer3"]; +foreach ($listRouters as $router){ + echo $router['name']." ".$router['id']."<br>"; +} + ?>
\ No newline at end of file diff --git a/server/core/NetworkLayer3.php b/server/core/NetworkLayer3.php index 28d27b4..30e8a78 100755 --- a/server/core/NetworkLayer3.php +++ b/server/core/NetworkLayer3.php @@ -89,7 +89,7 @@ class networkLayer3 { /** * 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) + * @param array $opt Options for the floating ip creation (floatingNetworkId is required) * * @return floatingip */ @@ -108,19 +108,14 @@ class networkLayer3 { $this->app->setOutput("NetworkLayer3", $floatingip); } }catch(BadResponseError $e){ - echo $e."</br>"; $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - echo $e."</br>"; $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - echo $e."</br>"; $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - echo $e."</br>"; $this->app->getErrorInstance()->NotImplementedHandler($e); }catch(Exception $e){ - echo $e->getMessage()."</br>"; $this->app->getErrorInstance()->OtherException($e); } } @@ -150,7 +145,7 @@ class networkLayer3 { // Verification if id exists $result = null; foreach ($res as $f) { - if(strcmp($res['id'], $id)){ + if(strcmp($f->id, $id)){ $result = $f; } @@ -162,7 +157,6 @@ class networkLayer3 { $res = $this->libClass->getFloatingIp($id); $this->app->setOutput("NetworkLayer3", $res); } - }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -181,7 +175,7 @@ class networkLayer3 { * * @param id the id of the floatingip to update * - * @return Image + * @return void */ private function updateFloatingIp(){ $id = $this->app->getPostParam("id"); @@ -201,7 +195,7 @@ class networkLayer3 { // Verification if id exists $result = null; foreach ($res as $f) { - if(strcmp($res['id'], $id)){ + if(strcmp($f->id, $id)){ $result = $f; } @@ -212,8 +206,6 @@ class networkLayer3 { }else{ $result->update(); } - - }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -251,7 +243,7 @@ class networkLayer3 { // Verification if id exists $result = null; foreach ($res as $f) { - if(strcmp($res['id'], $id)){ + if(strcmp($f->id, $id)){ $result = $f; } @@ -300,7 +292,7 @@ class networkLayer3 { // Verification if id exists $result = null; foreach ($res as $f) { - if(strcmp($res['id'], $id)){ + if(strcmp($f->id, $id)){ $result = $f; } @@ -323,4 +315,217 @@ class networkLayer3 { $this->app->getErrorInstance()->OtherException($e); } } + + + + /** + * Create a new router + * + * @param array $opt Options for the new router + * externalGatewayInfo[] required (only the param networkId in the tab) + * adminStateUp (optionnal) + * name (optionnal) + * + * @return router + */ + private function createRouter(){ + $opt = $this->app->getPostParam("opt"); + + if(!isset($opt)){ + $this->app->setOutput("Error", "Incorrect parameter opt"); + } + try{ + $router = $this->libClass->createRouter($opt); + + if(!isset($router)){ + $this->app->setOutput("Error", "Unknowing error during floating ip creation"); + }else{ + $this->app->setOutput("NetworkLayer3", $router); + } + }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); + } + } + + + /** + * List routers + * + * @return list of the routers + */ + private function listRouters(){ + try{ + $result = array(); + $l = $this->libClass->listRouters(); + 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); + } + } + + + /** + * Show router details + * + * @param String id the id of the router + * + * @return router details + */ + private function getRouter(){ + $id = $this->app->getPostParam("id"); + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter opt"); + } + try{ + // List of routers + $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", "Unknow id"); + }else{ // If id exists + $res = $this->libClass->getRouter($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); + } + } + + + /** + * Delete a router + * + * @param string router the router to delete + * + * @return void + */ + private function deleteRouter(){ + $id = $this->app->getPostParam("id"); + + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter opt"); + } + try{ + // List of routers + $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 router 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); + } + } + + + /** + * 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); + } + } } |
