From c32933b362874d99207a4305d09b203dcbf20585 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 30 Mar 2016 18:30:44 +0200 Subject: [PATCH] debut automatisation --- server/core/Automating.php | 89 +++++++++----------------------------- 1 file changed, 20 insertions(+), 69 deletions(-) diff --git a/server/core/Automating.php b/server/core/Automating.php index 1eef72c..4a6a0b4 100644 --- a/server/core/Automating.php +++ b/server/core/Automating.php @@ -22,6 +22,7 @@ class automating implements Core{ protected $appImage; protected $appNetwork; protected $appIdentity; + protected $app; /** * Our library's app constructor for all server app objects @@ -38,6 +39,7 @@ class automating implements Core{ $this->appImage = $appImage; $this->appNetwork = $appNetwork; $this->appIdentity = $appIdentity; + $this->app = $app; } /** @@ -72,79 +74,28 @@ class automating implements Core{ appCompute->createServer(); } - /** - * Create a new image on a new server - * - * @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); - - $name = $this->app->getPostParam("name"); - $falvor_id = $this->app->getPostParam("falvor_id"); // Compris entre 1 et 5 (1=petit serveur, 5=gros serveur) + + private function createServer() + { + $imageName = $this->app->getPostParam('imageName'); + $serverName = $this->app->getPostParam('serverName'); + $flavor = $this->app->getPostParam('flavor'); - $opt = Array(); - $opt['name'] = $name; - $opt['visibility'] = 'public'; - $opt['minDisk'] = 100; // A VOIR - $opt['minRam'] = 128; // A VOIR - $opt['protected'] = false; + // Création image + $opt = Array(); + $opt['name'] = $imageName; + $this->app->setPostParam('opt' $opt); + $this->appImage->createImage(); + $image = json_decode($this->app->show(), true)["Images"]; - $this->app->setPostParam("opt", $opt); + // Création server + $this->app->setPostParam('name', $serverName); + $this->app->setPostParam('imageId', $image['id']); + $this->app->setPostParam('flavorId', $flavor); + $this->appNetwork->createServer(); - $image->action("createImage"); - $res = json_decode($this->app->show(), true)["Images"]; + // Ajout adresse IP public - - $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); - } - //$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); - }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); - } } }