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(); + } } + } ?> 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); + } + } +} diff --git a/server/core/Image.php b/server/core/Image.php index 59f7aed..334fce4 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 @@ -400,7 +396,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 @@ -437,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 @@ -521,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