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.""}(); } /** * List floatingip * * @return list of the floatingip */ private function listFloatingIp(){ try{ $result = array(); $l = $this->libClass->listFloatingIps(); error_log(var_export($l, true), 0); foreach ($l as $tmp) { $result[] = $tmp; } $this->app->setOutput("FloatingIp", $result); }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); } } /** * 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->createFloatingIp($opt); echo 'YOLO'; if(!isset($floatingip)){ $this->app->setOutput("Error", "Unknowing error during floating ip creation"); } else{ $this->app->setOutput("FloatingIp", $floatingip); } }catch(BadResponseError $e){ echo $e."
"; $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ echo $e."
"; $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ echo $e."
"; $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ echo $e."
"; $this->app->getErrorInstance()->NotImplementedHandler($e); }catch(Exception $e){ echo $e->getMessage()."
"; $this->app->getErrorInstance()->OtherException($e); } } /** * Show floatingip details * * @param String id the id of the floatingip * * @return floatingip details */ private function getFloatingIp(){ $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter opt"); } try{ /*$l = $this->listFloatingIp(); $res = null; foreach ($l as $f) { if($f['id']==$id){ $res = $f; } } if(!isset($f)){ $this->app->setOutput("Error", "Unknow id"); } else{*/ $res = $this->libClass->getFloatingIp($id); $this->app->setOutput("FloatingIp", $res); //} }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{ $floatingips = listFloatingIps(); $floatingIp = null; foreach ($floatingips as $f) { if($f['id'] == $id){ $floatingIp = $f; } } if(!isset($floatingIp)){ $this->app->setOutput("Error", "Unknowing floatingip id"); } $floatingip->update(); }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{ $floatingips = listFloatingIps(); $floatingIp = null; foreach ($floatingips as $f) { if($f['id'] == $id){ $floatingIp = $f; } } if(!isset($floatingIp)){ $this->app->setOutput("Error", "Unknowing floatingip id"); } $floatingip->delete(); }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{ $floatingips = listFloatingIps(); $floatingIp = null; foreach ($floatingips as $f) { if($f['id'] == $id){ $floatingIp = $f; } } if(!isset($floatingIp)){ $this->app->setOutput("Error", "Unknowing floatingip id"); } $floatingip->retrieve(); }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); } } }