Merge branch 'develop' into loic

This commit is contained in:
manzerbredes 2016-03-16 12:43:07 +01:00
commit 4dea72976b
7 changed files with 240 additions and 70 deletions

View file

@ -1,12 +1,24 @@
<?php
include_once("../core/Plugin_Api.php");
include_once("../core/LibOverride/genTokenOptions.php");
<<<<<<< HEAD
<<<<<<< Updated upstream
=======
include_once("../core/ErrorManagement.php");
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
>>>>>>> Stashed changes
=======
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;
>>>>>>> develop
class AppTest{

42
server/composer.lock generated
View file

@ -71,16 +71,16 @@
},
{
"name": "guzzlehttp/promises",
"version": "1.0.3",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea"
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/b1e1c0d55f8083c71eda2c28c12a228d708294ea",
"reference": "b1e1c0d55f8083c71eda2c28c12a228d708294ea",
"url": "https://api.github.com/repos/guzzle/promises/zipball/bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"reference": "bb9024c526b22f3fe6ae55a561fd70653d470aa8",
"shasum": ""
},
"require": {
@ -118,20 +118,20 @@
"keywords": [
"promise"
],
"time": "2015-10-15 22:28:00"
"time": "2016-03-08 01:15:46"
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.2",
"version": "1.2.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb"
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5d04bdd2881ac89abde1fb78cc234bce24327bb",
"reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/2e89629ff057ebb49492ba08e6995d3a6a80021b",
"reference": "2e89629ff057ebb49492ba08e6995d3a6a80021b",
"shasum": ""
},
"require": {
@ -176,7 +176,7 @@
"stream",
"uri"
],
"time": "2016-01-23 01:23:02"
"time": "2016-02-18 21:54:00"
},
{
"name": "justinrainbow/json-schema",
@ -295,23 +295,29 @@
"source": {
"type": "git",
"url": "https://github.com/php-opencloud/openstack.git",
"reference": "15aca73f423166c7ef8337ba08615c103c66e931"
"reference": "f2ee77024843659d970817a9e7055bb40a3724f9"
},
"dist": {
"type": "zip",
<<<<<<< HEAD
<<<<<<< Updated upstream
"url": "https://api.github.com/repos/php-opencloud/openstack/zipball/15aca73f423166c7ef8337ba08615c103c66e931",
=======
"url": "https://api.github.com/repos/php-opencloud/openstack/zipball/f2ee77024843659d970817a9e7055bb40a3724f9",
>>>>>>> develop
"reference": "15aca73f423166c7ef8337ba08615c103c66e931",
=======
"url": "https://api.github.com/repos/php-opencloud/openstack/zipball/f2ee77024843659d970817a9e7055bb40a3724f9",
"reference": "f2ee77024843659d970817a9e7055bb40a3724f9",
>>>>>>> Stashed changes
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "~6.1",
"justinrainbow/json-schema": "~1.3",
"php": ">=5.6"
"php-opencloud/common": "dev-master"
},
"require-dev": {
"fabpot/php-cs-fixer": "~1.0",
"jakub-onderka/php-parallel-lint": "0.*",
"phpspec/prophecy-phpunit": "~1.0",
"phpunit/phpunit": "~4.0",
"psr/log": "~1.0",
"sami/sami": "dev-master",
@ -320,9 +326,7 @@
"type": "library",
"autoload": {
"psr-4": {
"OpenStack\\": "src/",
"OpenStack\\Test\\": "tests/unit/",
"OpenStack\\Integration\\": "tests/integration/"
"OpenStack\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -333,7 +337,7 @@
"homepage": "https://github.com/jamiehannaford"
}
],
"time": "2016-01-25 10:35:10"
"time": "2016-03-08 14:37:14"
},
{
"name": "psr/http-message",

View file

@ -85,6 +85,28 @@ class App{
}
public function deauthenticate(){
try{
$this->tokenClass->revokeComputeToken();
$this->tokenClass->revokeImageToken();
$this->tokenClass->revokeNetworkToken();
$this->tokenClass->revokeIdentityToken();
$this->setOutput("deauthenticate", "Ok");
}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];

109
server/core/Compute.php Normal file → Executable file
View file

@ -1,7 +1,6 @@
<?php
//namespace istic-openstack\Server\core;
// TODO introduce error-handling based on errors specific to the compute module
use OpenStack\Common\Error;
use OpenCloud\Common\Error;
class compute
{
@ -225,31 +224,115 @@ class compute
$this->app->setOutput("Success", $serverId." has been deleted successfully.");
return;
}
/*
public function changePassword($newPassword)
/**
* Change the password of a server
* @return void
*/
public function changePassword()
{
//TODO
$serverId = $this->app->getPostParam("serverId");
$password = $this->app->getPostParam("newPassword");
if(!isset($serverId) || !isset($password)){
$this->app->setOutput("Error", "Server ID or new password missing.");
return;
}
public function reboot($type = Enum::REBOOT_SOFT)
$opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt);
$server->changePassword($password);
$this->app->setOutput("Success", "Password for ".$serverId." has been updated successfully.");
return;
}
/**
* Reboot a server
* @return void
*/
public function reboot()
{
//TODO
$serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing, son!");
return;
}
public function rebuild(array $options)
$opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt);
$server->reboot();
$this->app->setOutput("Success", $serverId." has been deleted successfully.");
return;
}
/**
* Rebuild a server
* @return void
*/
public function rebuild()
{
//TODO
$serverId = $this->app->getPostParam("serverId");
$imageId = $this->app->getPostParam("imageId");
$newName = $this->app->getPostParam("newName");
$adminPass = $this->app->getPostParam("adminPass");
if(!isset($serverId)|| !isset($imageId) || isset($newName) || isset($adminPass)) {
$this->app->setOutput("Error", "You'll have to provide server ID and the new image, name and admin password!");
return;
}
public function resize($flavorId)
$opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt);
$attr = array('imageId' => $imageId, 'name' => $newName, 'adminPass' => $adminPass);
$server->rebuild($attr);
$this->app->setOutput("Success", $serverId." has been rebuilt successfully with the new image.");
return;
}
/**
* Resize a server
* A call to this method has to be followed by either confirmResize or revertResize
* @return void
*/
public function resize()
{
//TODO
$serverId = $this->app->getPostParam("serverId");
$newFlavorId = $this->app->getPostParam("newFlavorId");
if(!isset($serverId)|| !isset($flavorId)){
$this->app->setOutput("Error", "You'll have to provide server ID and the new flavor ID!");
return;
}
$opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt);
$server->resize($newFlavorId);
return;
}
/**
* Confirm resize operation on a server
* @return void
*/
public function confirmResize()
{
//TODO
$serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing!");
return;
}
$opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt);
$server->confirmResize();
$this->app->setOutput("Success", $serverId." has been resized successfully as the new flavor.");
return;
}
/**
* Revert resize operation on a server
* @return void
*/
public function revertResize()
{
//TODO
$serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing!");
return;
}
$opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt);
$server->revertResize();
$this->app->setOutput("Success", $serverId." : resize operation has been reverted to the old flavor.");
return;
}
/*
public function createImage(array $options)
{
//TODO

17
server/core/Image.php Normal file → Executable file
View file

@ -14,8 +14,10 @@ use OpenStack\Common\Error\BaseError;
use OpenStack\Common\Error\NotImplementedError;
use OpenStack\Common\Error\UserInputError;
include("CoreInterface.php");
/**
* Image Class of the back-end application
*
@ -71,6 +73,7 @@ class image implements Core{
private function createImage(){
$opt = $this->app->getPostParam("opt");
if(!isset($opt)){
$this->app->setOutput("Error", "Incorrect parameter");
}
@ -135,6 +138,7 @@ class image implements Core{
$this->app->getErrorInstance->NotImplementedHandler($e);
}
$this->app->setOutput("Images", $image);
}
/**
@ -158,7 +162,9 @@ class image implements Core{
}catch(NotImplementedError $e){
$this->app->getErrorInstance->NotImplementedHandler($e);
}
$this->app->setOutput("Images", $result);
}
/**
@ -172,6 +178,7 @@ class image implements Core{
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");
}
try{
$service = $this->libClass;
@ -179,7 +186,9 @@ class image implements Core{
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$this->app->setOutput("Images", $image);
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
@ -200,9 +209,11 @@ class image implements Core{
* @param array $opt
* options for the image creation
**/
private function updateImage(){
$id = $this->app->getPostParam("id");
$opt = $this->app->getPostParam("opt");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");
}
@ -292,6 +303,7 @@ class image implements Core{
**/
private function reactivateImage(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter");
}
@ -322,6 +334,7 @@ class image implements Core{
**/
private function desactivateImage(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter");
}
@ -357,6 +370,7 @@ class image implements Core{
$id = $this->app->getPostParam("id");
$file_name = $this->app->getPostParam("file_name");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect id parameter");
}
@ -391,6 +405,7 @@ class image implements Core{
**/
private function downloadImage(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter");
}
@ -462,6 +477,7 @@ class image implements Core{
private function listMemberImage(){
$image_id = $this->app->getPostParam("image_id");
$member_id = $this->app->getPostParam("member_id");
if(!isset($image_id)){
$this->app->setOutput("Error", "Incorrect parameter image_id");
}
@ -503,6 +519,7 @@ class image implements Core{
private function detailMemberImage(){
$image_id = $this->app->getPostParam("image_id");
$member_id = $this->app->getPostParam("member_id");
if(!isset($image_id)){
$this->app->setOutput("Error", "Incorrect parameter image_id");
}

View file

@ -75,6 +75,12 @@ class genTokenOptions
$this->optionsGlobal['Identity'] = $options;
}
public function revokeIdentityToken(){
$token = $this->unserializeToken($this->backup['Identity']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
public function loadIdentityBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'false';
@ -123,6 +129,12 @@ class genTokenOptions
$this->optionsGlobal['Image'] = $options;
}
public function revokeImageToken(){
$token = $this->unserializeToken($this->backup['Image']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
public function loadImageBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'glance';
@ -170,6 +182,12 @@ class genTokenOptions
$this->optionsGlobal['Network'] = $options;
}
public function revokeNetworkToken(){
$token = $this->unserializeToken($this->backup['Network']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
public function loadNetworkBackup($opt){
$options = $this->optionsGlobal['Common'];
$options['catalogName'] = 'neutron';
@ -217,6 +235,12 @@ class genTokenOptions
$this->optionsGlobal['Compute'] = $options;
}
public function revokeComputeToken(){
$token = $this->unserializeToken($this->backup['Compute']['token']);
$this->optionsGlobal['Common']['identityService']->revokeToken($token->id);
}
public function loadComputeBackup($opt){
$options = $this->optionsGlobal['Common'];
@ -245,7 +269,7 @@ class genTokenOptions
private function saveBackup($name, $data){
$token = $this->serializeToken($data["token"]);
$path = "core/LibOverride/projectTokenData/".$token['saved']["project"]["name"];
error_log(print_r($path, true), 0);
//error_log(print_r($path, true), 0);
file_put_contents("core/LibOverride/projectTokenData/".$token['saved']["project"]["name"], serialize($token['saved']));
$this->backup["roles"] = $token["roles"];
$this->backup["project"] = $token['saved']["project"]["name"];

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

@ -6,7 +6,7 @@
if(isset($_POST["task"]) && isset($_POST["action"])){
$task = $_POST["task"];
$action = $_POST["action"];
}else if(isset($_POST["task"]) && $_POST["task"] == "Authenticate"){
}else if(isset($_POST["task"]) && $_POST["task"] == "Authenticate" || $_POST["task"] == "Deauthenticate"){
$task = $_POST["task"];
}else{
//Gestion Erreur
@ -17,8 +17,12 @@
$App->authenticate();
$App->show();
}
}else if($task == "Deauthenticate"){
$App->deauthenticate();
$App->show();
}else{
switch($task)
{
case "identity":
@ -50,3 +54,7 @@
break;
}
}