summaryrefslogtreecommitdiff
path: root/server/core
diff options
context:
space:
mode:
Diffstat (limited to 'server/core')
-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
4 files changed, 166 insertions, 20 deletions
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"];