list_images and images_details

This commit is contained in:
yogg@epsina.com 2016-01-31 11:36:58 +01:00
parent 83fd3eb19d
commit 325362a386
2 changed files with 35 additions and 17 deletions

View file

@ -22,10 +22,8 @@ class Image {
} }
public function create_image(array $opt){ public function create_image(array $opt){
$service = $openstack->imagesV2();
// OPTIONS A VOIR // OPTIONS A VOIR
$image = $service->createImage([ $image = $this->oidentity->createImage([
'name' => $opt[name], 'name' => $opt[name],
'tags' => ['{tag1}', '{tag2}'], // A VOIR 'tags' => ['{tag1}', '{tag2}'], // A VOIR
'containerFormat' => $opt[containerFormat], 'containerFormat' => $opt[containerFormat],
@ -43,20 +41,27 @@ class Image {
* List images * List images
*/ */
public function list_images(){ public function list_images(){
$images = $this->oidentity->listImages(); $service = $this->oidentity;
$images = $service->listImages();
return $images; return $images;
} }
/*
* Details about an image
*
* @param string $id
* identifier of the image
*
*/
public function image_details($id){ public function image_details($id){
$service = $openstack->imagesV2(); $service = $this->oidentity;
$image = $service->getImage($id); $image = $service->getImage($id);
return $image; return $image;
} }
public function update_image($id, array $opt){ public function update_image($id, array $opt){
$service = $openstack->imagesV2(); $service = $this->oidentity;
//OPTIONS A VOIR //OPTIONS A VOIR
$image = $service->getImage($id); $image = $service->getImage($id);
@ -73,26 +78,27 @@ class Image {
// RETOUR A VOIR // RETOUR A VOIR
public function delete_image($name){ public function delete_image($name){
$openstack->imagesV2()->getImage($name)->delete(); $service = $this->oidentity;
$service->getImage($name)->delete();
} }
// RETOUR A VOIR // RETOUR A VOIR
public function reactivate_image($id){ public function reactivate_image($id){
$service = $openstack->imagesV2(); $service = $this->oidentity;
$image = $service->getImage($id); $image = $service->getImage($id);
$image->reactivate(); $image->reactivate();
} }
// RETOUR A VOIR // RETOUR A VOIR
public function desactivate_function($id){ public function desactivate_function($id){
$service = $openstack->imagesV2(); $service = $this->oidentity;
$image = $service->getImage($id); $image = $service->getImage($id);
$image->deactivate(); $image->deactivate();
} }
// RETOUR A VOIR // RETOUR A VOIR
public function upload_image($id, $file_name){ public function upload_image($id, $file_name){
$service = $openstack->imagesV2(); $service = $this->oidentity;
$image = $service->getImage($id); $image = $service->getImage($id);
$stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR
$image->uploadData($stream); $image->uploadData($stream);
@ -100,7 +106,7 @@ class Image {
// RETOUR A VOIR // RETOUR A VOIR
public function download_image($id){ public function download_image($id){
$service = $openstack->imagesV2(); $service = $this->oidentity;
$image = $service->getImage($id); $image = $service->getImage($id);
$stream = $image->downloadData(); $stream = $image->downloadData();
} }

View file

@ -16,7 +16,6 @@ $openstack = new OpenStack\OpenStack($options);
// Since usernames will not be unique across an entire OpenStack installation, // Since usernames will not be unique across an entire OpenStack installation,
// when authenticating with them you must also provide your domain ID. You do // when authenticating with them you must also provide your domain ID. You do
// not have to do this if you authenticate with a user ID. // not have to do this if you authenticate with a user ID.
/*$token = $identity->generateToken([ /*$token = $identity->generateToken([
'user' => [ 'user' => [
'name' => 'admin', 'name' => 'admin',
@ -28,20 +27,33 @@ $openstack = new OpenStack\OpenStack($options);
]); ]);
*/ */
//$compute = $openstack->computeV2(["region" => "RegionOne"]); //$compute = $openstack->computeV2(["region" => "RegionOne"]);
//$image= $openstack->imagesV2(["region" => "RegionOne"]); //$image= $openstack->imagesV2(["region" => "RegionOne"]);
//var_dump($compute->client);
//$servers = $compute->listServers(true);
// Initialisation Image()
$optImage = Array(); $optImage = Array();
$optImage["region"] = "RegionOne"; $optImage["region"] = "RegionOne";
$image = new Image($openstack, $optImage); $image = new Image($openstack, $optImage);
//Liste des images
$images = $image->list_images(); $images = $image->list_images();
//var_dump($compute->client); echo "Images présentes :";
//$servers = $compute->listServers(true); echo "</br>";
foreach($images as $i){ foreach($images as $i){
//echo $server->id." !!! ";
echo $i->name; echo $i->name;
if($i->name == "TinyCore"){
$id_image = $i->id;
}
echo "</br>"; echo "</br>";
} }
echo "</br>";
// Détails Image
$details = $image->image_details($id_image);
?>