Merge branch 'develop' of github.com:manzerbredes/istic-openstack into develop

This commit is contained in:
manzerbredes 2016-02-17 14:01:49 +01:00
commit 4819078870
9 changed files with 1932 additions and 82 deletions

73
server/Test/AppTestClass.php Executable file
View file

@ -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);
}
}

30
server/Test/InitTest.php Executable file
View file

@ -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);
?>

View file

@ -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";

View file

@ -1,9 +1,8 @@
<?php
ini_set('display_errors', 1);
date_default_timezone_set("Europe/Paris");
require 'vendor/autoload.php';
include("core/Image.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"]));
@ -30,11 +29,9 @@ $openstack = new OpenStack\OpenStack($options);
//$image= $openstack->imagesV2(["region" => "RegionOne"]);
//var_dump($compute->client);
//$servers = $compute->listServers(true);
echo 'toto';
// Initialisation Image()
$optImage = Array();
$optImage["region"] = "RegionOne";
$image = new Image($openstack, $optImage);
$image = new Image($App);
$opt = Array();
$opt['name'] = "Test";
@ -48,6 +45,7 @@ $opt['minRam'] = 10;
//$new_image = $image->create_image($opt);
//Liste des images
$images = $image->list_images();

View file

@ -1,13 +1,21 @@
<?php
include_once("core/Plugin_Api.php");
include_once("core/LibOverride/genTokenOptions.php");
include_once("core/ErrorManagement.php");
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Error\BaseError;
use OpenStack\Common\Error\NotImplementedError;
use OpenStack\Common\Error\UserInputError;
class App{
protected $openstack;
protected $pluginsApi;
protected $postParams;
protected $tokenClass;
protected $tokenPost;
protected $errorClass;
protected $output;
public function __construct($args){
@ -16,7 +24,9 @@ class App{
$this->tokenClass = new genTokenOptions($args);
$this->openstack = new OpenStack\OpenStack([]);
$this->pluginsApi = plugin_api::getInstance();
$this->errorClass = new errorManagement($this);
$this->output = array();
$this->postParams = $_POST;
}
@ -31,14 +41,14 @@ class App{
switch($service){
case "Identity":
if($tokenPost == NULL) $tokenClass->genIdentityToken();
$opt = $tokenClass->getOptions($service);
if($this->tokenPost == NULL) $this->tokenClass->genIdentityToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->identityV3($opt);
break;
case "Image":
if($tokenPost == NULL) $tokenClass->genImageToken();
$opt = $tokenClass->getOptions($service);
return $this->$openstack->imagesV2($opt);
if($this->tokenPost == NULL) $this->tokenClass->genImageToken();
$opt = $this->tokenClass->getOptions($service);
return $this->openstack->imagesV2($opt);
break;
}
@ -53,10 +63,21 @@ class App{
$this->tokenClass->genNetworkToken();
$this->setOutput("token", $this->tokenClass->getBackup());
}catch(Exception $e){
echo $e;
exit();
}
}catch(BadResponseError $e){
$this->errorClass->BadResponseHandler($e);
}catch(UserInputError $e){
$this->errorClass->UserInputHandler($e);
}catch(BaseError $e){
$this->errorClass->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->errorClass->NotImplementedHandler($e);
}
}
public function getPostParam($name){
return $this->postParams[$name];
}
@ -66,6 +87,12 @@ class App{
}
public function getErrorInstance(){
return $this->errorClass;
}
public function show(){
echo json_encode($this->output);
}

39
server/core/ErrorManagement.php Executable file
View file

@ -0,0 +1,39 @@
<?php
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Error\BaseError;
use OpenStack\Common\Error\NotImplementedError;
use OpenStack\Common\Error\UserInputError;
Class errorManagement{
protected $app;
public function __construct($args){
$this->app = $args;
}
public function BaseErrorHandler($error){
}
public function BadResponseHandler($error){
$this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
}
public function NotImplementedHandler($error){
$this->app->setOutput("Error", "Erreur Interne, Merci de contacter un administrateur!");
}
public function UserInputHandler($error){
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -1,26 +1,55 @@
<?php
ini_set('display_errors', 1);
date_default_timezone_set("Europe/Paris");
class Image {
//require 'CoreInterface.php';
/**
* File containing the Image Class.
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Yogg 'yogg at epsina . com'
*
* @todo Complete the functions with errors detection and finish the descriptions
*/
/**
* Image Class of the back-end application
*
* ADD CLASS DESCRIPTION
*
*/
class image{
//implements Core
/** @var App $app protected, contains the main app object */
protected $app;
protected $oidentity;
//protected $plugins;
/** @var OpenStack\Identity $libClass protected, contains the library Identity object */
protected $libClass;
/** @var array $actions protected, contains the functions which can be call by the front-end */
protected $actions = array();
/**
* Constructor
* Image constructor
*
* @param $openstack
*
* @param $options
* @param App $app the main app object
*
**/
public function __construct($ostack, $options){ //, $apiP
$this->oidentity = $ostack->imagesV2($options);
//$this->plugins = $apiP;
* @throws [Type] [<description>]
*
* @return Image
*/
public function __construct($app){
$this->app = $app;
$this->libClass = $app->getLibClass("Image");
}
/**
* Details about an image
*

@ -1 +1 @@
Subproject commit 15aca73f423166c7ef8337ba08615c103c66e931
Subproject commit 1419eb2e01164bb6b8b837df37724423907352d7