summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-16 12:43:07 +0100
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2016-03-16 12:43:07 +0100
commit4dea72976bbef1715cf06fae6c8f6f881b856f00 (patch)
tree17e1c09b04cda1ff955f1824b14da6939b91b2f5 /server
parent26d10bc0fa4befbac54453228ae1ce89021bdec2 (diff)
parent11dc33c440f97410a2358f7e615d2adc5e69f072 (diff)
Merge branch 'develop' into loic
Diffstat (limited to 'server')
-rwxr-xr-xserver/Test/AppTestClass.php12
-rw-r--r--server/composer.lock42
-rwxr-xr-xserver/core/App.php32
-rwxr-xr-x[-rw-r--r--]server/core/Compute.php109
-rwxr-xr-x[-rw-r--r--]server/core/Image.php17
-rwxr-xr-xserver/core/LibOverride/genTokenOptions.php28
-rwxr-xr-x[-rw-r--r--]server/index.php68
7 files changed, 239 insertions, 69 deletions
diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php
index 57dd422..b398088 100755
--- a/server/Test/AppTestClass.php
+++ b/server/Test/AppTestClass.php
@@ -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{
diff --git a/server/composer.lock b/server/composer.lock
index 4a9581a..6ab8a7f 100644
--- a/server/composer.lock
+++ b/server/composer.lock
@@ -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",
diff --git a/server/core/App.php b/server/core/App.php
index ceda7c9..d35ccc0 100755
--- a/server/core/App.php
+++ b/server/core/App.php
@@ -56,10 +56,10 @@ class App{
return $this->openstack->networkingV2($opt);
break;
case "Compute":
- if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
- $opt = $this->tokenClass->getOptions($service);
- return $this->openstack->computeV2($opt);
- break;
+ if($this->tokenPost == NULL) $this->tokenClass->genComputeToken();
+ $opt = $this->tokenClass->getOptions($service);
+ return $this->openstack->computeV2($opt);
+ break;
}
}
@@ -81,7 +81,29 @@ class App{
$this->errorClass->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->errorClass->NotImplementedHandler($e);
- }
+ }
+
+ }
+
+ 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);
+ }
}
diff --git a/server/core/Compute.php b/server/core/Compute.php
index f02eb8b..b658580 100644..100755
--- a/server/core/Compute.php
+++ b/server/core/Compute.php
@@ -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;
+ }
+ $opt = array('id' => $serverId);
+ $server = $this->libClass->getServer($opt);
+ $server->changePassword($password);
+ $this->app->setOutput("Success", "Password for ".$serverId." has been updated successfully.");
+ return;
}
- public function reboot($type = Enum::REBOOT_SOFT)
+ /**
+ * 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;
+ }
+ $opt = array('id' => $serverId);
+ $server = $this->libClass->getServer($opt);
+ $server->reboot();
+ $this->app->setOutput("Success", $serverId." has been deleted successfully.");
+ return;
}
- public function rebuild(array $options)
+ /**
+ * 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;
+ }
+ $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;
}
- public function resize($flavorId)
+ /**
+ * 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
diff --git a/server/core/Image.php b/server/core/Image.php
index f509cd6..d37c828 100644..100755
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -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");
}
diff --git a/server/core/LibOverride/genTokenOptions.php b/server/core/LibOverride/genTokenOptions.php
index 18d880f..bdae8a6 100755
--- a/server/core/LibOverride/genTokenOptions.php
+++ b/server/core/LibOverride/genTokenOptions.php
@@ -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';
@@ -157,7 +169,7 @@ class genTokenOptions
$stack = HandlerStack::create();
- $stack->push(Middleware::authHandler($options['authHandler'], $token));
+ $stack->push(Middleware::authHandler($options['authHandler'], $token));
$this->addDebugMiddleware($options, $stack);
@@ -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"];
diff --git a/server/index.php b/server/index.php
index f888671..31feb08 100644..100755
--- a/server/index.php
+++ b/server/index.php
@@ -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,36 +17,44 @@
$App->authenticate();
$App->show();
- }
-
- switch($task)
- {
- case "identity":
- include_once("core/Identity.php");
- $identityObject = new identity($App);
- $identityObject->action($action);
- $App->show();
- break;
+ }else if($task == "Deauthenticate"){
+
+ $App->deauthenticate();
+ $App->show();
- case "network":
- include_once("core/Network.php");
- $networkObject = new network($App);
- $networkObject->action($action);
- $App->show();
- break;
+ }else{
+ switch($task)
+ {
+ case "identity":
+ include_once("core/Identity.php");
+ $identityObject = new identity($App);
+ $identityObject->action($action);
+ $App->show();
+ break;
+
+ case "network":
+ include_once("core/Network.php");
+ $networkObject = new network($App);
+ $networkObject->action($action);
+ $App->show();
+ break;
+
+ case "image":
+ include_once("core/Image.php");
+ $imageObject = new image($App);
+ $imageObject->action($action);
+ $App->show();
+ break;
+
+ case "compute":
+ include_once("core/Compute.php");
+ $computeObject = new compute($App);
+ $computeObject->action($action);
+ $App->show();
+ break;
+ }
- case "image":
- include_once("core/Image.php");
- $imageObject = new image($App);
- $imageObject->action($action);
- $App->show();
- break;
-
- case "compute":
- include_once("core/Compute.php");
- $computeObject = new compute($App);
- $computeObject->action($action);
- $App->show();
- break;
}
+
+