istic-openstack/server/core/Image.php
2016-01-31 18:28:09 +01:00

157 lines
3.1 KiB
PHP

<?php
ini_set('display_errors', 1);
date_default_timezone_set("Europe/Paris");
//require '../vendor/autoload.php';
class Image {
protected $oidentity;
//protected $plugins;
/**
* Constructor
*
* @param $openstack
*
* @param $options
*
**/
public function __construct($ostack, $options){ //, $apiP
$this->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 COMMENT RENDRE LES CHAMPS OPTIONNELS (SAUF NAME)
$image = $this->oidentity->createImage([
'name' => $opt['name'],
//'tags' => $opt['tag'], // A VOIR COMMENT CA MARCHE
'containerFormat' => $opt['containerFormat'],
'diskFormat' => $opt['diskFormat'],
'visibility' => $opt['visibility'],
'minDisk' => $opt['minDisk'],
'protected' => $opt['protected'],
'minRam' => $opt['minRam'],
]);
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);
$image->update([
'minDisk' => $opt['minDisk'],
'minRam' => $opt['minRam'],
'name' => $opt['name'],
'protected' => $opt['protected'],
'visibility' => $opt['visibility'],
]);
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;
}
}
?>