summaryrefslogtreecommitdiff
path: root/server/core
diff options
context:
space:
mode:
authorstupidon <bhupendra.siyag@gmail.com>2016-03-05 13:58:52 +0100
committerstupidon <bhupendra.siyag@gmail.com>2016-03-05 13:58:52 +0100
commitf4e59ee82c5947496d1810d53483c5a0afd57fe8 (patch)
treeee1ab8cfdb599e621d4360735f89d017d30cc839 /server/core
parent85222e1246b3805100428717874d15aafd682d26 (diff)
- added more details in the listServers, listImages, listFlavors functions
- updated all functions to provide basic error-handling - defined updateServer and deleteServer
Diffstat (limited to 'server/core')
-rw-r--r--server/core/Compute.php111
1 files changed, 93 insertions, 18 deletions
diff --git a/server/core/Compute.php b/server/core/Compute.php
index a5b8375..4a50f4a 100644
--- a/server/core/Compute.php
+++ b/server/core/Compute.php
@@ -12,11 +12,11 @@ class compute
protected $libClass;
- public function __construct($app)
- {
- $this->app = $app;
- $this->libClass = $app->getLibClass("Compute");
- }
+ public function __construct($app)
+ {
+ $this->app = $app;
+ $this->libClass = $app->getLibClass("Compute");
+ }
/**
* Execute an action
*
@@ -41,13 +41,26 @@ class compute
$servers[$server->id] = Array();
$server->flavor->retrieve();
$server->image->retrieve();
+ $server->retrieve();
$servers[$server->id]["id"] = $server->id;
$servers[$server->id]["name"] = $server->name;
- $servers[$server->id]["imageId"] = $server->image->id;
- $servers[$server->id]["flavorId"] = $server->flavor->id;
- $servers[$server->id]["status"] = $server->status;
+ $servers[$server->id]["image"] = $server->image;
$servers[$server->id]["ram"] = $server->flavor->ram;
$servers[$server->id]["disk"] = $server->flavor->disk;
+ $servers[$server->id]["flavor"] = $server->flavor;
+ $servers[$server->id]["status"] = $server->status;
+ $servers[$server->id]["created"] = $server->created;
+ $servers[$server->id]["updated"] = $server->updated;
+ $servers[$server->id]["ipv4"] = $server->ipv4;
+ $servers[$server->id]["ipv6"] = $server->ipv6;
+ $servers[$server->id]["progress"] = $server->progress;
+ $servers[$server->id]["hostId"] = $server->hostId;
+ $servers[$server->id]["tenantId"] = $server->tenantId;
+ $servers[$server->id]["userId"] = $server->userId;
+ $servers[$server->id]["taskState"] = $server->taskState;
+ $servers[$server->id]["addresses"] = $server->addresses;
+ $servers[$server->id]["links"] = $server->links;
+ $servers[$server->id]["metadata"] = $server->metadata;
}
$this->app->setOutput("Servers", $servers);
return;
@@ -62,8 +75,13 @@ class compute
$flavors = Array();
foreach($flavorList as $flavor){
$flavors[$flavor->id] = Array();
+ $flavor->retrieve();
$flavors[$flavor->id]["id"] = $flavor->id;
$flavors[$flavor->id]["name"] = $flavor->name;
+ $flavors[$flavor->id]["ram"] = $flavor->ram;
+ $flavors[$flavor->id]["disk"] = $flavor->disk;
+ $flavors[$flavor->id]["vcpus"] = $flavor->vcpus;
+ $flavors[$flavor->id]["links"] = $flavor->links;
}
$this->app->setOutput("Flavors", $flavors);
return;
@@ -78,8 +96,17 @@ class compute
$images = Array();
foreach($imageList as $image){
$images[$image->id] = Array();
+ $image->retrieve();
$images[$image->id]["id"] = $image->id;
$images[$image->id]["name"] = $image->name;
+ $images[$image->id]["status"] = $image->status;
+ $images[$image->id]["created"] = $image->created;
+ $images[$image->id]["updated"] = $image->updated;
+ $images[$image->id]["minDisk"] = $image->minDisk;
+ $images[$image->id]["minRam"] = $image->minRam;
+ $images[$image->id]["progress"] = $image->progress;
+ $images[$image->id]["links"] = $image->links;
+ $images[$image->id]["metadata"] = $image->metadata;
}
$this->app->setOutput("Images", $images);
return;
@@ -87,11 +114,18 @@ class compute
/**
* Create server.
* @return array
- *
+ */
public function createServer()
{
-
- $server = $this->libClass->createServer();
+ $name = $this->app->getPostParam("name");
+ $imageId = $this->app->getPostParam("imageId");
+ $flavorId = $this->app->getPostParam("flavorId");
+ if(!isset($name) || !isset($imageId) || !isset($flavorId)){
+ $this->app->setOutput("Error", "No, we don't let you create a server without a name OR image ID OR flavor ID.");
+ return;
+ }
+ $opt = array('name' => $name, 'imageId' => $imageId, 'flavorId' => $flavorId);
+ $server = $this->libClass->createServer($opt);
}
*/
/**
@@ -101,6 +135,10 @@ class compute
public function getServer()
{
$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->retrieve();
@@ -114,6 +152,10 @@ class compute
public function getFlavor()
{
$flavorId = $this->app->getPostParam("flavorId");
+ if(!isset($serverId)){
+ $this->app->setOutput("Error", "Flavor ID is missing, son!");
+ return;
+ }
$opt = array('id' => $flavorId);
$flavor = $this->libClass->getFlavor($opt);
$flavor->retrieve();
@@ -127,23 +169,56 @@ class compute
public function getImage()
{
$imageId = $this->app->getPostParam("imageId");
+ if(!isset($serverId)){
+ $this->app->setOutput("Error", "Image ID is missing, son!");
+ return;
+ }
$opt = array('id' => $imageId);
$image = $this->libClass->getImage($opt);
$image->retrieve();
$this->app->setOutput("MyImage", $image);
return;
}
- /* working on tests
-
- public function update()
+ public function updateServer()
{
- $image = $this->app->getServer(array $options = []);
-
+ $serverId = $this->app->getPostParam("serverId");
+ $newName = $this->app->getPostParam("newName");
+ $newIpv4 = $this->app->getPostParam("newIpv4");
+ $newIpv6 = $this->app->getPostParam("newIpv6");
+ if(!isset($serverId)|| !(isset($newName) || isset($newIpv4) || isset($newIpv6)) ){
+ $this->app->setOutput("Error", "You'll have to provide server ID and the new attribute(IP(v4/v6)/Name) you desire to update!");
+ return;
+ }
+ $opt = array('id' => $serverId);
+ $server = $this->libClass->getServer($opt);
+ if (isset($newName)){
+ if(isset($newIpv4)){
+ if(isset($newIpv6){
+ $attr = array('name' => $newName, 'accessIPv4' => $newIPv4, 'accessIPv6' => $newIpv6);
+ }
+ $attr = array('name' => $newName, 'accessIPv4' => $newIPv4);
+ }
+ $attr = array('name' => $newName);
+ }
+ $server->update($attr);
+ $this->app->setOutput("Success", $serverId." has been updated successfully.");
+ return;
}
- public function delete()
+ */
+ public function deleteServer()
{
- //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->delete();
+ $this->app->setOutput("Success", $serverId." has been deleted successfully.");
+ return;
}
+ /*
public function changePassword($newPassword)
{
//TODO