Modifications qui seront validées :
modifié : server/core/Image.php modifié : server/test.php
This commit is contained in:
parent
721620a549
commit
83fd3eb19d
2 changed files with 114 additions and 91 deletions
|
@ -1,96 +1,108 @@
|
|||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
date_default_timezone_set("Europe/Paris");
|
||||
require '../vendor/autoload.php';
|
||||
//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);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
@ -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 "</br>";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue