istic-openstack/server/core/Image.php

321 lines
7 KiB
PHP
Raw Normal View History

<?php
2016-02-11 20:38:15 +01:00
/**
* 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
*/
2016-02-14 18:41:45 +01:00
use OpenStack\Common\Error;
2016-02-11 20:38:15 +01:00
/**
* Image Class of the back-end application
*
* ADD CLASS DESCRIPTION
*
*/
2016-02-17 16:09:44 +01:00
class image {
2016-02-11 20:38:15 +01:00
//implements Core
/** @var App $app protected, contains the main app object */
protected $app;
2016-02-11 20:38:15 +01:00
/** @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();
2016-02-11 20:38:15 +01:00
/**
2016-02-11 20:38:15 +01:00
* Image constructor
*
2016-02-11 20:38:15 +01:00
* @param App $app the main app object
*
2016-02-11 20:38:15 +01:00
* @throws [Type] [<description>]
*
* @return Image
*/
public function __construct($app){
$this->app = $app;
$this->libClass = $app->getLibClass("Image");
}
2016-02-17 16:09:44 +01:00
private $images = array();
2016-02-11 20:38:15 +01:00
/**
* Details about an image
*
* @param array $opt
* options for the image creation
*
**/
2016-02-17 16:09:44 +01:00
public function createImage(array $opt){
// VOIR SI MAUVAIS TYPE
$options = Array();
2016-02-07 10:29:12 +01:00
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'];
}
2016-02-14 18:41:45 +01:00
$image = $this->libClass->createImage($options);
return $image;
}
2016-02-14 18:41:45 +01:00
/**
* List the images of the server
*
* @return the list with all images on the server
*/
2016-02-17 16:09:44 +01:00
public function listImage(){
2016-02-07 10:29:12 +01:00
// vérifier si au moins une image
2016-02-14 18:41:45 +01:00
$this->libClass->listImages();
//return $l;
}
/**
* Details about an image
*
* @param string $id
* identifier of the image
*
**/
2016-02-17 16:09:44 +01:00
public function detailsImage($id){
2016-02-07 10:29:12 +01:00
//vérifier existence image
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
$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
**/
2016-02-17 16:09:44 +01:00
public function updateImage($id, array $opt){
2016-02-07 10:29:12 +01:00
//vérifier existence image
2016-02-14 18:41:45 +01:00
$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);
return $image;
}
/**
* Delete an image
*
* @param string $id
* identifier of the image
**/
2016-02-17 16:09:44 +01:00
public function imageDelete($id){
2016-02-07 10:29:12 +01:00
// si protected = true, demander de le mettre a false
// vérifier existence image
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
$service->getImage($id)->delete();
}
/**
* Resactive an image
*
* @param string $id
* identifier of the image
**/
2016-02-17 16:09:44 +01:00
public function reactivateImage($id){
2016-02-07 10:29:12 +01:00
// vérifier existence image
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
$image = $service->getImage($id);
$image->reactivate();
}
/**
* Desactive an image
*
* @param string $id
* identifier of the image
**/
2016-02-17 16:09:44 +01:00
public function desactivateImage($id){
2016-02-07 10:29:12 +01:00
// vérifier existence image
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
$image = $service->getImage($id);
$image->deactivate();
}
/**
* Upload an image
*
* @param string $id
* identifier of the image
*
* @param string $file_name
* path of the image
**/
2016-02-17 16:09:44 +01:00
public function uploadImage($id, $file_name){
2016-02-07 10:29:12 +01:00
// vérifier existence image
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
$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
2016-02-07 10:29:12 +01:00
**/
2016-02-17 16:09:44 +01:00
public function downloadImage($id){
2016-02-07 10:29:12 +01:00
// vérifier existence image
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
$image = $service->getImage($id);
$stream = $image->downloadData();
return $stream;
}
2016-02-07 10:29:12 +01:00
/**
* Add a member to image
*
* @param string $image_id
* identifier of the image
*
* @param string $member_id
* identifier of the member
**/
2016-02-17 16:09:44 +01:00
public function addMemberImage($image_id, $member_id){
2016-02-07 10:29:12 +01:00
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
2016-02-07 10:29:12 +01:00
$member_id = $service>getImage($image_id)->addMember($member_id);
}
/**
* List members of an image
*
* @param string $image_id
* identifier of the image
**/
2016-02-17 16:09:44 +01:00
public function listMemberImage($image_id, $member_id){
2016-02-07 10:29:12 +01:00
// vérifier existence image
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
2016-02-07 10:29:12 +01:00
$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
**/
2016-02-17 16:09:44 +01:00
public function detailMemberImage($image_id, $member_id){
2016-02-07 10:29:12 +01:00
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
2016-02-07 10:29:12 +01:00
$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
**/
2016-02-17 16:09:44 +01:00
public function removeMemberImage($image_id, $member_id){
2016-02-07 10:29:12 +01:00
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
2016-02-07 10:29:12 +01:00
$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
**/
2016-02-17 16:09:44 +01:00
public function updateMemberImage($image_id, $member_id, $status){
2016-02-07 10:29:12 +01:00
// vérifier existence image
// on doit être le proprio de l'image
// vérifier membre existe
2016-02-14 18:41:45 +01:00
$service = $this->libClass;
2016-02-07 10:29:12 +01:00
$member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status);
}
}
?>