Maj Library
This commit is contained in:
commit
2b8decb81f
118 changed files with 6425 additions and 208 deletions
server/core
|
@ -3,10 +3,10 @@ include_once("core/Plugin_Api.php");
|
|||
include_once("core/LibOverride/genTokenOptions.php");
|
||||
include_once("core/ErrorManagement.php");
|
||||
|
||||
use OpenStack\Common\Error\BadResponseError;
|
||||
use OpenStack\Common\Error\BaseError;
|
||||
use OpenStack\Common\Error\NotImplementedError;
|
||||
use OpenStack\Common\Error\UserInputError;
|
||||
use OpenCloud\Common\Error\BadResponseError;
|
||||
use OpenCloud\Common\Error\BaseError;
|
||||
use OpenCloud\Common\Error\NotImplementedError;
|
||||
use OpenCloud\Common\Error\UserInputError;
|
||||
|
||||
class App{
|
||||
|
||||
|
|
|
@ -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,29 +96,32 @@ 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;
|
||||
}
|
||||
/**
|
||||
* Create server.
|
||||
* @return array
|
||||
*
|
||||
public function createServer()
|
||||
{
|
||||
|
||||
$server = $this->libClass->createServer();
|
||||
}
|
||||
*/
|
||||
/**
|
||||
/**
|
||||
* Get server details.
|
||||
* @return array
|
||||
*/
|
||||
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 +135,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 +152,80 @@ 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()
|
||||
/**
|
||||
* Create server.
|
||||
* @return array
|
||||
*/
|
||||
public function createServer()
|
||||
{
|
||||
$image = $this->app->getServer(array $options = []);
|
||||
|
||||
$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);
|
||||
}
|
||||
public function delete()
|
||||
|
||||
/**
|
||||
* update a server
|
||||
* @return void
|
||||
*/
|
||||
public function updateServer()
|
||||
{
|
||||
//TODO
|
||||
$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);
|
||||
}
|
||||
else $attr = array('name' => $newName, 'accessIPv4' => $newIPv4);
|
||||
}
|
||||
else $attr = array('name' => $newName);
|
||||
}
|
||||
$server->update($attr);
|
||||
$this->app->setOutput("Success", $serverId." has been updated successfully.");
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Delete a server
|
||||
* @return void
|
||||
*/
|
||||
public function deleteServer()
|
||||
{
|
||||
$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
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
use OpenStack\Common\Error\BadResponseError;
|
||||
use OpenStack\Common\Error\BaseError;
|
||||
use OpenStack\Common\Error\NotImplementedError;
|
||||
use OpenStack\Common\Error\UserInputError;
|
||||
use OpenCloud\Common\Error\BadResponseError;
|
||||
use OpenCloud\Common\Error\BaseError;
|
||||
use OpenCloud\Common\Error\NotImplementedError;
|
||||
use OpenCloud\Common\Error\UserInputError;
|
||||
|
||||
|
||||
Class errorManagement{
|
||||
|
@ -36,4 +36,4 @@ Class errorManagement{
|
|||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
* @todo Complete the functions and finish the descriptions
|
||||
*/
|
||||
use OpenStack\Common\Error;
|
||||
use OpenCloud\Common\Error;
|
||||
|
||||
/**
|
||||
* Identity Class of the back-end application
|
||||
|
|
|
@ -45,18 +45,8 @@ class image implements Core{
|
|||
if(!isset($app)){
|
||||
$this->app->setOutput("Error", "Incorrect parameter");
|
||||
}
|
||||
try{
|
||||
$this->app = $app;
|
||||
$this->libClass = $app->getLibClass("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);
|
||||
}
|
||||
$this->app = $app;
|
||||
$this->libClass = $app->getLibClass("Image");
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,8 +70,12 @@ class image implements Core{
|
|||
* options for the image creation
|
||||
*
|
||||
**/
|
||||
<<<<<<< HEAD
|
||||
private function createImage(array $opt){
|
||||
|
||||
=======
|
||||
private function createImage(){
|
||||
>>>>>>> develop
|
||||
$opt = $this->app->getPostParam("opt");
|
||||
|
||||
|
||||
|
@ -377,7 +371,7 @@ class image implements Core{
|
|||
* @param string $file_name
|
||||
* path of the image
|
||||
**/
|
||||
private function uploadImage($id, $file_name){
|
||||
private function uploadImage(){
|
||||
$id = $this->app->getPostParam("id");
|
||||
$file_name = $this->app->getPostParam("file_name");
|
||||
|
||||
|
@ -414,9 +408,13 @@ class image implements Core{
|
|||
* @param string $id
|
||||
* identifier of the image
|
||||
**/
|
||||
<<<<<<< HEAD
|
||||
private function downloadImage($id){
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
private function downloadImage(){
|
||||
>>>>>>> develop
|
||||
$id = $this->app->getPostParam("id");
|
||||
>>>>>>> develop
|
||||
if(!isset($id)){
|
||||
|
@ -620,7 +618,7 @@ class image implements Core{
|
|||
* @param string $status
|
||||
* new status for the member
|
||||
**/
|
||||
private function updateMemberImage($image_id, $member_id, $status){
|
||||
private function updateMemberImage(){
|
||||
$image_id = $this->app->getPostParam("image_id");
|
||||
$member_id = $this->app->getPostParam("member_id");
|
||||
$status = $this->app->getPostParam("status");
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use OpenStack\Common\Transport\HandlerStack;
|
||||
use OpenStack\Common\Transport\Middleware;
|
||||
use OpenCloud\Common\Transport\HandlerStack;
|
||||
use OpenCloud\Common\Transport\Middleware;
|
||||
use OpenStack\Identity\v3\Service;
|
||||
use OpenStack\Identity\v3\Api;
|
||||
use OpenStack\Common\Auth\Token;
|
||||
use OpenStack\Common\Transport\Utils;
|
||||
use OpenCloud\Common\Auth\Token;
|
||||
use OpenCloud\Common\Transport\Utils;
|
||||
use OpenStack\Identity\v3\Models;
|
||||
|
||||
class genTokenOptions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue