From b39f5c1cd4631be3259b272e1f6cbe9b4915410b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 4 Feb 2016 23:48:43 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20fonctionnalit=C3=A9s=20de=20base?= =?UTF-8?q?=20des=20images,=20sans=20gestion=20la=20d'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(-) 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; + } +} +?>