summaryrefslogtreecommitdiff
path: root/server/Test
diff options
context:
space:
mode:
authorroot <root@kabir-PC>2016-02-23 20:34:59 +0100
committerroot <root@kabir-PC>2016-02-23 20:34:59 +0100
commitd2f5ae5c83ef5bc41cf430ace79769459b4acbf8 (patch)
treeb48882db52687bdd64a398c7d1844d05dbc01343 /server/Test
parent1eff9ee90bf26127463cae0ae2cb2e1951527591 (diff)
parentff1832adcfe10fadb6cbf738c874611f77f6dd43 (diff)
Merge branch 'develop' of https://github.com/manzerbredes/istic-openstack into othmane
Diffstat (limited to 'server/Test')
-rwxr-xr-xserver/Test/AppTestClass.php73
-rwxr-xr-xserver/Test/InitTest.php30
-rw-r--r--[-rwxr-xr-x]server/Test/genTokenOptionsTest.php6
-rw-r--r--server/Test/imageTests.php95
4 files changed, 201 insertions, 3 deletions
diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php
new file mode 100755
index 0000000..311b9bf
--- /dev/null
+++ b/server/Test/AppTestClass.php
@@ -0,0 +1,73 @@
+<?php
+include_once("../core/Plugin_Api.php");
+include_once("../core/LibOverride/genTokenOptions.php");
+
+class AppTest{
+
+ protected $openstack;
+ protected $pluginsApi;
+ protected $tokenClass;
+ protected $tokenPost;
+ protected $output;
+
+ public function __construct($args){
+
+ $this->tokenPost = NULL;
+ $this->tokenClass = new genTokenOptions($args);
+ $this->openstack = new OpenStack\OpenStack([]);
+ $this->pluginsApi = plugin_api::getInstance();
+ $this->output = array();
+
+ }
+
+ public function setToken($token){
+
+ $this->tokenPost = $token;
+ $this->tokenClass->loadBackup($his->tokenPost);
+
+ }
+
+ public function getLibClass($service){
+
+ switch($service){
+ case "Identity":
+ if($this->tokenPost == NULL) $this->tokenClass->genIdentityToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->identityV3($opt);
+ break;
+ case "Image":
+ if($this->tokenPost == NULL) $this->tokenClass->genImageToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->imagesV2($opt);
+ break;
+ }
+
+ }
+
+ public function authenticate(){
+
+ try{
+ $this->tokenClass->genIdentityToken();
+ $this->tokenClass->genComputeToken();
+ $this->tokenClass->genImageToken();
+ $this->tokenClass->genNetworkToken();
+
+ $this->setOutput("token", $this->tokenClass->getBackup());
+ }catch(Exception $e){
+ echo $e;
+ exit();
+ }
+
+ }
+
+ public function setOutput($key, $out){
+
+ $this->output[$key] = $out;
+
+ }
+
+ public function show(){
+ echo json_encode($this->output);
+ }
+
+} \ No newline at end of file
diff --git a/server/Test/InitTest.php b/server/Test/InitTest.php
new file mode 100755
index 0000000..ab90864
--- /dev/null
+++ b/server/Test/InitTest.php
@@ -0,0 +1,30 @@
+<?php
+ require '../vendor/autoload.php';
+ include_once("../config.inc.php");
+ include_once("AppTestClass.php");
+
+
+ $user = "demo";
+ $password = "demopass";
+ $project = "demo";
+
+ $Args = Array(
+ "user" => Array(
+ "name" => $user,
+ "password" => $password,
+ "domain" => Array(
+ "name" => "Default")
+ ),
+ "scope" => Array(
+ "project" => Array(
+ "name" => $project,
+ "domain" => Array(
+ "name" => "Default")
+ )
+ ),
+ "authUrl" => $config["urlAuth"]
+ );
+
+ $App = new AppTest($Args);
+
+?>
diff --git a/server/Test/genTokenOptionsTest.php b/server/Test/genTokenOptionsTest.php
index 54c22d2..f7d0ee4 100755..100644
--- a/server/Test/genTokenOptionsTest.php
+++ b/server/Test/genTokenOptionsTest.php
@@ -1,8 +1,8 @@
<?php
- include_once("../config.inc.php");
+ include_once("config.inc.php");
require "../vendor/autoload.php";
- include_once("../core/Plugin_Api.php");
- include_once("../core/LibOverride/genTokenOptions.php");
+ include_once("core/Plugin_Api.php");
+ include_once("core/LibOverride/genTokenOptions.php");
$user = "admin";
$password = "ae5or6cn";
diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php
new file mode 100644
index 0000000..94ff7b6
--- /dev/null
+++ b/server/Test/imageTests.php
@@ -0,0 +1,95 @@
+<?php
+require '../vendor/autoload.php';
+include('/istic-openstack/server/init.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);
+
+//$identity = $openstack->identityV3();
+//var_dump($identity);
+// Since usernames will not be unique across an entire OpenStack installation,
+// when authenticating with them you must also provide your domain ID. You do
+// not have to do this if you authenticate with a user ID.
+/*$token = $identity->generateToken([
+ 'user' => [
+ 'name' => 'admin',
+ 'password' => 'ae5or6cn',
+ 'domain' => [
+ 'id' => 'Default'
+ ]
+ ]
+ ]);
+ */
+//$compute = $openstack->computeV2(["region" => "RegionOne"]);
+//$image= $openstack->imagesV2(["region" => "RegionOne"]);
+//var_dump($compute->client);
+//$servers = $compute->listServers(true);
+echo 'toto';
+
+$image = new Image($App);
+
+$opt = Array();
+$opt['name'] = "Test";
+$opt['tags'] = ['test', 'openstack'];
+//$opt['containerFormat'] = 'ami';
+//$opt['diskFormat'] = 'iso';
+$opt['visibility'] = 'public';
+$opt['minDisk'] = 1;
+$opt['protected'] = false;
+$opt['minRam'] = 10;
+
+//$new_image = $image->create_image($opt);
+
+
+//Liste des images
+$images = $image->list_images();
+
+echo "Images présentes :";
+echo "</br>";
+
+foreach($images as $i){
+ echo $i->name;
+ if($i->name == "Test"){
+ $id_image = $i->id;
+ $list = $i->tags;
+ echo $i->status;
+ }
+ echo "</br>";
+}
+echo "</br>";
+
+if(isset($list)){
+ foreach ($list as $l) {
+ echo $l;
+ echo "</br>";
+ }
+}
+
+// Détails Image
+//$details = $image->image_details($id_image);
+
+//$image->delete_image('123456');
+
+//$image->desactivate_image($id_image);
+//$image->reactivate_image($id_image);
+
+//$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso";
+//$image->upload_image($id_image, $file_name);
+
+//$image->download_image($id_image);
+
+/*
+$opt_update = Array();
+$opt_update['name'] = "Test";
+$opt_update['tags'] = null;
+
+$update = $image->update_image($id_image, $opt_update);
+echo $update->name;
+*/
+
+?> \ No newline at end of file