summaryrefslogtreecommitdiff
path: root/server/core
diff options
context:
space:
mode:
authoryogg@epsina.com <evan.pisani@etudiant.univ-rennes1.fr>2016-01-31 10:56:52 +0100
committeryogg@epsina.com <evan.pisani@etudiant.univ-rennes1.fr>2016-01-31 10:56:52 +0100
commit83fd3eb19dc9943d3ad53154f330ed4782ccff81 (patch)
treee02c16c79a49434d168e7d992ba2d71bb3258d51 /server/core
parent721620a549f38ca13f82351ae12d777f929b7372 (diff)
Modifications qui seront validées :
modifié : server/core/Image.php modifié : server/test.php
Diffstat (limited to 'server/core')
-rw-r--r--server/core/Image.php194
1 files changed, 103 insertions, 91 deletions
diff --git a/server/core/Image.php b/server/core/Image.php
index 984f03a..242bb5f 100644
--- a/server/core/Image.php
+++ b/server/core/Image.php
@@ -1,96 +1,108 @@
<?php
ini_set('display_errors', 1);
date_default_timezone_set("Europe/Paris");
-require '../vendor/autoload.php';
-
-$options = Array();
-$options["user"] = Array("name"=>"admin", "password"=>"ae5or6cn", "domain"=>["id"=>"Default"]);
-$options["scope"] = Array("project"=>Array("name"=>"admin", "domain"=>["id"=>"Default"]));
-$options["authUrl"] = "http://148.60.11.31:5000/v3";
-
-$openstack = OpenStack\OpenStack($options);
-
-
-public function create_image(array $opt){
- $service = $openstack->imagesV2();
-
- // OPTIONS A VOIR
- $image = $service->createImage([
- 'name' => $opt[name],
- 'tags' => ['{tag1}', '{tag2}'], // A VOIR
- 'containerFormat' => $opt[containerFormat],
- 'diskFormat' => $opt[diskFormat],
- 'visibility' => $opt[visibility],
- 'minDisk' => 10,
- 'protected' => true,
- 'minRam' => 10,
- ]);
-
- return $image;
+//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;
+ }
+
+ public function create_image(array $opt){
+ $service = $openstack->imagesV2();
+
+ // OPTIONS A VOIR
+ $image = $service->createImage([
+ 'name' => $opt[name],
+ 'tags' => ['{tag1}', '{tag2}'], // A VOIR
+ 'containerFormat' => $opt[containerFormat],
+ 'diskFormat' => $opt[diskFormat],
+ 'visibility' => $opt[visibility],
+ 'minDisk' => 10,
+ 'protected' => true,
+ 'minRam' => 10,
+ ]);
+
+ return $image;
+ }
+
+ /*
+ * List images
+ */
+ public function list_images(){
+ $images = $this->oidentity->listImages();
+ return $images;
+ }
+
+
+ public function image_details($id){
+ $service = $openstack->imagesV2();
+ $image = $service->getImage($id);
+ return $image;
+ }
+
+
+ public function update_image($id, array $opt){
+ $service = $openstack->imagesV2();
+
+ //OPTIONS A VOIR
+ $image = $service->getImage($id);
+ $image->update([
+ 'minDisk' => 1,
+ 'minRam' => 1,
+ 'name' => $opt[name],
+ 'protected' => false,
+ 'visibility' => $opt[visibility],
+ ]);
+
+ return $image;
+ }
+
+ // RETOUR A VOIR
+ public function delete_image($name){
+ $openstack->imagesV2()->getImage($name)->delete();
+ }
+
+ // RETOUR A VOIR
+ public function reactivate_image($id){
+ $service = $openstack->imagesV2();
+ $image = $service->getImage($id);
+ $image->reactivate();
+ }
+
+ // RETOUR A VOIR
+ public function desactivate_function($id){
+ $service = $openstack->imagesV2();
+ $image = $service->getImage($id);
+ $image->deactivate();
+ }
+
+ // RETOUR A VOIR
+ public function upload_image($id, $file_name){
+ $service = $openstack->imagesV2();
+ $image = $service->getImage($id);
+ $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
+ $image->uploadData($stream);
+ }
+
+ // RETOUR A VOIR
+ public function download_image($id){
+ $service = $openstack->imagesV2();
+ $image = $service->getImage($id);
+ $stream = $image->downloadData();
+ }
}
-
-public function list_image(){
- $images = $openstack->imagesV2()->listImages();
- return $images;
-}
-
-
-public function image_details($id){
- $service = $openstack->imagesV2();
- $image = $service->getImage($id);
- return $image;
-}
-
-
-public function update_image($id, array $opt){
- $service = $openstack->imagesV2();
-
- //OPTIONS A VOIR
- $image = $service->getImage($id);
- $image->update([
- 'minDisk' => 1,
- 'minRam' => 1,
- 'name' => $opt[name],
- 'protected' => false,
- 'visibility' => $opt[visibility],
- ]);
-
- return $image;
-}
-
-// RETOUR A VOIR
-public function delete_image($name){
- $openstack->imagesV2()->getImage($name)->delete();
-}
-
-// RETOUR A VOIR
-public function reactivate_image($id){
- $service = $openstack->imagesV2();
- $image = $service->getImage($id);
- $image->reactivate();
-}
-
-// RETOUR A VOIR
-public function desactivate_function($id){
- $service = $openstack->imagesV2();
- $image = $service->getImage($id);
- $image->deactivate();
-}
-
-// RETOUR A VOIR
-public function upload_image($id, $file_name){
- $service = $openstack->imagesV2();
- $image = $service->getImage($id);
- $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
- $image->uploadData($stream);
-}
-
-// RETOUR A VOIR
-public function download_image($id){
- $service = $openstack->imagesV2();
- $image = $service->getImage($id);
- $stream = $image->downloadData();
-}
-
-
?>