add router functions
This commit is contained in:
parent
3f6af0b644
commit
7e5b9f3a72
2 changed files with 278 additions and 15 deletions
|
@ -47,7 +47,7 @@ foreach ($listFloatingIp as $floatIp){
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
|
|
||||||
|
|
||||||
// Liste des floatingip
|
// get floatingip
|
||||||
echo "Get floatingip : </br>";
|
echo "Get floatingip : </br>";
|
||||||
$App->setPostParam('id', $id);
|
$App->setPostParam('id', $id);
|
||||||
$networkLayer3->action("getFloatingIp");
|
$networkLayer3->action("getFloatingIp");
|
||||||
|
@ -70,12 +70,14 @@ if(!isset($float)){
|
||||||
echo "</br>";
|
echo "</br>";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Suppression d'une ip flotante
|
// Suppression d'une ip flotante
|
||||||
$App->setPostParam('id', $id);
|
$App->setPostParam('id', $id);
|
||||||
$networkLayer3->action("deleteFloatingIp");
|
$networkLayer3->action("deleteFloatingIp");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Liste des floatingip
|
// Liste des floatingip
|
||||||
echo "Liste des floatingip : </br>";
|
echo "Liste des floatingip : </br>";
|
||||||
$networkLayer3->action("listFloatingIp");
|
$networkLayer3->action("listFloatingIp");
|
||||||
|
@ -83,6 +85,62 @@ $listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
|
||||||
foreach ($listFloatingIp as $floatIp){
|
foreach ($listFloatingIp as $floatIp){
|
||||||
echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."<br>";
|
echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."<br>";
|
||||||
}
|
}
|
||||||
|
echo "</br>";
|
||||||
|
|
||||||
|
|
||||||
|
// Liste des routeurs
|
||||||
|
echo "Liste des routeurs : </br>";
|
||||||
|
$networkLayer3->action("listRouters");
|
||||||
|
$listRouters = json_decode($App->show(), true)["NetworkLayer3"];
|
||||||
|
foreach ($listRouters as $router){
|
||||||
|
echo $router['name']." ".$router['id']."<br>";
|
||||||
|
if(strcmp($router['name'], "Test")){
|
||||||
|
$id = $router['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo "</br>";
|
||||||
|
|
||||||
|
|
||||||
|
// get floatingip
|
||||||
|
echo "Get router : </br>";
|
||||||
|
$App->setPostParam('id', $id);
|
||||||
|
$networkLayer3->action("getRouter");
|
||||||
|
$getRouter = json_decode($App->show(), true)["NetworkLayer3"];
|
||||||
|
echo $getRouter['id']."<br>";
|
||||||
|
echo "</br>";
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Création d'un routeur'
|
||||||
|
$opt = array();
|
||||||
|
$optGate = array();
|
||||||
|
$optGate['networkId'] = "251b4641-20ff-4a72-8549-1758788b51ce";
|
||||||
|
$opt['externalGatewayInfo'] = $optGate;
|
||||||
|
$opt['name'] = "Test";
|
||||||
|
$App->setPostParam('opt', $opt);
|
||||||
|
$networkLayer3->action("createRouter");
|
||||||
|
$r = json_decode($App->show(), true)["NetworkLayer3"];
|
||||||
|
if(!isset($r)){
|
||||||
|
echo "Erreur pendant la création</br>";
|
||||||
|
}
|
||||||
|
echo "</br>";
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Suppression d'un routeur
|
||||||
|
$App->setPostParam('id', $id);
|
||||||
|
$networkLayer3->action("deleteRouter");
|
||||||
|
echo "</br>";
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Liste des routeurs
|
||||||
|
echo "Liste des routeurs : </br>";
|
||||||
|
$networkLayer3->action("listRouters");
|
||||||
|
$listRouters = json_decode($App->show(), true)["NetworkLayer3"];
|
||||||
|
foreach ($listRouters as $router){
|
||||||
|
echo $router['name']." ".$router['id']."<br>";
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -89,7 +89,7 @@ class networkLayer3 {
|
||||||
/**
|
/**
|
||||||
* Create a new floating IP adress
|
* 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
|
* @return floatingip
|
||||||
*/
|
*/
|
||||||
|
@ -108,19 +108,14 @@ class networkLayer3 {
|
||||||
$this->app->setOutput("NetworkLayer3", $floatingip);
|
$this->app->setOutput("NetworkLayer3", $floatingip);
|
||||||
}
|
}
|
||||||
}catch(BadResponseError $e){
|
}catch(BadResponseError $e){
|
||||||
echo $e."</br>";
|
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
}catch(UserInputError $e){
|
||||||
echo $e."</br>";
|
|
||||||
$this->app->getErrorInstance()->UserInputHandler($e);
|
$this->app->getErrorInstance()->UserInputHandler($e);
|
||||||
}catch(BaseError $e){
|
}catch(BaseError $e){
|
||||||
echo $e."</br>";
|
|
||||||
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
$this->app->getErrorInstance()->BaseErrorHandler($e);
|
||||||
}catch(NotImplementedError $e){
|
}catch(NotImplementedError $e){
|
||||||
echo $e."</br>";
|
|
||||||
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
$this->app->getErrorInstance()->NotImplementedHandler($e);
|
||||||
}catch(Exception $e){
|
}catch(Exception $e){
|
||||||
echo $e->getMessage()."</br>";
|
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$this->app->getErrorInstance()->OtherException($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +145,7 @@ class networkLayer3 {
|
||||||
// Verification if id exists
|
// Verification if id exists
|
||||||
$result = null;
|
$result = null;
|
||||||
foreach ($res as $f) {
|
foreach ($res as $f) {
|
||||||
if(strcmp($res['id'], $id)){
|
if(strcmp($f->id, $id)){
|
||||||
$result = $f;
|
$result = $f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -162,7 +157,6 @@ class networkLayer3 {
|
||||||
$res = $this->libClass->getFloatingIp($id);
|
$res = $this->libClass->getFloatingIp($id);
|
||||||
$this->app->setOutput("NetworkLayer3", $res);
|
$this->app->setOutput("NetworkLayer3", $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(BadResponseError $e){
|
}catch(BadResponseError $e){
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
}catch(UserInputError $e){
|
||||||
|
@ -181,7 +175,7 @@ class networkLayer3 {
|
||||||
*
|
*
|
||||||
* @param id the id of the floatingip to update
|
* @param id the id of the floatingip to update
|
||||||
*
|
*
|
||||||
* @return Image
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function updateFloatingIp(){
|
private function updateFloatingIp(){
|
||||||
$id = $this->app->getPostParam("id");
|
$id = $this->app->getPostParam("id");
|
||||||
|
@ -201,7 +195,7 @@ class networkLayer3 {
|
||||||
// Verification if id exists
|
// Verification if id exists
|
||||||
$result = null;
|
$result = null;
|
||||||
foreach ($res as $f) {
|
foreach ($res as $f) {
|
||||||
if(strcmp($res['id'], $id)){
|
if(strcmp($f->id, $id)){
|
||||||
$result = $f;
|
$result = $f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -212,8 +206,6 @@ class networkLayer3 {
|
||||||
}else{
|
}else{
|
||||||
$result->update();
|
$result->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}catch(BadResponseError $e){
|
}catch(BadResponseError $e){
|
||||||
$this->app->getErrorInstance()->BadResponseHandler($e);
|
$this->app->getErrorInstance()->BadResponseHandler($e);
|
||||||
}catch(UserInputError $e){
|
}catch(UserInputError $e){
|
||||||
|
@ -251,7 +243,7 @@ class networkLayer3 {
|
||||||
// Verification if id exists
|
// Verification if id exists
|
||||||
$result = null;
|
$result = null;
|
||||||
foreach ($res as $f) {
|
foreach ($res as $f) {
|
||||||
if(strcmp($res['id'], $id)){
|
if(strcmp($f->id, $id)){
|
||||||
$result = $f;
|
$result = $f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -300,7 +292,7 @@ class networkLayer3 {
|
||||||
// Verification if id exists
|
// Verification if id exists
|
||||||
$result = null;
|
$result = null;
|
||||||
foreach ($res as $f) {
|
foreach ($res as $f) {
|
||||||
if(strcmp($res['id'], $id)){
|
if(strcmp($f->id, $id)){
|
||||||
$result = $f;
|
$result = $f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -323,4 +315,217 @@ class networkLayer3 {
|
||||||
$this->app->getErrorInstance()->OtherException($e);
|
$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
Reference in a new issue