Merge branch 'loic' into loic-image-edition

This commit is contained in:
Loic GUEGAN 2016-04-26 23:37:10 +02:00
commit a845b20ee9
14 changed files with 944 additions and 1409 deletions

View file

@ -63,6 +63,11 @@ class AppTest{
$opt = $this->tokenClass->getOptions($service); $opt = $this->tokenClass->getOptions($service);
return $this->openstack->networkingV2($opt); return $this->openstack->networkingV2($opt);
break; break;
case "NetworkLayer3":
if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
$opt = $this->tokenClass->getOptions('Network');
return $this->openstack->networkingV2ExtLayer3($opt);
break;
} }
} }

View file

@ -0,0 +1,146 @@
<?php
include('InitTest.php');
include_once("../core/Compute.php");
include_once("../core/Network.php");
include_once("../core/NetworkLayer3.php");
$compute = new Compute($App);
$network = new Network($App);
$networkLayer3 = new NetworkLayer3($App);
// Liste des serveurs
echo "Liste des serveurs : </br>";
$compute->action("listServers");
$servers = json_decode($App->show(), true)["Servers"];
$id = null;
foreach($servers as $server){
echo $server['name']." ".$server['id']." ".$server['ipv4']."<br>";
if(strcmp($server['name'], "bob")){
$id = $server['id'];
}
}
echo "</br>";
// Liste des networks
echo "Liste des network : </br>";
$network->action("list_network_ids");
$servers = json_decode($App->show(), true)["ListNetworkIds"];
$id = null;
foreach($servers as $server){
echo $server."<br>";
}
echo "</br>";
// Liste des floatingip
echo "Liste des floatingip : </br>";
$networkLayer3->action("listFloatingIp");
$listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
$id = null;
foreach ($listFloatingIp as $floatIp){
echo $floatIp['floatingIpAddress']." ".$floatIp['id']." ".$floatIp["status"]."<br>";
$id = $floatIp['id'];
}
echo "</br>";
// get floatingip
echo "Get floatingip : </br>";
$App->setPostParam('id', $id);
$networkLayer3->action("getFloatingIp");
$getFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
echo $getFloatingIp['id']."<br>";
echo "</br>";
/*
// Création d'une ip flotante
$opt = array();
$opt['floatingNetworkId'] = "251b4641-20ff-4a72-8549-1758788b51ce";
$App->setPostParam('opt', $opt);
$networkLayer3->action("createFloatingIp");
$float = json_decode($App->show(), true)["NetworkLayer3"];
if(!isset($float)){
echo "Erreur pendant la création</br>";
}
echo "</br>";
*/
/*
// Suppression d'une ip flotante
$App->setPostParam('id', $id);
$networkLayer3->action("deleteFloatingIp");
*/
// Liste des floatingip
echo "Liste des floatingip : </br>";
$networkLayer3->action("listFloatingIp");
$listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
foreach ($listFloatingIp as $floatIp){
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>";
}
?>

20
server/Test/automatingTests.php Executable file
View file

@ -0,0 +1,20 @@
<?php
include('InitTest.php');
include_once("../core/Automating.php");
$automating = new Automating($App);
//$id = // id du réseau
/*
// Création serveur avec ip publique
echo "Test création serveur avec ip publique : </br>";
$App->setPostParam('networkId', $id);
$App->setPostParam('imageName', "ImageTest");
$App->setPostParam('serverName', "ServerTest");
$App->setPostParam('flavor', 1);
$compute->action("createPublicServer");
$servers = json_decode($App->show(), true)["Automating"];
*/
?>

View file

@ -5,7 +5,7 @@
$config["modules_enabled"] = ""; $config["modules_enabled"] = "";
$config["urlAuth"] = "http://148.60.11.31:5000/v3"; $config["urlAuth"] = "http://148.60.11.31:5000/v3";
$config["tokenTime"] = 60 //miunte = 60 //miuntess $config["tokenTime"] = 60 //minute = 60
?> ?>

View file

@ -1,5 +1,4 @@
<?php <?php
include_once("core/Plugin_Api.php");
include_once("core/LibOverride/genTokenOptions.php"); include_once("core/LibOverride/genTokenOptions.php");
include_once("core/ErrorManagement.php"); include_once("core/ErrorManagement.php");
@ -11,7 +10,6 @@ use OpenCloud\Common\Error\UserInputError;
class App{ class App{
protected $openstack; protected $openstack;
protected $pluginsApi;
protected $postParams; protected $postParams;
protected $tokenClass; protected $tokenClass;
protected $tokenPost; protected $tokenPost;
@ -23,7 +21,6 @@ class App{
$this->tokenPost = NULL; $this->tokenPost = NULL;
$this->tokenClass = new genTokenOptions($args); $this->tokenClass = new genTokenOptions($args);
$this->openstack = new OpenStack\OpenStack(['authUrl' => $args["authUrl"]]); $this->openstack = new OpenStack\OpenStack(['authUrl' => $args["authUrl"]]);
$this->pluginsApi = plugin_api::getInstance();
$this->errorClass = new errorManagement($this); $this->errorClass = new errorManagement($this);
$this->output = array(); $this->output = array();
$this->postParams = $_POST; $this->postParams = $_POST;
@ -64,6 +61,11 @@ class App{
$opt = $this->tokenClass->getOptions($service); $opt = $this->tokenClass->getOptions($service);
return $this->openstack->computeV2($opt); return $this->openstack->computeV2($opt);
break; break;
case "NetworkLayer3":
if($this->tokenPost == NULL) $this->tokenClass->genNetworkToken();
$opt = $this->tokenClass->getOptions('Network');
return $this->openstack->networkingV2ExtLayer3($opt);
break;
} }
} }

View file

@ -10,19 +10,18 @@
* @todo Complete the functions with errors detection and finish the descriptions * @todo Complete the functions with errors detection and finish the descriptions
*/ */
include("CoreInterface.php");
include("Image.php"); include("Image.php");
include("Network.php"); include("Network.php");
include("Compute.php"); include("Compute.php");
include("NetworkLayer3.php");
class automating implements Core{ class automating{
/** @var App $app protected, contains the main app object */ /** @var App $app protected, contains the main app object */
protected $appCompute; protected $compute;
protected $appImage; protected $image;
protected $appNetwork; protected $network;
protected $appIdentity; protected $networkLayer3;
protected $appFloatingIp;
protected $app; protected $app;
/** /**
@ -33,15 +32,11 @@ class automating implements Core{
* @return * @return
*/ */
public function __construct($app){ public function __construct($app){
if(!isset($app)){
$this->app->setOutput("Error", "Parameter app missing.");
}
$this->appCompute = $appCompute;
$this->appImage = $appImage;
$this->appNetwork = $appNetwork;
$this->appIdentity = $appIdentity;
$this->appFloatingIp = $appFloatingIp;
$this->app = $app; $this->app = $app;
$compute = new Compute($app);
$image = new Image($app);
$network = new Network($app);
$networkLayer3 = new NetworkLayer3($app);
} }
/** /**
@ -58,14 +53,16 @@ class automating implements Core{
/** /**
* create a new server and associate a public ip * create a new server and associate a public ip
* *
* @param String $networkId the id of the network where the server will be created
* @param String $imageName name of the new image * @param String $imageName name of the new image
* @param String $serverName name ofthe new server * @param String $serverName name ofthe new server
* @param String $flavor kind of server * @param String $flavor kind of server
* *
* @return void * @return void
*/ */
private function createServer() private function createPublicServer()
{ {
$networkId = $this->app->getPostParam('networkId');
$imageName = $this->app->getPostParam('imageName'); $imageName = $this->app->getPostParam('imageName');
$serverName = $this->app->getPostParam('serverName'); $serverName = $this->app->getPostParam('serverName');
$flavor = $this->app->getPostParam('flavor'); $flavor = $this->app->getPostParam('flavor');
@ -83,27 +80,44 @@ class automating implements Core{
// Création image // Création image
$opt = array(); $opt = array();
$opt['name'] = $imageName; $opt['name'] = $imageName;
$this->appImage->setPostParam('opt' $opt); $image->setPostParam('opt', $opt);
$this->appImage->createImage(); $image->action("createImage");
$image = json_decode($this->app->show(), true)["Images"]; $image = json_decode($this->app->show(), true)["Images"];
// Création server // Création server
$this->appCompute->setPostParam('name', $serverName); $compute->setPostParam('name', $serverName);
$this->appCompute->setPostParam('imageId', $image['id']); $compute->setPostParam('imageId', $image['id']);
$this->appCompute->setPostParam('flavorId', $flavor); $compute->setPostParam('flavorId', $flavor);
$this->appCompute->createServer(); $compute->action("createServer");
$server = json_decode($this->app->show(), true)["Compute"]; $server = json_decode($this->app->show(), true)["Compute"];
// Ajout adresse IP public // liste des adresses ip publiques diponibles
$optIp = array(); $networkLayer3->action("listFloatingIp");
$opt['floatingip'] = null; //new floatingip(); ??? $listFloatingIp = json_decode($App->show(), true)["NetworkLayer3"];
$opt['floating_network_id'] = $server['id']; $ip = null;
$this->appFloatingIp->setPostParam('opt', $optIp); foreach ($listFloatingIp as $f) {
$this->appFloatingIp->create(); if(strcmp($f['status'], "DOWN")){
$ip = $f;
}
}
// Si pas d'ip publique disponible on en créé une
if(!isset($ip)){
// Ajout adresse IP public
$optIp = array();
$opt['floatingNetworkId'] = $networkId;
$floatingIp->setPostParam('opt', $optIp);
$networkLayer3->action("createFloatingIp");
$ip = json_decode($App->show(), true)["NetworkLayer3"];
}
// Association de l'ip publique au serveur
/*
* API non diponible pour le moment
*/
} }
} }
} }
?> ?>

View file

@ -1,195 +0,0 @@
<?php
/**
* File containing the FloatingIp Class.
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Evan Pisani 'yogg at epsina . com'
*
* @todo Complete the functions with errors detection and finish the descriptions
*/
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
include("CoreInterface.php");
/**
* Image Class of the back-end application
*
* Management of images
*
*/
class floatingIp implements Core{
/** @var App $app protected, contains the main app object */
protected $app;
/** @var OpenStack\Identity $libClass protected, contains the library Identity object */
protected $libClass;
/**
* Image constructor
*
* @param App $app the main app object
*
* @return Image
*/
public function __construct($app){
if(!isset($app)){
$this->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);
}
}
}

View file

@ -14,8 +14,6 @@ use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError; use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError; use OpenCloud\Common\Error\UserInputError;
include("CoreInterface.php");
/** /**
* Network Class of the back-end application * Network Class of the back-end application
* *
@ -42,7 +40,7 @@ class network{
public function __construct($app){ public function __construct($app){
$this->app = $app; $this->app = $app;
$this->libClass = $app->getLibClass("network"); $this->libClass = $app->getLibClass("Network");
} }
@ -73,24 +71,29 @@ class network{
{ {
$options = array(); $options = array();
// check the name if it is null // check the name if it is null
if (isset($this->app->getPostParam("name"))) $name = $this->app->getPostParam("name");
$adminStateUp = $this->app->getPostParam("adminStateUp");
$shared = $this->app->getPostParam("shared");
$tenantId = $this->app->getPostParam("tenantId");
if (isset($name))
{ {
$options['name'] = $this->app->getPostParam("name"); $options['name'] = $name;
} }
// check the adminStateUp if it is null // check the adminStateUp if it is null
if (isset($this->app->getPostParam("adminStateUp"))) if (isset($adminStateUp))
{ {
$options['adminStateUp'] = $this->app->getPostParam("adminStateUp"); $options['adminStateUp'] = $adminStateUp;
} }
// check the shared if it is null // check the shared if it is null
if (isset($this->app->getPostParam("shared"))) if (isset($shared))
{ {
$options['shared'] = $this->app->getPostParam("shared"); $options['shared'] = $shared;
} }
// check the tenantId if it is null // check the tenantId if it is null
if (isset($this->app->getPostParam("tenantId"))) if (isset($tenantId))
{ {
$options['tenantId'] = $this->app->getPostParam("tenantId"); $options['tenantId'] =$tenantId;
} }
try try
{ {
@ -115,7 +118,7 @@ class network{
} }
/** /**
* Create a new subnet * Create a new subnet
* *
@ -138,49 +141,61 @@ class network{
private function create_subnet() private function create_subnet()
{ $options = array(); { $options = array();
if (isset($this->app->getPostParam("networkId"))) $networkId = $this->app->getPostParam("networkId");
$ipVersion = $this->app->getPostParam("ipVersion");
$cidr = $this->app->getPostParam("cidr");
$tenantId = $this->app->getPostParam("tenantId");
$name = $this->app->getPostParam("name");
$gatewayIp = $this->app->getPostParam("gatewayIp");
$dnsNameservers = $this->app->getPostParam("dnsNameservers");
$allocationPools = $this->app->getPostParam("allocationPools");
$hostRoutes = $this->app->getPostParam("hostRoutes");
$enableDhcp = $this->app->getPostParam("enableDhcp");
$tenantId = $this->app->getPostParam("tenantId");
if (isset($networkId))
{ {
$options['networkId'] = $networkId; $options['networkId'] = $networkId;
} }
if (isset($this->app->getPostParam("ipVersion"))) if (isset($ipVersion))
{ {
$options['ipVersion'] = $this->app->getPostParam("ipVersion"); $options['ipVersion'] = $ipVersion;
} }
if (isset($this->app->getPostParam("cidr"))) if (isset($cidr))
{ {
$options['cidr'] = $this->app->getPostParam("cidr"); $options['cidr'] = $cidr;
} }
if (isset($this->app->getPostParam("tenantId"))) if (isset($tenantId))
{ {
$options['tenantId'] = $this->app->getPostParam("tenantId"); $options['tenantId'] = $tenantId;
} }
if (isset($this->app->getPostParam("name"))) if (isset($name))
{ {
$options['name'] = $$this->app->getPostParam("name"); $options['name'] = $name;
} }
if (isset($this->app->getPostParam("gatewayIp"))) if (isset($gatewayIp))
{ {
$options['gatewayIp'] = $this->app->getPostParam("gatewayIp"); $options['gatewayIp'] = $gatewayIp;
} }
if (isset($this->app->getPostParam("dnsNameservers"))) if (isset($dnsNameservers))
{ {
$options['dnsNameservers'] = $this->app->getPostParam("dnsNameservers"); $options['dnsNameservers'] = $dnsNameservers;
} }
if (isset($this->app->getPostParam("allocationPools"))) if (isset($allocationPools))
{ {
$options['allocationPools'] = $this->app->getPostParam("allocationPools"); $options['allocationPools'] = $allocationPools;
} }
if (isset($this->app->getPostParam("hostRoutes"))) if (isset($hostRoutes))
{ {
$options['hostRoutes'] = $this->app->getPostParam("hostRoutes"); $options['hostRoutes'] = $hostRoutes;
} }
if (isset($this->app->getPostParam("enableDhcp"))) if (isset($enableDhcp))
{ {
$options['enableDhcp'] = $this->app->getPostParam("enableDhcp"); $options['enableDhcp'] = $enableDhcp;
} }
if (isset($this->app->getPostParam("tenantId"))) if (isset($tenantId))
{ {
$options['tenantId'] = $this->app->getPostParam("tenantId"); $options['tenantId'] = $tenantId;
} }
try try
@ -333,17 +348,16 @@ class network{
* retrieve a specific network * retrieve a specific network
* @param networkId ID of network which we want to get * @param networkId ID of network which we want to get
* @return Network * @return Network
*/ */
retrieve a specific network
private function getNetwork() private function getNetwork()
{ {
$network=""; $network="";
try try
{ $newtork = $this->libClass->getNetwork($this->app->getPostParam("networkId")); {
$network->retrieve(); $networkId = $this->app->getPostParam("networkId");
$newtork = $this->libClass->getNetwork($networkId);
$network->retrieve();
} }
@ -372,7 +386,7 @@ class network{
* @param String netId ID of network which we want to get * @param String netId ID of network which we want to get
* @return Network * @return Network
*/ */
private function getNetwork($netId) private function getNetworkP($netId)
{ {
$network=""; $network="";
@ -414,10 +428,10 @@ class network{
$sbnet=""; $sbnet="";
try try
{ $subnet = $this->libClass->getSubnet($this->app->getPostParam("subnetId")); {
$subnetId = $this->app->getPostParam("subnetId");
$subnet = $this->libClass->getSubnet($subnetId);
$subnet->retrieve(); $subnet->retrieve();
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -444,7 +458,7 @@ class network{
* @param String subnetId ID of subnet which we want to get * @param String subnetId ID of subnet which we want to get
* @return subnet * @return subnet
*/ */
private function getSubnet($subnetId) private function getSubnetP($subnetId)
{ {
$subnet=""; $subnet="";
@ -490,21 +504,26 @@ class network{
private function updateNetwork() private function updateNetwork()
{ {
$options = array(); $options = array();
if(isset($this->app->getPostParam("name"))) $name = $this->app->getPostParam("name");
$shared = $this->app->getPostParam("shared");
$adminStateUp = $this->app->getPostParam("adminStateUp");
if(isset($name))
{ {
$options['name'] = $this->app->getPostParam("name"); $options['name'] = $name;
} }
if(isset($this->app->getPostParam("shared"))) if(isset($shared))
{ {
$options['shared'] = $this->app->getPostParam("shared"); $options['shared'] = $shared;
} }
if(isset($this->app->getPostParam("adminStateUp"))) if(isset($adminStateUp))
{ {
$options['adminStateUp'] = $this->app->getPostParam("adminStateUp"); $options['adminStateUp'] = $adminStateUp;
} }
try try
{ {
$network = getNetwork($this->app->getPostParam("networkId")); $networkId = $this->app->getPostParam("networkId");
$network = getNetworkP($networkId);
$network->update($options); $network->update($options);
} }
@ -548,26 +567,30 @@ class network{
private function updateSubnet() private function updateSubnet()
{ {
$options = array(); $options = array();
if(isset($this->app->getPostParam("name"))) $name = $this->app->getPostParam("name");
$networkId = $this->app->getPostParam("networkId");
$ipVersion = $this->app->getPostParam("ipVersion");
$cidr = $this->app->getPostParam("cidr");
if(isset($name))
{ {
$options['name'] = $this->app->getPostParam("name"); $options['name'] = $name;
} }
if(isset($this->app->getPostParam("networkId"))) if(isset($networkId))
{ {
$options['networkId'] = $this->app->getPostParam("networkId"); $options['networkId'] = $networkId;
} }
if(isset($this->app->getPostParam("ipVersion"))) if(isset($ipVersion))
{ {
$options['ipVersion'] = $this->app->getPostParam("ipVersion"); $options['ipVersion'] = $ipVersion;
} }
if(isset($this->app->getPostParam("cidr"))) if(isset($cidr))
{ {
$options['cidr'] = $this->app->getPostParam("cidr"); $options['cidr'] = $cidr;
} }
try try
{ {
$subnet = getSubnet($this->app->getPostParam("networkId")); $networkId = $this->app->getPostParam("networkId");
$subnet = getSubnetP($networkId);
$subnet->update($options); $subnet->update($options);
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -592,7 +615,6 @@ class network{
* Delete a network given * Delete a network given
* *
* @param String networkId ID if network which we want to delete * @param String networkId ID if network which we want to delete
* *
* *
* @return void * @return void
@ -601,8 +623,8 @@ class network{
{ {
try try
{ {
$networkId = $this->app->getPostParam("networkId");
$network = getNetwork($this->app->getPostParam("networkId")); $network = getNetworkP($networkId);
$network->delete(); $network->delete();
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -627,7 +649,6 @@ class network{
* Delete a subnet given * Delete a subnet given
* *
* @param String subnetId ID if network which we want to delete * @param String subnetId ID if network which we want to delete
* *
* *
* @return void * @return void
@ -636,7 +657,8 @@ class network{
{ {
try try
{ {
$subnet = getNetwork($this->app->getPostParam("subnetId")); $subnetId = $this->app->getPostParam("subnetId");
$subnet = getNetworkP($subnetId);
$subnet->delete(); $subnet->delete();
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -676,41 +698,51 @@ class network{
private function createPort() private function createPort()
{ {
$options = array(); $options = array();
if (isset($this->app->getPostParam("networkId"))) $networkId = $this->app->getPostParam("networkId");
$name = $this->app->getPostParam("name");
$adminStateUp = $this->app->getPostParam("adminStateUp");
$macAddress = $this->app->getPostParam("macAddress");
$fixedIps = $this->app->getPostParam("fixedIps");
$deviceId = $this->app->getPostParam("deviceId");
$deviceOwner = $this->app->getPostParam("deviceOwner");
$securityGroups = $this->app->getPostParam("securityGroups");
$tenantId = $this->app->getPostParam("tenantId");
if (isset($networkId))
{ {
$options['networkId'] = $this->app->getPostParam("networkId"); $options['networkId'] = $networkId;
} }
if (isset($this->app->getPostParam("name"))) if (isset($name))
{ {
$options['name'] = $this->app->getPostParam("name"); $options['name'] = $name;
} }
if (isset($this->app->getPostParam("adminStateUp"))) if (isset($adminStateUp))
{ {
$options['adminStateUp'] = $this->app->getPostParam("adminStateUp"); $options['adminStateUp'] = $adminStateUp;
} }
if (isset($this->app->getPostParam("macAddress"))) if (isset($macAddress))
{ {
$options['macAddress'] = $this->app->getPostParam("macAddress"); $options['macAddress'] = $macAddress;
} }
if (isset($this->app->getPostParam("fixedIps"))) if (isset($fixedIps))
{ {
$options['fixedIps'] = $this->app->getPostParam("fixedIps"); $options['fixedIps'] = $fixedIps;
} }
if (isset($this->app->getPostParam("deviceId"))) if (isset($deviceId))
{ {
$options['deviceId'] = $this->app->getPostParam("deviceId"); $options['deviceId'] = $deviceId;
} }
if (isset($this->app->getPostParam("deviceOwner"))) if (isset($deviceOwner))
{ {
$options['deviceOwner'] = $this->app->getPostParam("deviceOwner"); $options['deviceOwner'] = $deviceOwner;
} }
if (isset($this->app->getPostParam("securityGroups"))) if (isset($securityGroups))
{ {
$options['securityGroups'] = $this->app->getPostParam("securityGroups"); $options['securityGroups'] = $securityGroups;
} }
if (isset($this->app->getPostParam("tenantId"))) if (isset($tenantId))
{ {
$options['tenantId'] = $this->app->getPostParam("tenantId"); $options['tenantId'] = $tenantId;
} }
try try
{ {
@ -774,7 +806,8 @@ class network{
{ {
try try
{ {
$port = $this->libClass->getport($this->app->getPostParam("portId")); $portId = $this->app->getPostParam("portId");
$port = $this->libClass->getport($portId);
$this->app->setOutput("Port", $port); $this->app->setOutput("Port", $port);
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -803,7 +836,7 @@ class network{
* @return port * @return port
*/ */
private function getPort($portId) private function getPortP($portId)
{ {
try try
{ {
@ -848,46 +881,55 @@ class network{
private function updatePort() private function updatePort()
{ {
$options = array(); $options = array();
$networkId = $this->app->getPostParam("networkId");
if (isset($this->app->getPostParam("networkId"))) $name = $this->app->getPostParam("name");
$adminStateUp = $this->app->getPostParam("adminStateUp");
$macAddress = $this->app->getPostParam("macAddress");
$fixedIps = $this->app->getPostParam("fixedIps");
$deviceId = $this->app->getPostParam("deviceId");
$deviceOwner = $this->app->getPostParam("deviceOwner");
$securityGroups = $this->app->getPostParam("securityGroups");
$tenantId = $this->app->getPostParam("tenantId");
if (isset($networkId))
{ {
$options['networkId'] = $this->app->getPostParam("networkId"); $options['networkId'] = $networkId;
} }
if (isset($this->app->getPostParam("name"))) if (isset($name))
{ {
$options['name'] =$this->app->getPostParam("name"); $options['name'] = $name;
} }
if (isset($this->app->getPostParam("adminStateUp"))) if (isset($adminStateUp))
{ {
$options['adminStateUp'] =$this->app->getPostParam("adminStateUp"); $options['adminStateUp'] = $adminStateUp;
} }
if (isset($this->app->getPostParam("macAddress"))) if (isset($macAddress))
{ {
$options['macAddress'] = $this->app->getPostParam("macAddress"); $options['macAddress'] = $macAddress;
} }
if (isset($this->app->getPostParam("fixedIps"))) if (isset($fixedIps))
{ {
$options['fixedIps'] = $this->app->getPostParam("fixedIps"); $options['fixedIps'] = $fixedIps;
} }
if (isset($this->app->getPostParam("deviceId"))) if (isset($deviceId))
{ {
$options['deviceId'] = $this->app->getPostParam("deviceId"); $options['deviceId'] = $deviceId;
} }
if (isset($this->app->getPostParam("deviceOwner"))) if (isset($deviceOwner))
{ {
$options['deviceOwner'] = $this->app->getPostParam("deviceOwner"); $options['deviceOwner'] = $deviceOwner;
} }
if (isset($this->app->getPostParam("networkId"))) if (isset($securityGroups))
{ {
$options['securityGroups'] = $this->app->getPostParam("securityGroups"); $options['securityGroups'] = $securityGroups;
} }
if (isset($this->app->getPostParam("tenantId"))) if (isset($tenantId))
{ {
$options['tenantId'] = $this->app->getPostParam("tenantId"); $options['tenantId'] = $tenantId;
} }
try try
{ {
$port = getPort($this->app->getPostParam("networkId")); $port = getPortP($networkId);
$port->update($options); $port->update($options);
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -911,7 +953,6 @@ class network{
* Delete a port given * Delete a port given
* *
* @param String portId id of port which we wante to delete * @param String portId id of port which we wante to delete
* @return void * @return void
*/ */
private function deletePort() private function deletePort()
@ -919,7 +960,8 @@ class network{
try try
{ {
$port = getPort($this->app->getPostParam("portId")); $portId = $this->app->getPostParam("portId");
$port = getPortP($portId);
$port->delete(); $port->delete();
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -952,13 +994,16 @@ class network{
private function createSecurityGroup() private function createSecurityGroup()
{ {
$options = array(); $options = array();
if (isset($this->app->getPostParam("name"))) $name = $this->app->getPostParam("name");
$description = $this->app->getPostParam("description");
if (isset($name))
{ {
$options['name'] = $this->app->getPostParam("name"); $options['name'] = $name;
} }
if (isset($this->app->getPostParam("description"))) if (isset($description))
{ {
$options['description'] = $this->app->getPostParam("description"); $options['description'] = $description;
} }
try try
{ {
@ -1000,37 +1045,46 @@ class network{
private function createSecurityGroupRule() private function createSecurityGroupRule()
{ {
$options = array(); $options = array();
if (isset($this->app->getPostParam("securityGroupId"))) $securityGroupId = $this->app->getPostParam("securityGroupId");
$direction = $this->app->getPostParam("direction");
$ethertype = $this->app->getPostParam("ethertype");
$portRangeMin = $this->app->getPostParam("portRangeMin");
$portRangeMax = $this->app->getPostParam("portRangeMax");
$protocol = $this->app->getPostParam("protocol");
$remoteGroupId = $this->app->getPostParam("remoteGroupId");
$remoteIpPrefix = $this->app->getPostParam("remoteIpPrefix");
if (isset($securityGroupId))
{ {
$options['securityGroupId'] = $this->app->getPostParam("securityGroupId"); $options['securityGroupId'] = $securityGroupId;
} }
if (isset($this->app->getPostParam("direction"))) if (isset($direction))
{ {
$options['direction'] = $this->app->getPostParam("direction"); $options['direction'] = $direction;
} }
if (isset($this->app->getPostParam("ethertype"))) if (isset($ethertype))
{ {
$options['ethertype'] = $this->app->getPostParam("ethertype"); $options['ethertype'] = $ethertype;
} }
if (isset($this->app->getPostParam("portRangeMin"))) if (isset($portRangeMin))
{ {
$options['portRangeMin'] = $this->app->getPostParam("portRangeMin"); $options['portRangeMin'] = $portRangeMin;
} }
if (isset($this->app->getPostParam("portRangeMax"))) if (isset($portRangeMax))
{ {
$options['portRangeMax'] = $this->app->getPostParam("portRangeMax"); $options['portRangeMax'] = $portRangeMax;
} }
if (isset($this->app->getPostParam("protocol"))) if (isset($protocol))
{ {
$options['protocol'] = $this->app->getPostParam("protocol"); $options['protocol'] = $protocol;
} }
if (isset($this->app->getPostParam("remoteGroupId"))) if (isset($remoteGroupId))
{ {
$options['remoteGroupId'] = $this->app->getPostParam("remoteGroupId"); $options['remoteGroupId'] = $remoteGroupId;
} }
if (isset($this->app->getPostParam("remoteIpPrefix"))) if (isset($remoteIpPrefix))
{ {
$options['remoteIpPrefix'] = $this->app->getPostParam("remoteIpPrefix"); $options['remoteIpPrefix'] = $remoteIpPrefix;
} }
try try
{ {
@ -1128,7 +1182,8 @@ class network{
{ {
try try
{ {
$securityGroupe = $this->libClass->getSecurityGroupe($this->app->getPostParam("securityGroupeId")); $securityGroupId = $this->app->getPostParam("securityGroupeId");
$securityGroupe = $this->libClass->getSecurityGroupe($securityGroupId);
$this->app->setOutput("securityGroupe", $securityGroupe); $this->app->setOutput("securityGroupe", $securityGroupe);
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -1156,7 +1211,7 @@ class network{
* @param securityGroupeId ID of security Groupe which we want to get * @param securityGroupeId ID of security Groupe which we want to get
* @return securityGroupe * @return securityGroupe
*/ */
private function getSecurityGroupe($securityGroupeId) private function getSecurityGroupeP($securityGroupeId)
{ {
try try
{ {
@ -1187,11 +1242,11 @@ class network{
* @return void * @return void
*/ */
private function deleteSecurityGroupe() private function deleteSecurityGroupe()
{ {
try try
{ {
$securityGroupId = $this->app->getPostParam("securityGroupeId");
$securityGroupe = getSecurityGroupe($this->app->getPostParam("securityGroupeId")); $securityGroupe = getSecurityGroupeP($securityGroupId);
$securityGroupe->delete(); $securityGroupe->delete();
} }
catch(BadResponseError $e) catch(BadResponseError $e)
@ -1210,4 +1265,5 @@ class network{
{ {
$this->app->getErrorInstance->NotImplementedHandler($e); $this->app->getErrorInstance->NotImplementedHandler($e);
} }
} }
}

View file

@ -1,952 +0,0 @@
<?php
class network{
protected $app;
protected $libClass;
public function __construct($app){
$this->app = $app;
$this->libClass = $app->getLibClass("network");
}
public function action($action){
$this->{$action.""}();
}
public function create_network()
{
$options = array();
if (isset($this->app->getPostParam("name")))
{
$options['name'] = $this->app->getPostParam("name");
}
if (isset($this->app->getPostParam("adminStateUp")))
{
$options['adminStateUp'] = $this->app->getPostParam("adminStateUp");
}
if (isset($this->app->getPostParam("shared")))
{
$options['shared'] = $this->app->getPostParam("shared");
}
if (isset($this->app->getPostParam("tenantId")))
{
$options['tenantId'] = $this->app->getPostParam("tenantId");
}
try
{
$network = $this->libClass->createNetworks($options);
}
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);
}
}
public function create_subnet()
{ $options = array();
if (isset($this->app->getPostParam("networkId")))
{
$options['networkId'] = $networkId;
}
if (isset($this->app->getPostParam("ipVersion")))
{
$options['ipVersion'] = $this->app->getPostParam("ipVersion");
}
if (isset($this->app->getPostParam("cidr")))
{
$options['cidr'] = $this->app->getPostParam("cidr");
}
if (isset($this->app->getPostParam("tenantId")))
{
$options['tenantId'] = $this->app->getPostParam("tenantId");
}
if (isset($this->app->getPostParam("name")))
{
$options['name'] = $$this->app->getPostParam("name");
}
if (isset($this->app->getPostParam("gatewayIp")))
{
$options['gatewayIp'] = $this->app->getPostParam("gatewayIp");
}
if (isset($this->app->getPostParam("dnsNameservers")))
{
$options['dnsNameservers'] = $this->app->getPostParam("dnsNameservers");
}
if (isset($this->app->getPostParam("allocationPools")))
{
$options['allocationPools'] = $this->app->getPostParam("allocationPools");
}
if (isset($this->app->getPostParam("hostRoutes")))
{
$options['hostRoutes'] = $this->app->getPostParam("hostRoutes");
}
if (isset($this->app->getPostParam("enableDhcp")))
{
$options['enableDhcp'] = $this->app->getPostParam("enableDhcp");
}
if (isset($this->app->getPostParam("tenantId")))
{
$options['tenantId'] = $this->app->getPostParam("tenantId");
}
try
{
$subnet = $this->libClass->createSubnet($options);
}
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);
}
}
public function list_network_ids()
{
try
{
$ln = $this->libClass->listNetworks();
$list_ids = array();
foreach($ln as $n)
{
$list_ids[] = $n->id;
}
}
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);
}
$this->app->setOutput("ListNetworkIds", $list_ids);
}
public function list_network_names()
{
try
{
$ln = $this->libClass->listNetworks();
$list_names = array();
foreach($ln as $n)
{
$list_names[] = $n->name;
}
}
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);
}
$this->app->setOutput("ListNetworkNames", $list_names);
}
public function list_cidr()
{
try
{
$ls = $this->libClass->listSubnets();
$list_cidr = array();
foreach ($ls as $subnet)
{
$list_cidr[] = $subnet->cidr;
}
$this->app->setOutput("ListCidr", $list_cidr);
}
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);
}
}
public function getNetwork()
{
$network="";
try
{ $newtork = $this->libClass->getNetwork($this->app->getPostParam("networkId"));
$network->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);
}
$this->app->setOutput("Network", $network);
}
public function getNetwork($netId)
{
$network="";
try
{ $newtork = $this->libClass->getNetwork($netId);
$network->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);
}
return $network;
}
public function getSubnet()
{
$sbnet="";
try
{ $subnet = $this->libClass->getSubnet($this->app->getPostParam("subnetId"));
$subnet->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);
}
$this->app->setOutput("Subnet", subnet);
}
public function getSubnet($subnetId)
{
$subnet="";
try
{ $subnet = $this->libClass->getSubnet($subnetId);
$subnet->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);
}
return $subnet;
}
public function updateNetwork()
{
$options = array();
if(isset($this->app->getPostParam("name")))
{
$options['name'] = $this->app->getPostParam("name");
}
if(isset($this->app->getPostParam("shared")))
{
$options['shared'] = $this->app->getPostParam("shared");
}
if(isset($this->app->getPostParam("adminStateUp")))
{
$options['adminStateUp'] = $this->app->getPostParam("adminStateUp");
}
try
{
$network = getNetwork($this->app->getPostParam("networkId"));
$network->update($options);
}
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);
}
}
public function updateSubnet()
{
$options = array();
if(isset($this->app->getPostParam("name")))
{
$options['name'] = $this->app->getPostParam("name");
}
if(isset($this->app->getPostParam("networkId")))
{
$options['networkId'] = $this->app->getPostParam("networkId");
}
if(isset($this->app->getPostParam("ipVersion")))
{
$options['ipVersion'] = $this->app->getPostParam("ipVersion");
}
if(isset($this->app->getPostParam("cidr")))
{
$options['cidr'] = $this->app->getPostParam("cidr");
}
try
{
$subnet = getSubnet($this->app->getPostParam("networkId"));
$subnet->update($options);
}
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);
}
}
public function deleteNetwork()
{
try
{
$network = getNetwork($this->app->getPostParam("networkId"));
$network->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);
}
}
public function deleteSubnet()
{
try
{
$subnet = getNetwork($this->app->getPostParam("subnetId"));
$subnet->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);
}
}
public function createPort()
{
$options = array();
if (isset($this->app->getPostParam("networkId")))
{
$options['networkId'] = $this->app->getPostParam("networkId");
}
if (isset($this->app->getPostParam("name")))
{
$options['name'] = $this->app->getPostParam("name");
}
if (isset($this->app->getPostParam("adminStateUp")))
{
$options['adminStateUp'] = $this->app->getPostParam("adminStateUp");
}
if (isset($this->app->getPostParam("macAddress")))
{
$options['macAddress'] = $this->app->getPostParam("macAddress");
}
if (isset($this->app->getPostParam("fixedIps")))
{
$options['fixedIps'] = $this->app->getPostParam("fixedIps");
}
if (isset($this->app->getPostParam("deviceId")))
{
$options['deviceId'] = $this->app->getPostParam("deviceId");
}
if (isset($this->app->getPostParam("deviceOwner")))
{
$options['deviceOwner'] = $this->app->getPostParam("deviceOwner");
}
if (isset($this->app->getPostParam("securityGroups")))
{
$options['securityGroups'] = $this->app->getPostParam("securityGroups");
}
if (isset($this->app->getPostParam("tenantId")))
{
$options['tenantId'] = $this->app->getPostParam("tenantId");
}
try
{
$this->libClass->createPort($options);
}
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);
}
}
public function listPorts()
{
try
{
$this->app->setOutput("listPorts", $this->libClass->listPorts());
}
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);
}
}
public function getPort()
{
try
{
$port = $this->libClass->getport($this->app->getPostParam("portId"));
$this->app->setOutput("Port", $port);
}
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);
}
}
public function getPort($portId)
{
try
{
$port = $this->libClass->getport($portId);
return $port;
}
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);
}
}
public function updatePort()
{
$options = array();
if (isset($this->app->getPostParam("networkId")))
{
$options['networkId'] = $this->app->getPostParam("networkId");
}
if (isset($this->app->getPostParam("name")))
{
$options['name'] =$this->app->getPostParam("name");
}
if (isset($this->app->getPostParam("adminStateUp")))
{
$options['adminStateUp'] =$this->app->getPostParam("adminStateUp");
}
if (isset($this->app->getPostParam("macAddress")))
{
$options['macAddress'] = $this->app->getPostParam("macAddress");
}
if (isset($this->app->getPostParam("fixedIps")))
{
$options['fixedIps'] = $this->app->getPostParam("fixedIps");
}
if (isset($this->app->getPostParam("deviceId")))
{
$options['deviceId'] = $this->app->getPostParam("deviceId");
}
if (isset($this->app->getPostParam("deviceOwner")))
{
$options['deviceOwner'] = $this->app->getPostParam("deviceOwner");
}
if (isset($this->app->getPostParam("networkId")))
{
$options['securityGroups'] = $this->app->getPostParam("securityGroups");
}
if (isset($this->app->getPostParam("tenantId")))
{
$options['tenantId'] = $this->app->getPostParam("tenantId");
}
try
{
$port = getPort($this->app->getPostParam("networkId"));
$port->update($options);
}
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);
}
}
public function deletePort()
{
try
{
$port = getPort($this->app->getPostParam("portId"));
$port->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);
}
}
public function createSecurityGroup()
{
$options = array();
if (isset($this->app->getPostParam("name")))
{
$options['name'] = $this->app->getPostParam("name");
}
if (isset($this->app->getPostParam("description")))
{
$options['description'] = $this->app->getPostParam("description");
}
try
{
$this->libClass->createSecurityGroup($options);
}
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);
}
}
public function createSecurityGroupRule()
{
$options = array();
if (isset($this->app->getPostParam("securityGroupId")))
{
$options['securityGroupId'] = $this->app->getPostParam("securityGroupId");
}
if (isset($this->app->getPostParam("direction")))
{
$options['direction'] = $this->app->getPostParam("direction");
}
if (isset($this->app->getPostParam("ethertype")))
{
$options['ethertype'] = $this->app->getPostParam("ethertype");
}
if (isset($this->app->getPostParam("portRangeMin")))
{
$options['portRangeMin'] = $this->app->getPostParam("portRangeMin");
}
if (isset($this->app->getPostParam("portRangeMax")))
{
$options['portRangeMax'] = $this->app->getPostParam("portRangeMax");
}
if (isset($this->app->getPostParam("protocol")))
{
$options['protocol'] = $this->app->getPostParam("protocol");
}
if (isset($this->app->getPostParam("remoteGroupId")))
{
$options['remoteGroupId'] = $this->app->getPostParam("remoteGroupId");
}
if (isset($this->app->getPostParam("remoteIpPrefix")))
{
$options['remoteIpPrefix'] = $this->app->getPostParam("remoteIpPrefix");
}
try
{
$this->libClass->createSecurityGroupRule($options);
}
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);
}
}
public function listSecurityGroupe()
{
try
{
$this->app->setOutput("listSecurityGroups", $this->libClass->listSecurityGroups());
}
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);
}
}
public function listSecurityGroupeRule()
{
try
{
$this->app->setOutput("listSecurityGroupeRule", $this->libClass->listSecurityGroupRules());
}
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);
}
}
public function getSecurityGroupe()
{
try
{
$securityGroupe = $this->libClass->getSecurityGroupe($this->app->getPostParam("securityGroupeId"));
$this->app->setOutput("securityGroupe", $securityGroupe);
}
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);
}
}
public function getSecurityGroupe($securityGroupeId)
{
try
{
$securityGroupe = $this->libClass->getSecurityGroupe($securityGroupeId);
return $securityGroupe;
}
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);
}
}
public function deleteSecurityGroupe()
{
try
{
$securityGroupe = getSecurityGroupe($this->app->getPostParam("securityGroupeId"));
$securityGroupe->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);
}
}

531
server/core/NetworkLayer3.php Executable file
View file

@ -0,0 +1,531 @@
<?php
/**
* File containing the FloatingIp Class.
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Evan Pisani 'yogg at epsina . com'
*
* @todo Complete the functions with errors detection and finish the descriptions
*/
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
//include("CoreInterface.php");
/**
* Image Class of the back-end application
*
* Management of images
*
*/
class networkLayer3 {
/** @var App $app protected, contains the main app object */
protected $app;
/** @var OpenStack\Identity $libClass protected, contains the library Identity object */
protected $libClass;
/**
* floatingip constructor
*
* @param App $app the main app object
*
* @return networkLayer3
*/
public function __construct($app){
if(!isset($app)){
$this->app->setOutput("Error", "Incorrect parameter app");
}
$this->app = $app;
$this->libClass = $app->getLibClass("NetworkLayer3");
}
/**
* 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("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);
}
}
/**
* Create a new floating IP adress
*
* @param array $opt Options for the floating ip creation (floatingNetworkId is required)
*
* @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);
if(!isset($floatingip)){
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
}else{
$this->app->setOutput("NetworkLayer3", $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);
}
}
/**
* 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{
// List of floating IPs
$res = array();
$l = $this->libClass->listFloatingIps();
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->getFloatingIp($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);
}
}
/**
* Update floating ip
*
* @param id the id of the floatingip to update
*
* @return void
*/
private function updateFloatingIp(){
$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->listFloatingIps();
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);
}
}
/**
* 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{
// List of floating IPs
$res = array();
$l = $this->libClass->listFloatingIps();
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->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{
// List of floating IPs
$res = array();
$l = $this->libClass->listFloatingIps();
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->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);
}
}
/**
* 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);
}
}
}

View file

@ -1,13 +0,0 @@
<?php
abstract class plugin{
public $api;
public function __construct($api){
$this->api = $api;
}
}

View file

@ -1,24 +0,0 @@
<?php
//Init plugin directory
/*if (!defined('PLUGINS_DIR')) {
define('PLUGINS_DIR', INSTALL_PATH . 'plugins/');
}*/
class plugin_api{
static protected $instance;
protected function __construct(){
}
static function getInstance(){
if(!self::$instance){
self::$instance = new plugin_api();
}
return self::$instance;
}
}

View file

@ -1,55 +0,0 @@
<?php
ini_set('display_errors', 1);
date_default_timezone_set("Europe/Paris");
require 'vendor/autoload.php';
$options = Array();
$options["user"] = Array("name"=>"admin", "password"=>"ae5or6cn", "domain"=>["id"=>"Default"]);
$options["scope"] = Array("project"=>Array("name"=>"admin", "domain"=>["id"=>"Default"]));
$options["authUrl"] = "http://148.60.11.31:5000/v3";
$openstack = new OpenStack\OpenStack($options);
$compute=$openstack->computeV2(["region" => "RegionOne"]);
$servers = $compute->listServers(true);
foreach($servers as $server)
{
$monserv = $server;
echo $server->name."<br>";
}
echo "<br><br>";
$images = $compute->ListImages();
$monim = "";
foreach($images as $image)
{
$monim = $image;
echo $image->name."<br>";
break;
}
$flavors = $compute->ListFlavors();
echo "<br><br>";
$monflav = "";
foreach($flavors as $flavor)
{
$monflav=$flavor;
echo $flavor->name."<br>";
break;
}
$response= $compute->createServer(array('name' => "TestOthmane2",'imageId' => $monim->id , 'flavorId'=>$monflav->id , "networks" => array
( array("uuid"=> "251b4641-20ff-4a72-8549-1758788b51ce"))));

View file

@ -53,9 +53,9 @@
$App->show(); $App->show();
break; break;
case "floatingip": case "networkLayer3":
include_once("core/FloatingIp.php"); include_once("core/NetworkLayer3.php");
$computeObject = new floatingIp($App); $computeObject = new networkLayer3($App);
$computeObject->action($action); $computeObject->action($action);
$App->show(); $App->show();
break; break;