Merge branch 'develop' into loic

This commit is contained in:
manzerbredes 2016-03-01 08:22:51 +01:00
commit 53c6d3473a
2 changed files with 454 additions and 145 deletions

View file

@ -35,7 +35,15 @@ class compute
*/ */
public function listServers() public function listServers()
{ {
$servers = $this->libClass->listServers(); $serverList = $this->libClass->listServers();
$servers = Array();
foreach($serverList as $server){
$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";
}
$this->app->setOutput("Servers", $servers); $this->app->setOutput("Servers", $servers);
return; return;
} }
@ -45,7 +53,12 @@ class compute
*/ */
public function listFlavors() public function listFlavors()
{ {
$flavors = $this->libClass->listFlavors(); $flavorList = $this->libClass->listFlavors();
$flavors = Array();
foreach($flavorList as $flavor){
$flavors["$flavor->id"]["id"] = "$flavor->id;
$flavors["$flavor->id"]["name"] = "$flavor->name";
}
$this->app->setOutput("Flavors", $flavors); $this->app->setOutput("Flavors", $flavors);
return; return;
} }
@ -55,7 +68,12 @@ class compute
*/ */
public function listImages() public function listImages()
{ {
$images = $this->libClass->listImages(); $imageList = $this->libClass->listImages();
$images = Array();
foreach($imageList as $image){
$images["$image->id"]["id"] = "$image->id;
$images["$image->id"]["name"] = "$image->name";
}
$this->app->setOutput("Images", $images); $this->app->setOutput("Images", $images);
return; return;
} }

View file

@ -1,7 +1,4 @@
<?php <?php
//require 'CoreInterface.php';
/** /**
* File containing the Image Class. * File containing the Image Class.
* *
@ -12,16 +9,18 @@
* *
* @todo Complete the functions with errors detection and finish the descriptions * @todo Complete the functions with errors detection and finish the descriptions
*/ */
use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Error\BaseError;
use OpenStack\Common\Error\NotImplementedError;
use OpenStack\Common\Error\UserInputError;
/** /**
* Image Class of the back-end application * Image Class of the back-end application
* *
* ADD CLASS DESCRIPTION * ADD CLASS DESCRIPTION
* *
*/ */
class image{ class image implements Core{
//implements Core
/** @var App $app protected, contains the main app object */ /** @var App $app protected, contains the main app object */
protected $app; protected $app;
@ -29,10 +28,6 @@ class image{
/** @var OpenStack\Identity $libClass protected, contains the library Identity object */ /** @var OpenStack\Identity $libClass protected, contains the library Identity object */
protected $libClass; protected $libClass;
/** @var array $actions protected, contains the functions which can be call by the front-end */
protected $actions = array();
/** /**
* Image constructor * Image constructor
* *
@ -43,12 +38,36 @@ class image{
* @return Image * @return Image
*/ */
public function __construct($app){ public function __construct($app){
$this->app = $app; if(!isset($app)){
$this->libClass = $app->getLibClass("Image"); $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);
}
} }
/**
* Execute an action
*
* @param String $action name of another function of this class
*
* @return void
*/
public function action($action){
$this->{$action.""}();
}
/** /**
* Details about an image * Details about an image
@ -57,55 +76,96 @@ class image{
* options for the image creation * options for the image creation
* *
**/ **/
public function create_image(array $opt){ private function createImage(array $opt){
// VOIR SI MAUVAIS TYPE
$options = Array();
if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris
}
else{
//ERROR
}
if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
$options['id'] = $opt['id'];
}
if(isset($opt['visibility'])){ // public, private
$options['visibility'] = $opt['visibility'];
}
if(isset($opt['tags'])){ // list
$options['tags'] = $opt['tags'];
}
if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker
$options['containerFormat'] = $opt['containerFormat'];
}
if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso
$options['diskFormat'] = $opt['diskFormat'];
}
if(isset($opt['minDisk'])){ //int
$options['minDisk'] = $opt['minDisk'];
}
if(isset($opt['minRam'])){ // int
$options['minRam'] = $opt['minRam'];
}
if(isset($opt['protected'])){ // boolean
$options['protected'] = $opt['protected'];
}
if(isset($opt['properties'])){ // type dict ?
$options['properties'] = $opt['properties'];
}
$image = $this->oidentity->createImage($options); if(!isset($opt)){
$this->app->setOutput("Error", "Incorrect parameter");
}
try{
// VOIR SI MAUVAIS TYPE
$options = Array();
if(isset($opt['name'])){ // if the image name already exists -> error
$imagesList = listImage();
if(isset($images)){
foreach($imagesList as $image){
if(strcmp($image->name, $opt['name']) == 0){
}
}
}
}
else{
$this->app->setOutput("Error", "Image name already exists");
}
if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn
if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error
}
$options['id'] = $opt['id'];
}
if(isset($opt['visibility'])){ // public, private
$options['visibility'] = $opt['visibility'];
}
if(isset($opt['tags'])){ // list
$options['tags'] = $opt['tags'];
}
if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker
$options['containerFormat'] = $opt['containerFormat'];
}
if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso
$options['diskFormat'] = $opt['diskFormat'];
}
if(isset($opt['minDisk'])){ //int
$options['minDisk'] = $opt['minDisk'];
}
if(isset($opt['minRam'])){ // int
$options['minRam'] = $opt['minRam'];
}
if(isset($opt['protected'])){ // boolean
$options['protected'] = $opt['protected'];
}
if(isset($opt['properties'])){ // type dict ?
$options['properties'] = $opt['properties'];
}
$image = $this->libClass->createImage($options);
}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);
}
return $image; return $image;
} }
/* /**
* List images * List the images of the server
*
* @return the list with all images on the server
*/ */
public function list_images(){ private function listImage(){
// vérifier si au moins une image try{
$service = $this->oidentity; $l = $this->libClass->listImages();
$images = $service->listImages(); if(!isset($l)){ // if the list is empty there is no images
return $images; $this->app->setOutput("Error", "No 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);
}
return $l;
} }
/** /**
@ -115,11 +175,27 @@ class image{
* identifier of the image * identifier of the image
* *
**/ **/
public function image_details($id){ private function detailsImage($id){
//vérifier existence image if(!isset($id)){
$service = $this->oidentity; // Renvoyer erreur
$image = $service->getImage($id); }
return $image; try{
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
return $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);
}
} }
/** /**
@ -131,33 +207,53 @@ class image{
* @param array $opt * @param array $opt
* options for the image creation * options for the image creation
**/ **/
public function update_image($id, array $opt){ private function updateImage($id, array $opt){
//vérifier existence image if(!isset($id)){
$service = $this->oidentity; $this->app->setOutput("Error", "Incorrect id parameter");
$image = $service->getImage($id); }
$options = Array(); if(!isset($opt)){
$this->app->setOutput("Error", "Incorrect opt parameter");
}
// Voir vérification des types try{
if(isset($opt['name'])){ //string //vérifier existence image
$options['name'] = $opt['name']; $service = $this->libClass;
} $image = $service->getImage($id);
if(isset($opt['minDisk'])){ //int if($image == null){ // if the image don't exists -> error
$options['minDisk'] = $opt['minDisk']; $this->app->setOutput("Error", "Image doesn't exist");
} }
if(isset($opt['minRam'])){ // int
$options['minRam'] = $opt['minRam'];
}
if(isset($opt['protected'])){ // boolean
$options['protected'] = $opt['protected'];
}
if(isset($opt['visibility'])){ // public, private
$options['visibility'] = $opt['visibility'];
}
if(isset($opt['tags'])){ // list
$options['tags'] = $opt['tags'];
}
$image->update($options);
$options = Array();
// Voir vérification des types
if(isset($opt['name'])){ //string
$options['name'] = $opt['name'];
}
if(isset($opt['minDisk'])){ //int
$options['minDisk'] = $opt['minDisk'];
}
if(isset($opt['minRam'])){ // int
$options['minRam'] = $opt['minRam'];
}
if(isset($opt['protected'])){ // boolean
$options['protected'] = $opt['protected'];
}
if(isset($opt['visibility'])){ // public, private
$options['visibility'] = $opt['visibility'];
}
if(isset($opt['tags'])){ // list
$options['tags'] = $opt['tags'];
}
$image->update($options);
}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);
}
return $image; return $image;
} }
@ -167,11 +263,30 @@ class image{
* @param string $id * @param string $id
* identifier of the image * identifier of the image
**/ **/
public function delete_image($id){ private function deleteImage($id){
// si protected = true, demander de le mettre a false // si protected = true, demander de le mettre a false
// vérifier existence image // vérifier existence image
$service = $this->oidentity; if(!isset($id)){
$service->getImage($id)->delete(); $this->app->setOutput("Error", "Image doesn't exist");
}
try{
$service = $this->libClass;
$image = $this->libClass->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$image->delete();
}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);
}
} }
/** /**
@ -180,11 +295,27 @@ class image{
* @param string $id * @param string $id
* identifier of the image * identifier of the image
**/ **/
public function reactivate_image($id){ private function reactivateImage($id){
// vérifier existence image if(!isset($id)){
$service = $this->oidentity; $this->app->setOutput("Error", "Incorrect parameter");
$image = $service->getImage($id); }
$image->reactivate(); try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$image->reactivate();
}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);
}
} }
/** /**
@ -193,11 +324,27 @@ class image{
* @param string $id * @param string $id
* identifier of the image * identifier of the image
**/ **/
public function desactivate_image($id){ private function desactivateImage($id){
// vérifier existence image if(!isset($id)){
$service = $this->oidentity; $this->app->setOutput("Error", "Incorrect parameter");
$image = $service->getImage($id); }
$image->deactivate(); try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$image->deactivate();
}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);
}
} }
/** /**
@ -209,12 +356,31 @@ class image{
* @param string $file_name * @param string $file_name
* path of the image * path of the image
**/ **/
public function upload_image($id, $file_name){ private function uploadImage($id, $file_name){
// vérifier existence image if(!isset($id)){
$service = $this->oidentity; $this->app->setOutput("Error", "Incorrect id parameter");
$image = $service->getImage($id); }
$stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR if(!isset($file_name)){
$image->uploadData($stream); $this->app->setOutput("Error", "Incorrect file_name parameter");
}
try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r'));
$image->uploadData($stream);
}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);
}
} }
/** /**
@ -223,12 +389,28 @@ class image{
* @param string $id * @param string $id
* identifier of the image * identifier of the image
**/ **/
public function download_image($id){ private function downloadImage($id){
// vérifier existence image if(!isset($id)){
$service = $this->oidentity; $this->app->setOutput("Error", "Incorrect parameter");
$image = $service->getImage($id); }
$stream = $image->downloadData(); try{
return $stream; // vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$stream = $image->downloadData();
}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);
}
return $stream;
} }
/** /**
@ -240,12 +422,30 @@ class image{
* @param string $member_id * @param string $member_id
* identifier of the member * identifier of the member
**/ **/
public function add_member($image_id, $member_id){ private function addMemberImage($image_id, $member_id){
// vérifier existence image if(!isset($image_id)){
// on doit être le proprio de l'image $this->app->setOutput("Error", "Incorrect parameter image_id");
// vérifier membre existe }
$service = $this->oidentity; if(!isset($member_id)){
$member_id = $service>getImage($image_id)->addMember($member_id); $this->app->setOutput("Error", "Incorrect parameter member_id");
}
try{
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$member_id = $image->addMember($member_id);
}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);
}
} }
@ -255,11 +455,33 @@ class image{
* @param string $image_id * @param string $image_id
* identifier of the image * identifier of the image
**/ **/
public function list_member($image_id, $member_id){ private function listMemberImage($image_id, $member_id){
// vérifier existence image if(!isset($image_id)){
$service = $this->oidentity; $this->app->setOutput("Error", "Incorrect parameter image_id");
$image = $service->getImage($image_id); }
$members = $image->listMembers(); if(!isset($member_id)){
$this->app->setOutput("Error", "Incorrect parameter member_id");
}
try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($image_id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$members = $image->listMembers();
if($member == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "No member");
}
}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);
}
return $members; return $members;
} }
@ -272,12 +494,37 @@ class image{
* @param string $member_id * @param string $member_id
* identifier of the member * identifier of the member
**/ **/
public function detail_member($image_id, $member_id){ private function detailMemberImage($image_id, $member_id){
// vérifier existence image if(!isset($image_id)){
// on doit être le proprio de l'image $this->app->setOutput("Error", "Incorrect parameter image_id");
// vérifier membre existe }
$service = $this->oidentity; if(!isset($member_id)){
$member = $service>getImage($image_id)->getMember($member_id); $this->app->setOutput("Error", "Incorrect parameter member_id");
}
try{
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$member = $image->getMember($member_id);
if($member == null){ // if the member don't exists -> error
$this->app->setOutput("Error", "Member doesn't exist");
}
}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);
}
return $member; return $member;
} }
@ -290,12 +537,34 @@ class image{
* @param string $member_id * @param string $member_id
* identifier of the member * identifier of the member
**/ **/
public function remove_member($image_id, $member_id){ private function removeMemberImage($image_id, $member_id){
// vérifier existence image if(!isset($image_id)){
// on doit être le proprio de l'image $this->app->setOutput("Error", "Incorrect parameter image_id");
// vérifier membre existe }
$service = $this->oidentity; if(!isset($member_id)){
$service>getImage($image_id)->getMember($member_id)->delete(); $this->app->setOutput("Error", "Incorrect parameter member_id");
}
try{
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$member = $image->getMember($member_id);
if($member == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Member doesn't exist");
}
$member->delete();
}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);
}
} }
/** /**
@ -310,13 +579,35 @@ class image{
* @param string $status * @param string $status
* new status for the member * new status for the member
**/ **/
public function update_member($image_id, $member_id, $status){ private function updateMemberImage($image_id, $member_id, $status){
// vérifier existence image if(!isset($image_id)){
// on doit être le proprio de l'image $this->app->setOutput("Error", "Incorrect parameter image_id");
// vérifier membre existe }
$service = $this->oidentity; if(!isset($member_id)){
$member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); $this->app->setOutput("Error", "Incorrect parameter member_id");
}
try{
$service = $this->libClass;
$image = $service->getImage($id);
if($image == null){ // if the image don't exists -> error
$this->app->setOutput("Error", "Image doesn't exist");
}
$member = $image->getMember($member_id);
if($member == null){ // if the member don't exists -> error
$this->app->setOutput("Error", "Member doesn't exist");
}
$member->updateStatus($status);
}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);
}
} }
} }
?> ?>