1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
<?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;
}
}
?>
|