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/core/App.php | 2 +- server/core/Automating.php | 5 +- server/core/FloatingIp.php | 326 ------------------------------------------ server/core/NetworkLayer3.php | 326 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 330 insertions(+), 329 deletions(-) delete mode 100755 server/core/FloatingIp.php create mode 100755 server/core/NetworkLayer3.php (limited to 'server/core') 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); + } + } +} -- cgit v1.2.3