From 94629aeaf523f391f09ef18c1b2ca639e0b02d08 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Tue, 19 Apr 2016 23:57:03 +0200 Subject: [PATCH] tentative ip publique --- server/Test/automatingTests.php | 65 +++++++++++++++++++++++++++++++-- server/core/FloatingIp.php | 51 +++++++++++++++++++++++++- server/core/Network.php | 2 +- 3 files changed, 111 insertions(+), 7 deletions(-) diff --git a/server/Test/automatingTests.php b/server/Test/automatingTests.php index 8715464..078f86b 100755 --- a/server/Test/automatingTests.php +++ b/server/Test/automatingTests.php @@ -2,27 +2,84 @@ include('InitTest.php'); include_once("../core/Image.php"); include_once("../core/Compute.php"); -//include_once("../core/Network.php"); +include_once("../core/Network.php"); //include_once("../core/Automating.php"); include_once("../core/FloatingIp.php"); $image = new Image($App); $compute = new Compute($App); -//$network = new Network($App); +$network = new Network($App); $floatingIp = new FloatingIp($App); //$automating = new Automating($App); // Liste des serveurs +echo "Liste des serveurs :
"; $compute->action("listServers"); $servers = json_decode($App->show(), true)["Servers"]; +$id = null; foreach($servers as $server){ - echo $server['name']." ".$server['id']."
"; + echo $server['name']." ".$server['id']." ".$server['ipv4']."
"; + if(strcmp($server['name'], "bob")){ + $id = $server['id']; + } } +echo "
"; + +/* +// Liste des ports +echo "Liste des ports :
"; +$network->action("listPorts"); +$ports = json_decode($App->show(), true)["Network"]; +foreach ($ports as $p) { + echo $p["fixedIps"]."
"; +} +*/ + // liste des floatingip +echo "Liste des floatingip :
"; +$floatingIp->action("listFloatingIp"); +$listFloatingIp = json_decode($App->show(), true)["FloatingIp"]; +$ip = null; +foreach ($listFloatingIp as $floatIp){ + echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
"; + $ip = $floatIp; +} + +echo "
"; + +// Création d'une ip flotante +$opt = array(); +$opt['floatingNetworkId'] = $id; +$opt['floatingip'] = $ip; +//$opt['tenantId'] = "fbf5f920a7954b61b352bc09ce5ae803 "; +//$opt['fixedIpAddress'] = "10.0.0.52"; +//$opt['floatingIpAddress'] = "148.60.11.116"; +//$opt['portId'] = "10.0.0.52"; + +$App->setPostParam('opt', $opt); +$floatingIp->action("createFloatingIp"); +$float = json_decode($App->show(), true)["FloatingIp"]; +if(!isset($float)){ + echo "Erreur pendant la création
"; +} +else{ + foreach ($float as $f) { + echo $f." "; + } + echo "
"; +} + + +echo "
"; + +// liste des floatingip +echo "Liste des floatingip :
"; $floatingIp->action("listFloatingIp"); $listFloatingIp = json_decode($App->show(), true)["FloatingIp"]; foreach ($listFloatingIp as $floatIp){ - echo "IP : ".$floatIp['floating_ip_address']." et ID: ".$floatIp['id']." ".$floatIp["status"]."
"; + echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."
"; } + + ?> \ No newline at end of file diff --git a/server/core/FloatingIp.php b/server/core/FloatingIp.php index f26c3fb..528ab4f 100755 --- a/server/core/FloatingIp.php +++ b/server/core/FloatingIp.php @@ -68,7 +68,6 @@ class floatingIp { $result = array(); $l = $this->libClass->listFloatingIps(); error_log(var_export($l, true), 0); - echo 'toto'; foreach ($l as $tmp) { $result[] = $tmp; } @@ -101,13 +100,61 @@ class floatingIp { $this->app->setOutput("Error", "Incorrect parameter opt"); } try{ - $floatingip = $this->libClass->create($opt); + $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){ diff --git a/server/core/Network.php b/server/core/Network.php index 9564f06..3e5e2ca 100755 --- a/server/core/Network.php +++ b/server/core/Network.php @@ -40,7 +40,7 @@ class network{ public function __construct($app){ $this->app = $app; - $this->libClass = $app->getLibClass("network"); + $this->libClass = $app->getLibClass("Network"); }