From b39f5c1cd4631be3259b272e1f6cbe9b4915410b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 4 Feb 2016 23:48:43 +0100 Subject: Ajout des fonctionnalités de base des images, sans gestion la d'erreurs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/core/Image.php | 195 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 194 insertions(+), 1 deletion(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index 8d1c8b6..d345034 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -1 +1,194 @@ - +oidentity = $ostack->imagesV2($options); + //$this->plugins = $apiP; + } + + + /** + * Details about an image + * + * @param array $opt + * options for the image creation + * + **/ + public function create_image(array $opt){ + // VOIR SI MAUVAIS TYPE + $options = Array(); + if(isset($opt['name'])){ // string, rendre le nom obligatoire + $options['name'] = $opt['name']; + } + 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); + + return $image; + } + + /* + * List images + */ + public function list_images(){ + $service = $this->oidentity; + $images = $service->listImages(); + return $images; + } + + /** + * Details about an image + * + * @param string $id + * identifier of the image + * + **/ + public function image_details($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + return $image; + } + + /** + * Details about an image + * + * @param string $id + * id of the image + * + * @param array $opt + * options for the image creation + **/ + public function update_image($id, array $opt){ + $service = $this->oidentity; + $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); + + return $image; + } + + /** + * Delete an image + * + * @param string $id + * identifier of the image + **/ + public function delete_image($id){ + $service = $this->oidentity; + $service->getImage($id)->delete(); + } + + /** + * Resactive an image + * + * @param string $id + * identifier of the image + **/ + public function reactivate_image($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + $image->reactivate(); + } + + /** + * Desactive an image + * + * @param string $id + * identifier of the image + **/ + public function desactivate_image($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + $image->deactivate(); + } + + /** + * Upload an image + * + * @param string $id + * identifier of the image + * + * @param string $file_name + * path of the image + **/ + public function upload_image($id, $file_name){ + $service = $this->oidentity; + $image = $service->getImage($id); + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR + $image->uploadData($stream); + } + + /** + * Download an image + * + * @param string $id + * identifier of the image + */ + public function download_image($id){ + $service = $this->oidentity; + $image = $service->getImage($id); + $stream = $image->downloadData(); + return $stream; + } +} +?> -- cgit v1.2.3 From ee36719e20e6a72ca07849d4a2fea32c6ca9734f Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 7 Feb 2016 10:29:12 +0100 Subject: Add commentaries for errors managing --- server/core/Image.php | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 4 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index d345034..b83d155 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -31,8 +31,10 @@ class Image { public function create_image(array $opt){ // VOIR SI MAUVAIS TYPE $options = Array(); - if(isset($opt['name'])){ // string, rendre le nom obligatoire - $options['name'] = $opt['name']; + 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']; @@ -71,6 +73,7 @@ class Image { * List images */ public function list_images(){ + // vérifier si au moins une image $service = $this->oidentity; $images = $service->listImages(); return $images; @@ -84,6 +87,7 @@ class Image { * **/ public function image_details($id){ + //vérifier existence image $service = $this->oidentity; $image = $service->getImage($id); return $image; @@ -99,6 +103,7 @@ class Image { * options for the image creation **/ public function update_image($id, array $opt){ + //vérifier existence image $service = $this->oidentity; $image = $service->getImage($id); $options = Array(); @@ -134,6 +139,8 @@ class Image { * identifier of the image **/ public function delete_image($id){ + // si protected = true, demander de le mettre a false + // vérifier existence image $service = $this->oidentity; $service->getImage($id)->delete(); } @@ -145,6 +152,7 @@ class Image { * identifier of the image **/ public function reactivate_image($id){ + // vérifier existence image $service = $this->oidentity; $image = $service->getImage($id); $image->reactivate(); @@ -157,6 +165,7 @@ class Image { * identifier of the image **/ public function desactivate_image($id){ + // vérifier existence image $service = $this->oidentity; $image = $service->getImage($id); $image->deactivate(); @@ -172,6 +181,7 @@ class Image { * path of the image **/ public function upload_image($id, $file_name){ + // vérifier existence image $service = $this->oidentity; $image = $service->getImage($id); $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR @@ -183,12 +193,101 @@ class Image { * * @param string $id * identifier of the image - */ - public function download_image($id){ + **/ + public function download_image($id){ + // vérifier existence image $service = $this->oidentity; $image = $service->getImage($id); $stream = $image->downloadData(); return $stream; } + + /** + * Add a member to image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + **/ + public function add_member($image_id, $member_id){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $member_id = $service>getImage($image_id)->addMember($member_id); + } + + + /** + * List members of an image + * + * @param string $image_id + * identifier of the image + **/ + public function list_member($image_id, $member_id){ + // vérifier existence image + $service = $this->oidentity; + $image = $service->getImage($image_id); + $members = $image->listMembers(); + return $members; + } + + /** + * Show details of a member of an image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + **/ + public function detail_member($image_id, $member_id){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $member = $service>getImage($image_id)->getMember($member_id); + return $member; + } + + /** + * Remove a member of an image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + **/ + public function remove_member($image_id, $member_id){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $service>getImage($image_id)->getMember($member_id)->delete(); + } + + /** + * Update a member of an image + * + * @param string $image_id + * identifier of the image + * + * @param string $member_id + * identifier of the member + * + * @param string $status + * new status for the member + **/ + public function update_member($image_id, $member_id, $status){ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->oidentity; + $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); + } + } ?> -- cgit v1.2.3 From d81a376894b526b5769a553d07487b0b46fecaa2 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 11 Feb 2016 20:38:15 +0100 Subject: bugs --- server/Test/genTokenOptionsTest.php | 6 ++-- server/Test/imageTests.php | 5 ++-- server/core/App.php | 4 +-- server/core/Image.php | 55 ++++++++++++++++++++++++++++--------- 4 files changed, 50 insertions(+), 20 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/genTokenOptionsTest.php b/server/Test/genTokenOptionsTest.php index 54c22d2..d1571f0 100755 --- a/server/Test/genTokenOptionsTest.php +++ b/server/Test/genTokenOptionsTest.php @@ -1,8 +1,8 @@ listServers(true); echo 'toto'; +$image = new Image($App); $opt = Array(); $opt['name'] = "Test"; @@ -46,7 +47,7 @@ $opt['minRam'] = 10; //Liste des images -$images = $imageObject->list_images(); +$images = $image->list_images(); echo "Images présentes :"; echo "
"; diff --git a/server/core/App.php b/server/core/App.php index dafdaad..09da394 100755 --- a/server/core/App.php +++ b/server/core/App.php @@ -1,6 +1,6 @@ oidentity = $ostack->imagesV2($options); - //$this->plugins = $apiP; + * @throws [Type] [] + * + * @return Image + */ + public function __construct($app){ + $this->app = $app; + $this->libClass = $app->getLibClass("Image"); } + + /** * Details about an image * -- cgit v1.2.3