From dcf0d8b2ba2547720215f7de55a747bf7ec47a0b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 23 Mar 2016 15:46:57 +0100 Subject: begining of automating tasks --- server/core/Automating.php | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 server/core/Automating.php (limited to 'server/core/Automating.php') diff --git a/server/core/Automating.php b/server/core/Automating.php new file mode 100644 index 0000000..2665541 --- /dev/null +++ b/server/core/Automating.php @@ -0,0 +1,95 @@ +app->setOutput("Error", "Incorrect parameter app"); + } + $this->app = $app; + $this->libClass = $app->getLibClass("Automating"); + } + + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + $this->{$action.""}(); + } + + + private function createImageOnNewServer(){ + try{ + $image = new Image($this->app); + $compute = new Compute($this->app); + + $name = $this->app->getPostParam("name"); + $falvor_id = $this->app->getPostParam("falvor_id"); // Compris entre 1 et 5 (1=petit serveur, 5=gros serveur) + + $opt = Array(); + $opt['name'] = $name; + $opt['visibility'] = 'public'; + $opt['minDisk'] = 100; // A VOIR + $opt['minRam'] = 128; // A VOIR + $opt['protected'] = false; + + $this->app->setPostParam("opt", $opt); + + $image->action("createImage"); + $res = json_decode($this->app->show(), true)["Images"]; + + + $this->app->setPostParam("name", $name); + $this->app->setPostParam("imageId", $res['id']); + $this->app->setPostParam("flavorId", $falvor_id); + + $compute->action("createServer"); + + }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); + } + } + + +} + +?> \ No newline at end of file -- cgit v1.2.3 From 19d84e2ae4c6710aac2236df4f135409ef519fc8 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 27 Mar 2016 19:40:36 +0200 Subject: Update commentaries --- server/core/Automating.php | 15 +++++++---- server/core/ErrorManagement.php | 55 ++++++++++++++++++++++++++++++++++++++--- server/core/Image.php | 4 +-- 3 files changed, 64 insertions(+), 10 deletions(-) (limited to 'server/core/Automating.php') diff --git a/server/core/Automating.php b/server/core/Automating.php index 2665541..065cf5e 100644 --- a/server/core/Automating.php +++ b/server/core/Automating.php @@ -1,11 +1,11 @@ {$action.""}(); } - + /** + * Create a new image on a new server + * + * @param $error the error triggered + * + * @return Image the new image created + */ private function createImageOnNewServer(){ try{ $image = new Image($this->app); @@ -87,9 +93,8 @@ class automating implements Core{ }catch(Exception $e){ $this->app->getErrorInstance()->OtherException($e); } + $this->app->setOutput("Auto", $res); } - - } ?> \ No newline at end of file diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index e7cb83e..be7080b 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -1,4 +1,13 @@ app = $args; } + /** + * Put an error message corresponding to a base error in the output + * + * @param $error the error triggered + * + * @return String BaseError message + */ public function BaseErrorHandler($error){ $this->app->setOutput("Error", "BaseError"); } + /** + * Put an error message corresponding to a bad response in function of the status code in the output + * + * @param $error the error triggered + * + * @return String Error message + */ public function BadResponseHandler($error){ $statusCode = $error->getResponse()->getStatusCode(); switch ($statusCode) { @@ -54,19 +83,39 @@ Class errorManagement{ } } + /** + * Put an error message corresponding to a not implemented yet error in the output + * + * @param $error the error triggered + * + * @return String internal error message + */ public function NotImplementedHandler($error){ $this->app->setOutput("Error", "Internal error (not implemented yet), please contact an administrator"); } + /** + * Put an error message corresponding to a user input error in the output + * + * @param $error the error triggered + * + * @return String User input error message + */ public function UserInputHandler($error){ $this->app->setOutput("Error", "UserInputError"); } + /** + * Put an error message corresponding to an other error in the output + * + * @param $error the error triggered + * + * @return String error message + */ public function OtherException($error){ $this->app->setOutput("Error", $error->getMessage()); } - } ?> diff --git a/server/core/Image.php b/server/core/Image.php index e9736a2..c595135 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -5,7 +5,7 @@ * @version 1.0 Initialisation of this file * @since 1.0 Core application's file * -* @author Yogg 'yogg at epsina . com' +* @author Evan Pisani 'yogg at epsina . com' * * @todo Complete the functions with errors detection and finish the descriptions */ @@ -19,7 +19,7 @@ include("CoreInterface.php"); /** * Image Class of the back-end application * -* ADD CLASS DESCRIPTION +* Management of images * */ class image implements Core{ -- cgit v1.2.3 From 804fa322d841d73ee7592885ec500dc94e91b9e6 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 27 Mar 2016 19:54:38 +0200 Subject: difficulties with automating --- server/core/Automating.php | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'server/core/Automating.php') diff --git a/server/core/Automating.php b/server/core/Automating.php index 065cf5e..7f2c654 100644 --- a/server/core/Automating.php +++ b/server/core/Automating.php @@ -51,12 +51,14 @@ class automating implements Core{ /** * Create a new image on a new server * - * @param $error the error triggered + * @param $name the name of the new image + * @param $falvor_id the id of the flavor it will be used to create the new server * * @return Image the new image created */ private function createImageOnNewServer(){ try{ + /* POURRI $image = new Image($this->app); $compute = new Compute($this->app); @@ -81,6 +83,32 @@ class automating implements Core{ $this->app->setPostParam("flavorId", $falvor_id); $compute->action("createServer"); + */ + }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("Auto", $res); + } + + + /** + * Create a new image on an existing server + * + * @param $name the name of the new image + * @param $server_id the id of the server + * + * @return Image the new image created + */ + private function createImageOnServer(){ + try{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -93,7 +121,6 @@ class automating implements Core{ }catch(Exception $e){ $this->app->getErrorInstance()->OtherException($e); } - $this->app->setOutput("Auto", $res); } } -- cgit v1.2.3