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 @@ "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); +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 create_image(array $opt){ - $service = $openstack->imagesV2(); + public function image_details($id){ + $service = $openstack->imagesV2(); + $image = $service->getImage($id); + return $image; + } - // 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; + 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(); -} - - ?> diff --git a/server/test.php b/server/test.php index 16555e4..4e6743f 100644 --- a/server/test.php +++ b/server/test.php @@ -2,6 +2,7 @@ ini_set('display_errors', 1); date_default_timezone_set("Europe/Paris"); require 'vendor/autoload.php'; +include("core/Image.php"); $options = Array(); $options["user"] = Array("name"=>"admin", "password"=>"ae5or6cn", "domain"=>["id"=>"Default"]); @@ -26,11 +27,21 @@ $openstack = new OpenStack\OpenStack($options); ] ]); */ -$compute = $openstack->computeV2(["region" => "RegionOne"]); +//$compute = $openstack->computeV2(["region" => "RegionOne"]); + +//$image= $openstack->imagesV2(["region" => "RegionOne"]); +$optImage = Array(); +$optImage["region"] = "RegionOne"; +$image = new Image($openstack, $optImage); + + +$images = $image->list_images(); + //var_dump($compute->client); //$servers = $compute->listServers(true); -//foreach($servers as $server){ -// echo $server->id." !!! "; -// echo $server->name." !!! "; -//} +foreach($images as $i){ + //echo $server->id." !!! "; + echo $i->name; + echo "
"; +}