From b8e08062f35c6327dbdb210c6b3d1045bd30c1c1 Mon Sep 17 00:00:00 2001 From: stupidon Date: Tue, 15 Mar 2016 22:39:05 +0100 Subject: [PATCH] defined rest of the server functions --- server/core/Compute.php | 106 +++++++++++++++++++++++++++++++++++----- 1 file changed, 95 insertions(+), 11 deletions(-) diff --git a/server/core/Compute.php b/server/core/Compute.php index 64a88aa..37fc8ad 100644 --- a/server/core/Compute.php +++ b/server/core/Compute.php @@ -224,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