Add errors management

This commit is contained in:
Yoggzo 2016-02-17 18:29:03 +01:00
parent 58a936d015
commit 16e0328884

View file

@ -46,8 +46,18 @@ class image {
if(!isset($app)){
// Renvoyer erreur
}
$this->app = $app;
$this->libClass = $app->getLibClass("Image");
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);
}
}
@ -63,44 +73,54 @@ class image {
public function createImage(array $opt){
if(!isset($opt)){
// Renvoyer erreur
}
// 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->libClass->createImage($options);
try{
// 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->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;
}
@ -110,9 +130,20 @@ class image {
* @return the list with all images on the server
*/
public function listImage(){
// vérifier si au moins une image
$this->libClass->listImages();
//return $l;
try{
// vérifier si au moins une image
$l = $this->libClass->listImages();
}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;
}
/**
@ -126,10 +157,21 @@ class image {
if(!isset($id)){
// Renvoyer erreur
}
//vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
return $image;
try{
//vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
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);
}
}
/**
@ -148,32 +190,42 @@ class image {
if(!isset($opt)){
// Renvoyer erreur
}
//vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$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);
try{
//vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$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;
}
@ -214,10 +266,20 @@ class image {
if(!isset($id)){
// Renvoyer erreur
}
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$image->reactivate();
try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$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);
}
}
/**
@ -230,10 +292,20 @@ class image {
if(!isset($id)){
// Renvoyer erreur
}
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$image->deactivate();
try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$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);
}
}
/**
@ -252,11 +324,21 @@ class image {
if(!isset($file_name)){
// Renvoyer erreur
}
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
$image->uploadData($stream);
try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
$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);
}
}
/**
@ -269,11 +351,21 @@ class image {
if(!isset($id)){
// Renvoyer erreur
}
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$stream = $image->downloadData();
return $stream;
try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($id);
$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;
}
/**
@ -292,11 +384,21 @@ class image {
if(!isset($member_id)){
// Renvoyer erreur
}
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$member_id = $service>getImage($image_id)->addMember($member_id);
try{
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$member_id = $service>getImage($image_id)->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);
}
}
@ -313,10 +415,20 @@ class image {
if(!isset($member_id)){
// Renvoyer erreur
}
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($image_id);
$members = $image->listMembers();
try{
// vérifier existence image
$service = $this->libClass;
$image = $service->getImage($image_id);
$members = $image->listMembers();
}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;
}
@ -336,11 +448,21 @@ class image {
if(!isset($member_id)){
// Renvoyer erreur
}
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$member = $service>getImage($image_id)->getMember($member_id);
try{
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$member = $service>getImage($image_id)->getMember($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);
}
return $member;
}
@ -360,11 +482,21 @@ class image {
if(!isset($member_id)){
// Renvoyer erreur
}
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$service>getImage($image_id)->getMember($member_id)->delete();
try{
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$service>getImage($image_id)->getMember($member_id)->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);
}
}
/**
@ -386,12 +518,22 @@ class image {
if(!isset($member_id)){
// Renvoyer erreur
}
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status);
try{
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
$service = $this->libClass;
$member = $service>getImage($image_id)->getMember($member_id)->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);
}
}
}
?>
?>