Merge branch 'develop' into Evan

mise a jour de la branche
This commit is contained in:
Yoggzo 2016-02-04 23:54:00 +01:00
commit ae8e5e7d1c
35 changed files with 771 additions and 1331 deletions

View file

@ -0,0 +1,86 @@
<?php
include_once("../config.inc.php");
require "../vendor/autoload.php";
include_once("../core/Plugin_Api.php");
include_once("../core/LibOverride/genTokenOptions.php");
$user = "admin";
$password = "ae5or6cn";
$project = "admin";
$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"]
);
$genOptions = new genTokenOptions($Args);
$genOptions->genIdentityToken();
$genOptions->genComputeToken();
$genOptions->genNetworkToken();
$genOptions->genImageToken();
$backCompute = $genOptions->getBackup("Compute");
$backIdentity = $genOptions->getBackup("Identity");
$backNetwork = $genOptions->getBackup("Network");
$backImage = $genOptions->getBackup("Image");
$openstack_api = new OpenStack\OpenStack([]);
$newGenOptions = new genTokenOptions($Args);
$newGenOptions->loadIdentityBackup($backIdentity);
$newGenOptions->loadComputeBackup($backCompute);
$newGenOptions->loadImageBackup($backImage);
$newGenOptions->loadNetworkBackup($backNetwork);
$optionsCompute = $newGenOptions->getOptions("Compute");
$optionsIdentity = $newGenOptions->getOptions("Identity");
$optionsNetwork = $newGenOptions->getOptions("Network");
$optionsImage = $newGenOptions->getOptions("Image");
$identityTest = $openstack_api->identityV3($optionsIdentity);
$computeTest = $openstack_api->computeV2($optionsCompute);
$networkTest = $openstack_api->networkingV2($optionsNetwork);
$imageTest = $openstack_api->imagesV2($optionsImage);
$domainsTest = $identityTest->listDomains();
echo "Identity Test, List Domains </br>";
foreach($domainsTest as $domain){
echo $domain->id;
echo "</br>";
}
echo "</br>";
$imagesTest = $imageTest->listImages();
echo "Image Test, List Images </br>";
foreach($imagesTest as $image){
echo $image->id;
echo "</br>";
}
echo "</br>";
$serversTest = $computeTest->listServers();
echo "Compute Test, List Servers </br>";
foreach($serversTest as $server){
echo $server->id;
echo "</br>";
}
echo "</br>";
$networkTest = $networkTest->listNetworks();
echo "Network Test, List networks </br>";
foreach($networkTest as $network){
echo $network->id;
echo "</br>";
}
?>

View file

@ -1,7 +1,10 @@
<?php
date_default_timezone_set('Europe/Paris');
$config = Array();
$config["modules_enabled"] = "";
$config["urlAuth"] = "http://148.60.11.31:5000/v3";
?>

View file

@ -1 +1,19 @@
<?php
class identity {
protected $oidentity;
public function __construct($ostack, $apiP){
$this->oidentity = $ostack->identityV3();
$this->plugins = $apiP;
}
public function genToken(){
global $Args;
$token = $this->oidentity->generateToken($Args);
return $token;
}
}

View file

@ -0,0 +1,369 @@
<?php
use GuzzleHttp\Client;
use OpenStack\Common\Transport\HandlerStack;
use OpenStack\Common\Transport\Middleware;
use OpenStack\Identity\v3\Service;
use OpenStack\Identity\v3\Api;
use OpenStack\Common\Auth\Token;
use OpenStack\Common\Transport\Utils;
use OpenStack\Identity\v3\Models;
class genTokenOptions
{
private $optionsGlobal;
private $stack;
private $backup = [];
private $httpClient;
public function __construct($options){
$this->stack = HandlerStack::create();
$httpClient = new Client([
'base_uri' => Utils::normalizeUrl($options['authUrl']),
'handler' => $this->stack,
]);
$this->httpClient = $httpClient;
$options['identityService'] = Service::factory($httpClient);
$options['authHandler'] = function () use ($options) {
return $options['identityService']->generateToken($options);
};
$this->optionsGlobal['Common'] = $options;
}
/**
* @codeCoverageIgnore
*/
private function addDebugMiddleware(array $options, HandlerStack &$stack)
{
if (!empty($options['debugLog'])
&& !empty($options['logger'])
&& !empty($options['messageFormatter'])
) {
$stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
}
}
public function genIdentityToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'false';
$options['catalogType'] = 'false';
$options['region'] = 'RegionOne';
//list($token, $baseUrl) = $options['identityService']->authenticate($options);
$baseUrl = $options["authUrl"];
$token = $options['identityService']->generateToken($options);
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Identity'] = $options;
}
public function loadIdentityBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'false';
$options['catalogType'] = 'false';
$options['region'] = 'RegionOne';
$this->backup['Identity'] = unserialize($opt);
$token = $this->unserializeToken($this->backup['Identity']['token']);
$baseUrl = $this->backup['Identity']['baseUrl'];
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Identity'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Identity'] = $options;
}
public function genImageToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'glance';
$options['catalogType'] = 'image';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Image'] = $options;
}
public function loadImageBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'glance';
$options['catalogType'] = 'image';
$options['region'] = 'RegionOne';
$this->backup['Image'] = unserialize($opt);
$token = $this->unserializeToken($this->backup['Image']['token']);
$baseUrl = $this->backup['Image']['baseUrl'];
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Image'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Image'] = $options;
}
public function genNetworkToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'neutron';
$options['catalogType'] = 'network';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Network'] = $options;
}
public function loadNetworkBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'neutron';
$options['catalogType'] = 'network';
$options['region'] = 'RegionOne';
$this->backup['Network'] = unserialize($opt);
$token = $this->unserializeToken($this->backup['Network']['token']);
$baseUrl = $this->backup['Network']['baseUrl'];
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Network'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Network'] = $options;
}
public function genComputeToken(){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'nova';
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
list($token, $baseUrl) = $options['identityService']->authenticate($options);
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Compute'] = $options;
}
public function loadComputeBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'nova';
$options['catalogType'] = 'compute';
$options['region'] = 'RegionOne';
$this->backup['Compute'] = unserialize($opt);
$token = $this->unserializeToken($this->backup['Compute']['token']);
$baseUrl = $this->backup['Compute']['baseUrl'];
$stack = HandlerStack::create();
$stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
$options['httpClient'] = new Client([
'base_uri' => Utils::normalizeUrl($baseUrl),
'handler' => $stack,
]);
$this->backup['Compute'] = array('token' => $this->serializeToken($token), 'baseUrl' => $baseUrl );
$this->optionsGlobal['Compute'] = $options;
}
public function getBackup($service){
return serialize($this->backup[$service]);
}
public function getOptions($service){
return $this->optionsGlobal[$service];
}
private function serializeToken($token){
$tokenSerialized = [];
$tokenSerialized["methods"] = serialize($token->methods);
$tokenSerialized["roles"] = [];
foreach($token->roles as $role){
$tokenSerialized["roles"][serialize($role->id)]["links"] = serialize($role->links);
$tokenSerialized["roles"][serialize($role->id)]["name"] = serialize($role->name);
}
$tokenSerialized["expires"] = serialize($token->expires);
$tokenSerialized["project"]["domainId"] = serialize($token->project->domainId);
$tokenSerialized["project"]["parentId"] = serialize($token->project->parentId);
$tokenSerialized["project"]["enabled"] = serialize($token->project->enabled);
$tokenSerialized["project"]["description"] = serialize($token->project->description);
$tokenSerialized["project"]["id"] = serialize($token->project->id);
$tokenSerialized["project"]["links"] = serialize($token->project->links);
$tokenSerialized["project"]["name"] = serialize($token->project->name);
foreach($token->catalog->services as $service){
$tokenSerialized["catalog"][serialize($service->id)]["name"] = serialize($service->name);
$tokenSerialized["catalog"][serialize($service->id)]["description"] = serialize($service->description);
$tokenSerialized["catalog"][serialize($service->id)]["type"] = serialize($service->type);
foreach($service->endpoints as $end){
$tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["interface"] = serialize($end->interface);
$tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["name"] = serialize($end->name);
$tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["serviceId"] = serialize($end->serviceId);
$tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["region"] = serialize($end->region);
$tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["links"] = serialize($end->links);
$tokenSerialized["catalog"][serialize($service->id)]["endpoints"][serialize($end->id)]["url"] = serialize($end->url);
}
$tokenSerialized["roles"][serialize($service->id)]["links"] = serialize($service->links);
}
$tokenSerialized["extras"] = serialize($token->extras);
$tokenSerialized["user"]["domainId"] = serialize($token->user->domainId);
$tokenSerialized["user"]["defaultProjectId"] = serialize($token->user->defaultProjectId);
$tokenSerialized["user"]["id"] = serialize($token->user->id);
$tokenSerialized["user"]["email"] = serialize($token->user->email);
$tokenSerialized["user"]["enabled"] = serialize($token->user->enabled);
$tokenSerialized["user"]["description"] = serialize($token->user->description);
$tokenSerialized["user"]["links"] = serialize($token->user->links);
$tokenSerialized["user"]["name"] = serialize($token->user->name);
$tokenSerialized["issued"] = serialize($token->issued);
$tokenSerialized["id"] = serialize($token->id);
return $tokenSerialized;
}
private function unserializeToken($tokenSerialized){
$api = new Api();
$token = new Models\Token($this->httpClient, $api);
$token->methods = unserialize($tokenSerialized["methods"]);
$token->roles = [];
foreach($tokenSerialized["roles"] as $key => $role){
$tmp = new Models\Role($this->httpClient, $api);
$tmp->id = unserialize($key);
$tmp->links = unserialize($role["links"]);
if(isset($role["name"]))
$tmp->name = unserialize($role["name"]);
$token->roles[] = $tmp;
}
$token->expires = unserialize($tokenSerialized["expires"]);
$token->project = new Models\Project($this->httpClient, $api);
$token->project->domainId = unserialize($tokenSerialized["project"]["domainId"]);
$token->project->parentId = unserialize($tokenSerialized["project"]["parentId"]);
$token->project->enabled = unserialize($tokenSerialized["project"]["enabled"]);
$token->project->description = unserialize($tokenSerialized["project"]["description"]);
$token->project->id = unserialize($tokenSerialized["project"]["id"]);
$token->project->links = unserialize($tokenSerialized["project"]["links"]);
$token->project->name = unserialize($tokenSerialized["project"]["name"]);
$token->catalog = new Models\Catalog($this->httpClient, $api);
$token->catalog->services = [];
foreach($tokenSerialized["catalog"] as $key => $service){
$tmp = new Models\Service($this->httpClient, $api);
$tmp->id = unserialize($key);
$tmp->name = unserialize($service["name"]);
$tmp->description = unserialize($service["description"]);
$tmp->type = unserialize($service["type"]);
$tmp->endpoints = [];
foreach($service["endpoints"] as $key => $end){
$tmpEnd = new Models\Endpoint($this->httpClient, $api);
$tmpEnd->id = unserialize($key);
$tmpEnd->interface = unserialize($end["interface"]);
$tmpEnd->name = unserialize($end["name"]);
$tmpEnd->serviceId = unserialize($end["serviceId"]);
$tmpEnd->region = unserialize($end["region"]);
$tmpEnd->links = unserialize($end["links"]);
$tmpEnd->url = unserialize($end["url"]);
$tmp->endpoints[] = $tmpEnd;
}
if(isset($service["links"]))
$tmp->links = unserialize($service["links"]);
$token->catalog->services[] = $tmp;
}
$token->extras = unserialize($tokenSerialized["extras"]);
$token->user = new Models\User($this->httpClient, $api);
$token->user->domainId = unserialize($tokenSerialized["user"]["domainId"]);
$token->user->defaultProjectId = unserialize($tokenSerialized["user"]["defaultProjectId"]);
$token->user->id = unserialize($tokenSerialized["user"]["id"]);
$token->user->email = unserialize($tokenSerialized["user"]["email"]);
$token->user->enabled = unserialize($tokenSerialized["user"]["enabled"]);
$token->user->links = unserialize($tokenSerialized["user"]["links"]);
$token->user->name = unserialize($tokenSerialized["user"]["name"]);
$token->user->description = unserialize($tokenSerialized["user"]["description"]);
$token->issued = unserialize($tokenSerialized["issued"]);
$token->id = unserialize($tokenSerialized["id"]);
return $token;
}
}

View file

@ -1,9 +1,9 @@
<?php
//Init plugin directory
if (!defined('PLUGINS_DIR')) {
/*if (!defined('PLUGINS_DIR')) {
define('PLUGINS_DIR', INSTALL_PATH . 'plugins/');
}
}*/
class plugin_api{

30
server/index.php Normal file → Executable file
View file

@ -3,7 +3,33 @@
include_once("config.inc.php");
include_once("init.php");
$task = $_POST["task"];
$action = $_POST["action"];
// $task = $_POST["task"];
// $action = $_POST["action"];
//$id = new identity($openstack_api, $pluginApi);
// var_dump($id->genToken());
// $identity = $openstack_api->identityV3($Args);
//$tmp = $identity->listEndpoints();
//foreach($tmp as $cred){
// echo $cred->id." %%%%%% ";
//}
//$servers = $compute->listServers(true);
//var_dump($servers);
//foreach($servers as $server){
// echo $server->id." !!!!!!!!! ";
//}
$tmp = new genTokenOptions($Args);
$tmp->loadIdentityBackup($identityBack);
$array = $tmp->getOptions("Identity");
$openstackTest = new OpenStack\OpenStack([]);
$identityTest = $openstackTest->identityV3($array);
$domainsTest = $identityTest->listDomains();
foreach($domainsTest as $domain){
echo $domain->id." %%%%%% ";
}
// var_dump($openstack_api->getBuilderOptions());

43
server/init.php Normal file → Executable file
View file

@ -2,7 +2,9 @@
include_once("config.inc.php");
include_once("core/Plugin_Api.php");
require "vendor/autoload.php";
include_once("core/LibOverride/genTokenOptions.php");
include_once("core/Identity.php");
//traitement requete, recuperation data
if(isset($_POST["key"])){
//recuperation des donnes sauvegardes
@ -27,11 +29,44 @@
"name" => "Default")
)
),
"authUrl" => $urlAuth
"authUrl" => $config["urlAuth"]
);
} else {
$user = "admin";
$password = "ae5or6cn";
$project = "admin";
$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"]
);
}
$openstack_api = new OpenStack\OpenStack($Args);
$pluginApi = plugin_api::getInstance();
//$openstack_api = new OpenStack\OpenStack($Args);
//$id = new identity($openstack_api, $pluginApi);
//$token = $id->genToken();
$tmp = new genTokenOptions($Args);
$tmp->genIdentityToken();
$array = $tmp->getOptions("Identity");
$openstack_api = new OpenStack\OpenStack([]);
$identityBack = $tmp->getBackup("Identity");
//file_put_contents("token", serialize($tmp));
?>