add router functions
This commit is contained in:
parent
3f6af0b644
commit
7e5b9f3a72
2 changed files with 278 additions and 15 deletions
|
@ -89,7 +89,7 @@ class networkLayer3 {
|
|||
/**
|
||||
* 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)
|
||||
* @param array $opt Options for the floating ip creation (floatingNetworkId is required)
|
||||
*
|
||||
* @return floatingip
|
||||
*/
|
||||
|
@ -108,19 +108,14 @@ class networkLayer3 {
|
|||
$this->app->setOutput("NetworkLayer3", $floatingip);
|
||||
}
|
||||
}catch(BadResponseError $e){
|
||||
echo $e."</br>";
|
||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||
}catch(UserInputError $e){
|
||||
echo $e."</br>";
|
||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||
}catch(BaseError $e){
|
||||
echo $e."</br>";
|
||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||
}catch(NotImplementedError $e){
|
||||
echo $e."</br>";
|
||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||
}catch(Exception $e){
|
||||
echo $e->getMessage()."</br>";
|
||||
$this->app->getErrorInstance()->OtherException($e);
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +145,7 @@ class networkLayer3 {
|
|||
// Verification if id exists
|
||||
$result = null;
|
||||
foreach ($res as $f) {
|
||||
if(strcmp($res['id'], $id)){
|
||||
if(strcmp($f->id, $id)){
|
||||
$result = $f;
|
||||
|
||||
}
|
||||
|
@ -162,7 +157,6 @@ class networkLayer3 {
|
|||
$res = $this->libClass->getFloatingIp($id);
|
||||
$this->app->setOutput("NetworkLayer3", $res);
|
||||
}
|
||||
|
||||
}catch(BadResponseError $e){
|
||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||
}catch(UserInputError $e){
|
||||
|
@ -181,7 +175,7 @@ class networkLayer3 {
|
|||
*
|
||||
* @param id the id of the floatingip to update
|
||||
*
|
||||
* @return Image
|
||||
* @return void
|
||||
*/
|
||||
private function updateFloatingIp(){
|
||||
$id = $this->app->getPostParam("id");
|
||||
|
@ -201,7 +195,7 @@ class networkLayer3 {
|
|||
// Verification if id exists
|
||||
$result = null;
|
||||
foreach ($res as $f) {
|
||||
if(strcmp($res['id'], $id)){
|
||||
if(strcmp($f->id, $id)){
|
||||
$result = $f;
|
||||
|
||||
}
|
||||
|
@ -212,8 +206,6 @@ class networkLayer3 {
|
|||
}else{
|
||||
$result->update();
|
||||
}
|
||||
|
||||
|
||||
}catch(BadResponseError $e){
|
||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||
}catch(UserInputError $e){
|
||||
|
@ -251,7 +243,7 @@ class networkLayer3 {
|
|||
// Verification if id exists
|
||||
$result = null;
|
||||
foreach ($res as $f) {
|
||||
if(strcmp($res['id'], $id)){
|
||||
if(strcmp($f->id, $id)){
|
||||
$result = $f;
|
||||
|
||||
}
|
||||
|
@ -300,7 +292,7 @@ class networkLayer3 {
|
|||
// Verification if id exists
|
||||
$result = null;
|
||||
foreach ($res as $f) {
|
||||
if(strcmp($res['id'], $id)){
|
||||
if(strcmp($f->id, $id)){
|
||||
$result = $f;
|
||||
|
||||
}
|
||||
|
@ -323,4 +315,217 @@ class networkLayer3 {
|
|||
$this->app->getErrorInstance()->OtherException($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new router
|
||||
*
|
||||
* @param array $opt Options for the new router
|
||||
* externalGatewayInfo[] required (only the param networkId in the tab)
|
||||
* adminStateUp (optionnal)
|
||||
* name (optionnal)
|
||||
*
|
||||
* @return router
|
||||
*/
|
||||
private function createRouter(){
|
||||
$opt = $this->app->getPostParam("opt");
|
||||
|
||||
if(!isset($opt)){
|
||||
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||
}
|
||||
try{
|
||||
$router = $this->libClass->createRouter($opt);
|
||||
|
||||
if(!isset($router)){
|
||||
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
|
||||
}else{
|
||||
$this->app->setOutput("NetworkLayer3", $router);
|
||||
}
|
||||
}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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List routers
|
||||
*
|
||||
* @return list of the routers
|
||||
*/
|
||||
private function listRouters(){
|
||||
try{
|
||||
$result = array();
|
||||
$l = $this->libClass->listRouters();
|
||||
foreach ($l as $tmp) {
|
||||
$result[] = $tmp;
|
||||
}
|
||||
|
||||
$this->app->setOutput("NetworkLayer3", $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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show router details
|
||||
*
|
||||
* @param String id the id of the router
|
||||
*
|
||||
* @return router details
|
||||
*/
|
||||
private function getRouter(){
|
||||
$id = $this->app->getPostParam("id");
|
||||
if(!isset($id)){
|
||||
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||
}
|
||||
try{
|
||||
// List of routers
|
||||
$res = array();
|
||||
$l = $this->libClass->listRouters();
|
||||
foreach ($l as $tmp) {
|
||||
$res[] = $tmp;
|
||||
}
|
||||
|
||||
// Verification if id exists
|
||||
$result = null;
|
||||
foreach ($res as $f) {
|
||||
if(strcmp($f->id, $id)){
|
||||
$result = $f;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($result)){ // If id doesn't exists
|
||||
$this->app->setOutput("Error", "Unknow id");
|
||||
}else{ // If id exists
|
||||
$res = $this->libClass->getRouter($id);
|
||||
$this->app->setOutput("NetworkLayer3", $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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete a router
|
||||
*
|
||||
* @param string router the router to delete
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function deleteRouter(){
|
||||
$id = $this->app->getPostParam("id");
|
||||
|
||||
if(!isset($id)){
|
||||
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||
}
|
||||
try{
|
||||
// List of routers
|
||||
$res = array();
|
||||
$l = $this->libClass->listRouters();
|
||||
foreach ($l as $tmp) {
|
||||
$res[] = $tmp;
|
||||
}
|
||||
|
||||
// Verification if id exists
|
||||
$result = null;
|
||||
foreach ($res as $f) {
|
||||
if(strcmp($f->id, $id)){
|
||||
$result = $f;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($result)){ // If id doesn't exists
|
||||
$this->app->setOutput("Error", "Unknowing router id");
|
||||
}else{
|
||||
$result->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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update router
|
||||
*
|
||||
* @param id the id of the floatingip to update
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function updateRouter(){
|
||||
$id = $this->app->getPostParam("id");
|
||||
|
||||
if(!isset($id)){
|
||||
$this->app->setOutput("Error", "Incorrect parameter opt");
|
||||
}
|
||||
try{
|
||||
|
||||
// List of floating IPs
|
||||
$res = array();
|
||||
$l = $this->libClass->listRouters();
|
||||
foreach ($l as $tmp) {
|
||||
$res[] = $tmp;
|
||||
}
|
||||
|
||||
// Verification if id exists
|
||||
$result = null;
|
||||
foreach ($res as $f) {
|
||||
if(strcmp($f->id, $id)){
|
||||
$result = $f;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($result)){ // If id doesn't exists
|
||||
$this->app->setOutput("Error", "Unknowing floatingip id");
|
||||
}else{
|
||||
$result->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue