summaryrefslogtreecommitdiff
path: root/server/core/Compute.php
diff options
context:
space:
mode:
Diffstat (limited to 'server/core/Compute.php')
-rwxr-xr-x[-rw-r--r--]server/core/Compute.php109
1 files changed, 96 insertions, 13 deletions
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