summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/Test/DisplayListCidr.php26
-rw-r--r--server/Test/getIdNetwork.php34
-rw-r--r--server/Test/getNetwork.php26
-rw-r--r--server/core/Network.php195
4 files changed, 280 insertions, 1 deletions
diff --git a/server/Test/DisplayListCidr.php b/server/Test/DisplayListCidr.php
new file mode 100644
index 0000000..119b218
--- /dev/null
+++ b/server/Test/DisplayListCidr.php
@@ -0,0 +1,26 @@
+<?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);
+ $networking = $openstack->networkingV2(["region"=>"RegionOne"]);
+ $ls = $networking->listSubnets();
+
+ foreach ($ls as $subnet) {
+ echo $subnet->cidr."<br>";
+}
+
+
+
+
+
+
+
+
+
diff --git a/server/Test/getIdNetwork.php b/server/Test/getIdNetwork.php
new file mode 100644
index 0000000..1e38627
--- /dev/null
+++ b/server/Test/getIdNetwork.php
@@ -0,0 +1,34 @@
+<?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);
+ $networking = $openstack->networkingV2(["region"=>"RegionOne"]);
+
+ $ls = $networking->getNetwork('5f78d3c1-1f53-4be7-897b-cf3c797961e0');
+try{
+$ls->retrieve();
+
+
+
+echo "oui";}
+
+ catch (OpenStack\Common\Error\BadResponseError $e){
+echo "non"; }
+
+
+
+
+
+
+
+
+
+
+
diff --git a/server/Test/getNetwork.php b/server/Test/getNetwork.php
new file mode 100644
index 0000000..4c76480
--- /dev/null
+++ b/server/Test/getNetwork.php
@@ -0,0 +1,26 @@
+<?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);
+ $networking = $openstack->networkingV2(["region"=>"RegionOne"]);
+ $ls = $networking->listNetworks();
+
+ foreach ($ls as $subnet) {
+ echo $subnet->id."<br>";
+}
+
+
+
+
+
+
+
+
+
diff --git a/server/core/Network.php b/server/core/Network.php
index 8d1c8b6..6363fdb 100644
--- a/server/core/Network.php
+++ b/server/core/Network.php
@@ -1 +1,194 @@
-
+<?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(array $options)
+ {
+
+ $network = $this->libClass->createNetworks($options);
+
+
+ return $network;
+ }
+
+ public function create_subnet(array $options)
+ {
+
+ $subnet = $this->libClass->createSubnet($options);
+
+
+ return $subnet;
+ }
+
+ public function list_network_ids()
+ {
+
+ $ln = $this->libClass->listNetworks();
+
+ $list_ids = array();
+
+
+ foreach($ln as $n)
+ {
+
+ $list_ids[] = $n->id;
+
+
+ }
+
+ return $list_ids;
+ }
+
+ public function list_network_names()
+ {
+
+ $ln = $this->libClass->listNetworks();
+
+ $list_names = array();
+
+
+ foreach($ln as $n)
+ {
+
+ $list_names[] = $n->name;
+
+
+ }
+
+ return $list_names;
+ }
+
+ public function list_cidr()
+ {
+
+ $ls = $this->libClass->listSubnets();
+ $list_cidr = array();
+ foreach ($ls as $subnet)
+ {
+
+ $list_cidr[] = $subnet->cidr;
+ }
+
+ return $list_names;
+ }
+ //option array()
+ public function getNetwork($idNet)
+ {
+ $network="";
+
+ try
+ { $newtork = $networking->getNetwork($idNet);
+ $network->retrieve();
+
+
+ }
+
+ catch (OpenStack\Common\Error\BadResponseError $e)
+ {
+ $network = "Id non existant ";
+ }
+ catch (Exception $e)
+ {
+ $network = 'Exception reçue : ', $e->getMessage(), "\n";
+ }
+
+ return $network;
+ }
+
+ public function getSubnet($idSub)
+ {
+ $sbnet="";
+
+ try
+ { $subnet = $networking->getSubnet($idSub);
+ $subnet->retrieve();
+
+
+ }
+
+ catch (OpenStack\Common\Error\BadResponseError $e)
+ {
+ $sbnet = "Id non existant ";
+ }
+ catch (Exception $e)
+ {
+ $sbnet = 'Exception reçue : ', $e->getMessage(), "\n";
+ }
+
+ return $sbnet;
+ }
+
+ public function updateNetwork($idNet,$name,$shared,$adminStateUp)
+ {
+ $network = getNetwork($idNet);
+ if(!is_null($name))
+ {
+ $network->name = $name;
+ }
+ if(!is_null($shared))
+ {
+ $network->shared = $shared;
+ }
+ if(!is_null($adminStateUp))
+ {
+ $network->adminStateUp = $shared;
+ }
+ $network->update();
+ }
+
+ public function updateSubnet($idSub,$name,$networkId,$ipVersion,$cidr)
+ {
+ $subnet = getNetwork($idSub);
+ if(!is_null($name))
+ {
+ $subnet->name = $name;
+ }
+ if(!is_null($networkId))
+ {
+ $subnet->networkId = $networkId;
+ }
+ if(!is_null($ipVersion))
+ {
+ $subnet->ipVersion = $ipVersion;
+ }
+ if(!is_null($cidr))
+ {
+ $subnet->cidr = $cidr;
+ }
+ $subnet->update();
+ }
+
+ public function deleteNetwork($idNet)
+ {
+ $network = getNetwork($idNet);
+ $network->delete();
+ }
+
+ public function deleteSubnet($idSub)
+ {
+ $subnet = getNetwork($idSub);
+ $subnet->delete();
+ }