From dcf0d8b2ba2547720215f7de55a747bf7ec47a0b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 23 Mar 2016 15:46:57 +0100 Subject: [PATCH] begining of automating tasks --- server/Test/imageTests.php | 18 +++++++- server/core/App.php | 6 +++ server/core/Automating.php | 95 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 server/core/Automating.php diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index d184d44..d86c664 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -1,8 +1,10 @@ action("listImage"); $im = $App->show(); $images = json_decode($im, true)["Images"]; -$recup; echo "Images présentes :"; echo "
"; @@ -33,9 +34,22 @@ foreach($images as $i){ //echo $recup['id']; } echo "
"; -echo "Erreur capturée: "; + +echo "Flavors: "; echo "
"; +$compute->action("listFlavors"); +$flavors = json_decode($App->show(), true)["Flavors"]; + +foreach($flavors as $f){ + echo "Id=".$f['id'].", "; + echo "name=".$f['name'].", "; + echo "ram=".$f['ram'].", "; + echo "disk=".$f['disk'].", "; + echo "vcpus=".$f['vcpus']; + echo "
"; + } + /* $App->setPostParam('id', 354); $err = $image->action("deleteImage"); diff --git a/server/core/App.php b/server/core/App.php index 6970e5f..10813bd 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -116,6 +116,12 @@ class App{ return $this->postParams[$name]; } + + public function setPostParam($name, $value){ + + $this->postParams[$name]= $value; + + } public function setOutput($key, $out){ 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