completed error management and all functions of Compute module

This commit is contained in:
stupidon 2016-03-22 16:55:59 +01:00
parent b8e08062f3
commit 3372268aa1

View file

@ -34,6 +34,7 @@ class compute
*/ */
public function listServers() public function listServers()
{ {
try{
$serverList = $this->libClass->listServers(true); $serverList = $this->libClass->listServers(true);
$servers = Array(); $servers = Array();
foreach($serverList as $server){ foreach($serverList as $server){
@ -62,6 +63,22 @@ class compute
$servers[$server->id]["metadata"] = $server->metadata; $servers[$server->id]["metadata"] = $server->metadata;
} }
$this->app->setOutput("Servers", $servers); $this->app->setOutput("Servers", $servers);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -70,6 +87,7 @@ class compute
*/ */
public function listFlavors() public function listFlavors()
{ {
try{
$flavorList = $this->libClass->listFlavors(); $flavorList = $this->libClass->listFlavors();
$flavors = Array(); $flavors = Array();
foreach($flavorList as $flavor){ foreach($flavorList as $flavor){
@ -83,6 +101,22 @@ class compute
$flavors[$flavor->id]["links"] = $flavor->links; $flavors[$flavor->id]["links"] = $flavor->links;
} }
$this->app->setOutput("Flavors", $flavors); $this->app->setOutput("Flavors", $flavors);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -91,7 +125,8 @@ class compute
*/ */
public function listImages() public function listImages()
{ {
$imageList = $this->libClass->listImages(); try{
$imageList = $this->libClass->listImages();
$images = Array(); $images = Array();
foreach($imageList as $image){ foreach($imageList as $image){
$images[$image->id] = Array(); $images[$image->id] = Array();
@ -108,6 +143,22 @@ class compute
$images[$image->id]["metadata"] = $image->metadata; $images[$image->id]["metadata"] = $image->metadata;
} }
$this->app->setOutput("Images", $images); $this->app->setOutput("Images", $images);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -116,7 +167,8 @@ class compute
*/ */
public function getServer() public function getServer()
{ {
$serverId = $this->app->getPostParam("serverId"); try{
$serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){ if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing, son!"); $this->app->setOutput("Error", "Server ID is missing, son!");
return; return;
@ -125,6 +177,22 @@ class compute
$server = $this->libClass->getServer($opt); $server = $this->libClass->getServer($opt);
$server->retrieve(); $server->retrieve();
$this->app->setOutput("MyServer", $server); $this->app->setOutput("MyServer", $server);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -133,6 +201,7 @@ class compute
*/ */
public function getFlavor() public function getFlavor()
{ {
try{
$flavorId = $this->app->getPostParam("flavorId"); $flavorId = $this->app->getPostParam("flavorId");
if(!isset($serverId)){ if(!isset($serverId)){
$this->app->setOutput("Error", "Flavor ID is missing, son!"); $this->app->setOutput("Error", "Flavor ID is missing, son!");
@ -142,6 +211,22 @@ class compute
$flavor = $this->libClass->getFlavor($opt); $flavor = $this->libClass->getFlavor($opt);
$flavor->retrieve(); $flavor->retrieve();
$this->app->setOutput("MyFlavor", $flavor); $this->app->setOutput("MyFlavor", $flavor);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -150,6 +235,7 @@ class compute
*/ */
public function getImage() public function getImage()
{ {
try{
$imageId = $this->app->getPostParam("imageId"); $imageId = $this->app->getPostParam("imageId");
if(!isset($serverId)){ if(!isset($serverId)){
$this->app->setOutput("Error", "Image ID is missing, son!"); $this->app->setOutput("Error", "Image ID is missing, son!");
@ -159,6 +245,22 @@ class compute
$image = $this->libClass->getImage($opt); $image = $this->libClass->getImage($opt);
$image->retrieve(); $image->retrieve();
$this->app->setOutput("MyImage", $image); $this->app->setOutput("MyImage", $image);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -167,6 +269,7 @@ class compute
*/ */
public function createServer() public function createServer()
{ {
try{
$name = $this->app->getPostParam("name"); $name = $this->app->getPostParam("name");
$imageId = $this->app->getPostParam("imageId"); $imageId = $this->app->getPostParam("imageId");
$flavorId = $this->app->getPostParam("flavorId"); $flavorId = $this->app->getPostParam("flavorId");
@ -176,6 +279,23 @@ class compute
} }
$opt = array('name' => $name, 'imageId' => $imageId, 'flavorId' => $flavorId); $opt = array('name' => $name, 'imageId' => $imageId, 'flavorId' => $flavorId);
$server = $this->libClass->createServer($opt); $server = $this->libClass->createServer($opt);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return;
} }
/** /**
@ -184,6 +304,7 @@ class compute
*/ */
public function updateServer() public function updateServer()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
$newName = $this->app->getPostParam("newName"); $newName = $this->app->getPostParam("newName");
$newIpv4 = $this->app->getPostParam("newIpv4"); $newIpv4 = $this->app->getPostParam("newIpv4");
@ -205,6 +326,22 @@ class compute
} }
$server->update($attr); $server->update($attr);
$this->app->setOutput("Success", $serverId." has been updated successfully."); $this->app->setOutput("Success", $serverId." has been updated successfully.");
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -213,6 +350,7 @@ class compute
*/ */
public function deleteServer() public function deleteServer()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){ if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing, son!"); $this->app->setOutput("Error", "Server ID is missing, son!");
@ -222,6 +360,22 @@ class compute
$server = $this->libClass->getServer($opt); $server = $this->libClass->getServer($opt);
$server->delete(); $server->delete();
$this->app->setOutput("Success", $serverId." has been deleted successfully."); $this->app->setOutput("Success", $serverId." has been deleted successfully.");
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -230,6 +384,7 @@ class compute
*/ */
public function changePassword() public function changePassword()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
$password = $this->app->getPostParam("newPassword"); $password = $this->app->getPostParam("newPassword");
if(!isset($serverId) || !isset($password)){ if(!isset($serverId) || !isset($password)){
@ -240,6 +395,22 @@ class compute
$server = $this->libClass->getServer($opt); $server = $this->libClass->getServer($opt);
$server->changePassword($password); $server->changePassword($password);
$this->app->setOutput("Success", "Password for ".$serverId." has been updated successfully."); $this->app->setOutput("Success", "Password for ".$serverId." has been updated successfully.");
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -248,6 +419,7 @@ class compute
*/ */
public function reboot() public function reboot()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){ if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing, son!"); $this->app->setOutput("Error", "Server ID is missing, son!");
@ -257,6 +429,22 @@ class compute
$server = $this->libClass->getServer($opt); $server = $this->libClass->getServer($opt);
$server->reboot(); $server->reboot();
$this->app->setOutput("Success", $serverId." has been deleted successfully."); $this->app->setOutput("Success", $serverId." has been deleted successfully.");
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -265,6 +453,7 @@ class compute
*/ */
public function rebuild() public function rebuild()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
$imageId = $this->app->getPostParam("imageId"); $imageId = $this->app->getPostParam("imageId");
$newName = $this->app->getPostParam("newName"); $newName = $this->app->getPostParam("newName");
@ -278,6 +467,22 @@ class compute
$attr = array('imageId' => $imageId, 'name' => $newName, 'adminPass' => $adminPass); $attr = array('imageId' => $imageId, 'name' => $newName, 'adminPass' => $adminPass);
$server->rebuild($attr); $server->rebuild($attr);
$this->app->setOutput("Success", $serverId." has been rebuilt successfully with the new image."); $this->app->setOutput("Success", $serverId." has been rebuilt successfully with the new image.");
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -287,6 +492,7 @@ class compute
*/ */
public function resize() public function resize()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
$newFlavorId = $this->app->getPostParam("newFlavorId"); $newFlavorId = $this->app->getPostParam("newFlavorId");
if(!isset($serverId)|| !isset($flavorId)){ if(!isset($serverId)|| !isset($flavorId)){
@ -296,6 +502,22 @@ class compute
$opt = array('id' => $serverId); $opt = array('id' => $serverId);
$server = $this->libClass->getServer($opt); $server = $this->libClass->getServer($opt);
$server->resize($newFlavorId); $server->resize($newFlavorId);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -304,6 +526,7 @@ class compute
*/ */
public function confirmResize() public function confirmResize()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){ if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing!"); $this->app->setOutput("Error", "Server ID is missing!");
@ -313,6 +536,22 @@ class compute
$server = $this->libClass->getServer($opt); $server = $this->libClass->getServer($opt);
$server->confirmResize(); $server->confirmResize();
$this->app->setOutput("Success", $serverId." has been resized successfully as the new flavor."); $this->app->setOutput("Success", $serverId." has been resized successfully as the new flavor.");
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/** /**
@ -321,6 +560,7 @@ class compute
*/ */
public function revertResize() public function revertResize()
{ {
try{
$serverId = $this->app->getPostParam("serverId"); $serverId = $this->app->getPostParam("serverId");
if(!isset($serverId)){ if(!isset($serverId)){
$this->app->setOutput("Error", "Server ID is missing!"); $this->app->setOutput("Error", "Server ID is missing!");
@ -330,37 +570,53 @@ class compute
$server = $this->libClass->getServer($opt); $server = $this->libClass->getServer($opt);
$server->revertResize(); $server->revertResize();
$this->app->setOutput("Success", $serverId." : resize operation has been reverted to the old flavor."); $this->app->setOutput("Success", $serverId." : resize operation has been reverted to the old flavor.");
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return; return;
} }
/*
public function createImage(array $options)
{
//TODO
}
public function listAddresses(array $options = []) public function listAddresses(array $options = [])
{ {
//TODO try{
$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);
$addresses = $server->listAddresses();
$this->app->setOutput("Addresses", $addresses);
}
catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}
catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}
catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}
catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}
catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
return;
} }
public function getMetadata()
{
//TODO
}
public function resetMetadata(array $metadata)
{
//TODO
}
public function mergeMetadata(array $metadata)
{
//TODO
}
public function getMetadataItem($key)
{
//TODO
}
public function deleteMetadataItem($key)
{
//TODO
}
*/
} }