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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
<?php
/**
* File containing the FloatingIp Class.
*
* @version 1.0 Initialisation of this file
* @since 1.0 Core application's file
*
* @author Evan Pisani 'yogg at epsina . com'
*
* @todo Complete the functions with errors detection and finish the descriptions
*/
use OpenCloud\Common\Error\BadResponseError;
use OpenCloud\Common\Error\BaseError;
use OpenCloud\Common\Error\NotImplementedError;
use OpenCloud\Common\Error\UserInputError;
//include("CoreInterface.php");
/**
* Image Class of the back-end application
*
* Management of images
*
*/
class floatingIp {
/** @var App $app protected, contains the main app object */
protected $app;
/** @var OpenStack\Identity $libClass protected, contains the library Identity object */
protected $libClass;
/**
* floatingip constructor
*
* @param App $app the main app object
*
* @return floatingip
*/
public function __construct($app){
if(!isset($app)){
$this->app->setOutput("Error", "Incorrect parameter app");
}
$this->app = $app;
$this->libClass = $app->getLibClass("FloatingIp");
}
/**
* Execute an action
*
* @param String $action name of another function of this class
*
* @return void
*/
public function action($action){
$this->{$action.""}();
}
/**
* List floatingip
*
* @return list of the floatingip
*/
private function listFloatingIp(){
try{
$result = array();
$l = $this->libClass->listFloatingIps();
error_log(var_export($l, true), 0);
foreach ($l as $tmp) {
$result[] = $tmp;
}
$this->app->setOutput("FloatingIp", $result);
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
}
/**
* Create a new floating IP adress
*
* @param array $opt Options for the floating ip creation (floatingipo and floating network id are required, others are optionals)
*
* @return floatingip
*/
private function createFloatingIp(){
$opt = $this->app->getPostParam("opt");
if(!isset($opt)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
$floatingip = $this->libClass->createFloatingIp($opt);
echo 'YOLO';
if(!isset($floatingip)){
$this->app->setOutput("Error", "Unknowing error during floating ip creation");
}
else{
$this->app->setOutput("FloatingIp", $floatingip);
}
}catch(BadResponseError $e){
echo $e."</br>";
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
echo $e."</br>";
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
echo $e."</br>";
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
echo $e."</br>";
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
echo $e->getMessage()."</br>";
$this->app->getErrorInstance()->OtherException($e);
}
}
/**
* Show floatingip details
*
* @param String id the id of the floatingip
*
* @return floatingip details
*/
private function getFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
/*$l = $this->listFloatingIp();
$res = null;
foreach ($l as $f) {
if($f['id']==$id){
$res = $f;
}
}
if(!isset($f)){
$this->app->setOutput("Error", "Unknow id");
}
else{*/
$res = $this->libClass->getFloatingIp($id);
$this->app->setOutput("FloatingIp", $res);
//}
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
}
/**
* Update floating ip
*
* @param id the id of the floatingip to update
*
* @return Image
*/
private function updateFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
$floatingips = listFloatingIps();
$floatingIp = null;
foreach ($floatingips as $f) {
if($f['id'] == $id){
$floatingIp = $f;
}
}
if(!isset($floatingIp)){
$this->app->setOutput("Error", "Unknowing floatingip id");
}
$floatingip->update();
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
}
/**
* Delete a floating ip
*
* @param string floatingip_id the floating-ip id to delete
*
* @return void
*/
private function deleteFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
$floatingips = listFloatingIps();
$floatingIp = null;
foreach ($floatingips as $f) {
if($f['id'] == $id){
$floatingIp = $f;
}
}
if(!isset($floatingIp)){
$this->app->setOutput("Error", "Unknowing floatingip id");
}
$floatingip->delete();
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
}
/**
* Retrieve a floating ip
*
* @param string floatingip_id the floating-ip id to retrieve
*
* @return void
*/
private function retrieveFloatingIp(){
$id = $this->app->getPostParam("id");
if(!isset($id)){
$this->app->setOutput("Error", "Incorrect parameter opt");
}
try{
$floatingips = listFloatingIps();
$floatingIp = null;
foreach ($floatingips as $f) {
if($f['id'] == $id){
$floatingIp = $f;
}
}
if(!isset($floatingIp)){
$this->app->setOutput("Error", "Unknowing floatingip id");
}
$floatingip->retrieve();
}catch(BadResponseError $e){
$this->app->getErrorInstance()->BadResponseHandler($e);
}catch(UserInputError $e){
$this->app->getErrorInstance()->UserInputHandler($e);
}catch(BaseError $e){
$this->app->getErrorInstance()->BaseErrorHandler($e);
}catch(NotImplementedError $e){
$this->app->getErrorInstance()->NotImplementedHandler($e);
}catch(Exception $e){
$this->app->getErrorInstance()->OtherException($e);
}
}
}
|