From aa26e5f959b0b38fa43035a700cc72b5ac85e7a3 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 17 Apr 2016 11:44:32 +0200 Subject: [PATCH 1/3] modif upload --- server/core/Image.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/server/core/Image.php b/server/core/Image.php index c595135..fdf4e3a 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -224,7 +224,6 @@ class image implements Core{ } else{ try{ - //vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error @@ -276,8 +275,6 @@ class image implements Core{ * @return void */ private function deleteImage(){ - // si protected = true, demander de le mettre a false - // vérifier existence image $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); @@ -357,7 +354,6 @@ class image implements Core{ else { try{ - // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error @@ -389,8 +385,9 @@ class image implements Core{ private function uploadImage(){ $id = $this->app->getPostParam("id"); $file_name = $this->app->getPostParam("file_name"); - - + $file = $this->app->getPostParam("file"); + error_log(print_r($file, true), 0); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } @@ -399,13 +396,12 @@ class image implements Core{ } else{ try{ - // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $stream = \GuzzleHttp\Psr7\stream_for($file); $image->uploadData($stream); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -436,7 +432,6 @@ class image implements Core{ } else{ try{ - // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error @@ -520,7 +515,6 @@ class image implements Core{ } else{ try{ - // vérifier existence image $service = $this->libClass; $image = $service->getImage($image_id); if($image == null){ // if the image don't exists -> error From 9e7eb6774b823c1716ec14476ac8e53d758143ab Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Mon, 18 Apr 2016 17:20:27 +0200 Subject: [PATCH 2/3] begining of floating ip --- server/Test/AppTestClass.php | 6 ++ server/core/FloatingIp.php | 195 +++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 server/core/FloatingIp.php diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index a663514..d2f71e7 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -118,6 +118,12 @@ class AppTest{ return $this->errorClass; } + + public function getOutput($key){ + + return $this->output[$key]; + + } } diff --git a/server/core/FloatingIp.php b/server/core/FloatingIp.php new file mode 100644 index 0000000..72ae836 --- /dev/null +++ b/server/core/FloatingIp.php @@ -0,0 +1,195 @@ +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.""}(); + } + + /** + * 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->create($opt); + if(!isset){ + $this->app->setOutput("Error", "Unknowing error during floating ip creation"); + } + else{ + $this->app->setOutput("FloatingIp", $floatingip); + } + }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{ + $floatingip = null; //obtenir ip + + $floatingip->update(); + + if(!isset){ + $this->app->setOutput("Error", "Unknowing error during floating ip creation"); + } + }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{ + $floatingip = null; //obtenir ip + + $floatingip->delete(); + + if(!isset){ + $this->app->setOutput("Error", "Unknowing error during floating ip creation"); + } + }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{ + $floatingip = null; //obtenir ip + + $floatingip->retrieve(); + + if(!isset){ + $this->app->setOutput("Error", "Unknowing error during floating ip creation"); + } + }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); + } + } +} From e1b15c38d7f3bd158d477537bb26256baa7565a8 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Mon, 18 Apr 2016 17:38:25 +0200 Subject: [PATCH 3/3] begining of automating --- server/Test/AppTestClass.php | 6 --- server/core/Automating.php | 75 ++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index d2f71e7..a663514 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -118,12 +118,6 @@ class AppTest{ return $this->errorClass; } - - public function getOutput($key){ - - return $this->output[$key]; - - } } diff --git a/server/core/Automating.php b/server/core/Automating.php index 4a6a0b4..69a2773 100755 --- 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 $appFloatingIp; protected $app; /** @@ -39,6 +40,7 @@ class automating implements Core{ $this->appImage = $appImage; $this->appNetwork = $appNetwork; $this->appIdentity = $appIdentity; + $this->appFloatingIp = $appFloatingIp; $this->app = $app; } @@ -52,51 +54,56 @@ class automating implements Core{ public function action($action){ $this->{$action.""}(); } - - public function script() - { - $opt = Array(); - $opt['name'] = getPostParam('name'); - - appImage->setPostParam('opt' $opt); - appImage->createImage(); - - appNetwork->create_network(); - appnetwork->list_network_ids(); - appNetwork->create_subnet(); - - appCompute->listFlavors(); //to show all flavors with detail. - appCompute->listImages(); //to show all images with detail and to verify that the image was created successfully by the call above. - - appCompute->setPostParam("name","Test"); - appCompute->setPostParam("imageId","CREATED_ABOVE"); - appCompute->setPostParam("flavorId","1"); - appCompute->createServer(); - - } + /** + * create a new server and associate a public ip + * + * @param String $imageName name of the new image + * @param String $serverName name ofthe new server + * @param String $flavor kind of server + * + * @return void + */ private function createServer() { $imageName = $this->app->getPostParam('imageName'); $serverName = $this->app->getPostParam('serverName'); $flavor = $this->app->getPostParam('flavor'); - // Création image - $opt = Array(); - $opt['name'] = $imageName; - $this->app->setPostParam('opt' $opt); - $this->appImage->createImage(); - $image = json_decode($this->app->show(), true)["Images"]; + if(!isset($imageName)){ + $this->app->setOutput("Error", "Incorrect imageName parameter"); + } + else if(!isset($serverName)){ + $this->app->setOutput("Error", "Incorrect serverName parameter"); + } + else if(!isset($flavor)){ + $this->app->setOutput("Error", "Incorrect flavor parameter"); + } + else{ + // Création image + $opt = array(); + $opt['name'] = $imageName; + $this->appImage->setPostParam('opt' $opt); + $this->appImage->createImage(); + $image = json_decode($this->app->show(), true)["Images"]; - // Création server - $this->app->setPostParam('name', $serverName); - $this->app->setPostParam('imageId', $image['id']); - $this->app->setPostParam('flavorId', $flavor); - $this->appNetwork->createServer(); + // Création server + $this->appCompute->setPostParam('name', $serverName); + $this->appCompute->setPostParam('imageId', $image['id']); + $this->appCompute->setPostParam('flavorId', $flavor); + $this->appCompute->createServer(); + $server = json_decode($this->app->show(), true)["Compute"]; - // Ajout adresse IP public + // Ajout adresse IP public + $optIp = array(); + $opt['floatingip'] = null; //new floatingip(); ??? + $opt['floating_network_id'] = $server['id']; + $this->appFloatingIp->setPostParam('opt', $optIp); + $this->appFloatingIp->create(); + } } + } ?>