summaryrefslogtreecommitdiff
path: root/server/core/Image.php
diff options
context:
space:
mode:
Diffstat (limited to 'server/core/Image.php')
-rw-r--r--server/core/Image.php321
1 files changed, 321 insertions, 0 deletions
diff --git a/server/core/Image.php b/server/core/Image.php
index 8d1c8b6..3001eea 100644
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -1 +1,322 @@
+<?php
+
+//require 'CoreInterface.php';
+
+/**
+* File containing the Image Class.
+*
+* @version 1.0 Initialisation of this file
+* @since 1.0 Core application's file
+*
+* @author Yogg 'yogg at epsina . com'
+*
+* @todo Complete the functions with errors detection and finish the descriptions
+*/
+
+/**
+* Image Class of the back-end application
+*
+* ADD CLASS DESCRIPTION
+*
+*/
+class image{
+ //implements Core
+
+ /** @var App $app protected, contains the main app object */
+ protected $app;
+
+ /** @var OpenStack\Identity $libClass protected, contains the library Identity object */
+ protected $libClass;
+
+ /** @var array $actions protected, contains the functions which can be call by the front-end */
+ protected $actions = array();
+
+
+ /**
+ * Image constructor
+ *
+ * @param App $app the main app object
+ *
+ * @throws [Type] [<description>]
+ *
+ * @return Image
+ */
+ public function __construct($app){
+ $this->app = $app;
+ $this->libClass = $app->getLibClass("Image");
+ }
+
+
+
+
+ /**
+ * 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, 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);
+
+ return $image;
+ }
+
+ /*
+ * List images
+ */
+ public function list_images(){
+ // vérifier si au moins une image
+ $service = $this->oidentity;
+ $images = $service->listImages();
+ return $images;
+ }
+
+ /**
+ * Details about an image
+ *
+ * @param string $id
+ * identifier of the image
+ *
+ **/
+ public function image_details($id){
+ //vérifier existence image
+ $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){
+ //vérifier existence image
+ $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){
+ // si protected = true, demander de le mettre a false
+ // vérifier existence image
+ $service = $this->oidentity;
+ $service->getImage($id)->delete();
+ }
+
+ /**
+ * Resactive an image
+ *
+ * @param string $id
+ * identifier of the image
+ **/
+ public function reactivate_image($id){
+ // vérifier existence image
+ $service = $this->oidentity;
+ $image = $service->getImage($id);
+ $image->reactivate();
+ }
+
+ /**
+ * Desactive an image
+ *
+ * @param string $id
+ * identifier of the image
+ **/
+ public function desactivate_image($id){
+ // vérifier existence image
+ $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){
+ // vérifier existence image
+ $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){
+ // 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);
+ }
+
+}
+?>