|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_Service |
|
17 * @subpackage Rackspace |
|
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 */ |
|
21 |
|
22 require_once 'Zend/Service/Rackspace/Abstract.php'; |
|
23 require_once 'Zend/Service/Rackspace/Servers/Server.php'; |
|
24 require_once 'Zend/Service/Rackspace/Servers/ServerList.php'; |
|
25 require_once 'Zend/Service/Rackspace/Servers/Image.php'; |
|
26 require_once 'Zend/Service/Rackspace/Servers/ImageList.php'; |
|
27 require_once 'Zend/Service/Rackspace/Servers/SharedIpGroup.php'; |
|
28 require_once 'Zend/Service/Rackspace/Servers/SharedIpGroupList.php'; |
|
29 require_once 'Zend/Validate/Ip.php'; |
|
30 |
|
31 class Zend_Service_Rackspace_Servers extends Zend_Service_Rackspace_Abstract |
|
32 { |
|
33 const LIMIT_FILE_SIZE = 10240; |
|
34 const LIMIT_NUM_FILE = 5; |
|
35 const ERROR_SERVICE_UNAVAILABLE = 'The service is unavailable'; |
|
36 const ERROR_UNAUTHORIZED = 'Unauthorized'; |
|
37 const ERROR_OVERLIMIT = 'You reached the limit of requests, please wait some time before retry'; |
|
38 const ERROR_PARAM_NO_ID = 'You must specify the item\'s id'; |
|
39 const ERROR_PARAM_NO_NAME = 'You must specify the name'; |
|
40 const ERROR_PARAM_NO_SERVERID = 'You must specify the server Id'; |
|
41 const ERROR_PARAM_NO_IMAGEID = 'You must specify the server\'s image ID'; |
|
42 const ERROR_PARAM_NO_FLAVORID = 'You must specify the server\'s flavor ID'; |
|
43 const ERROR_PARAM_NO_ARRAY = 'You must specify an array of parameters'; |
|
44 const ERROR_PARAM_NO_WEEKLY = 'You must specify a weekly backup schedule'; |
|
45 const ERROR_PARAM_NO_DAILY = 'You must specify a daily backup schedule'; |
|
46 const ERROR_ITEM_NOT_FOUND = 'The item specified doesn\'t exist.'; |
|
47 const ERROR_NO_FILE_EXISTS = 'The file specified doesn\'t exist'; |
|
48 const ERROR_LIMIT_FILE_SIZE = 'You reached the size length of a file'; |
|
49 const ERROR_IN_PROGRESS = 'The item specified is still in progress'; |
|
50 const ERROR_BUILD_IN_PROGRESS = 'The build is still in progress'; |
|
51 const ERROR_RESIZE_NOT_ALLOWED = 'The resize is not allowed'; |
|
52 /** |
|
53 * Get the list of the servers |
|
54 * If $details is true returns detail info |
|
55 * |
|
56 * @param boolean $details |
|
57 * @return Zend_Service_Rackspace_Servers_ServerList|boolean |
|
58 */ |
|
59 public function listServers($details=false) |
|
60 { |
|
61 $url= '/servers'; |
|
62 if ($details) { |
|
63 $url.= '/detail'; |
|
64 } |
|
65 $result= $this->httpCall($this->getManagementUrl().$url,'GET'); |
|
66 $status= $result->getStatus(); |
|
67 switch ($status) { |
|
68 case '200' : |
|
69 case '203' : // break intentionally omitted |
|
70 $servers= json_decode($result->getBody(),true); |
|
71 return new Zend_Service_Rackspace_Servers_ServerList($this,$servers['servers']); |
|
72 case '503' : |
|
73 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
74 break; |
|
75 case '401' : |
|
76 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
77 break; |
|
78 case '413' : |
|
79 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
80 break; |
|
81 default: |
|
82 $this->errorMsg= $result->getBody(); |
|
83 break; |
|
84 } |
|
85 $this->errorCode= $status; |
|
86 return false; |
|
87 } |
|
88 /** |
|
89 * Get the specified server |
|
90 * |
|
91 * @param string $id |
|
92 * @return Zend_Service_Rackspace_Servers_Server |
|
93 */ |
|
94 public function getServer($id) |
|
95 { |
|
96 if (empty($id)) { |
|
97 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
98 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
99 } |
|
100 $result= $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id),'GET'); |
|
101 $status= $result->getStatus(); |
|
102 switch ($status) { |
|
103 case '200' : |
|
104 case '203' : // break intentionally omitted |
|
105 $server = json_decode($result->getBody(),true); |
|
106 return new Zend_Service_Rackspace_Servers_Server($this,$server['server']); |
|
107 case '503' : |
|
108 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
109 break; |
|
110 case '401' : |
|
111 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
112 break; |
|
113 case '404' : |
|
114 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
115 break; |
|
116 case '413' : |
|
117 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
118 break; |
|
119 default: |
|
120 $this->errorMsg= $result->getBody(); |
|
121 break; |
|
122 } |
|
123 $this->errorCode= $status; |
|
124 return false; |
|
125 } |
|
126 /** |
|
127 * Create a new server |
|
128 * |
|
129 * The required parameters are specified in $data (name, imageId, falvorId) |
|
130 * The $files is an associative array with 'serverPath' => 'localPath' |
|
131 * |
|
132 * @param array $data |
|
133 * @param array $metadata |
|
134 * @param array $files |
|
135 * @return Zend_Service_Rackspace_Servers_Server|boolean |
|
136 */ |
|
137 public function createServer(array $data, $metadata=array(),$files=array()) |
|
138 { |
|
139 if (empty($data) || !is_array($data) || !is_array($metadata) || !is_array($files)) { |
|
140 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
141 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ARRAY); |
|
142 } |
|
143 if (!isset($data['name'])) { |
|
144 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
145 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME); |
|
146 } |
|
147 if (!isset($data['flavorId'])) { |
|
148 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
149 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_FLAVORID); |
|
150 } |
|
151 if (!isset($data['imageId'])) { |
|
152 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
153 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_IMAGEID); |
|
154 } |
|
155 if (count($files)>self::LIMIT_NUM_FILE) { |
|
156 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
157 throw new Zend_Service_Rackspace_Exception('You can attach '.self::LIMIT_NUM_FILE.' files maximum'); |
|
158 } |
|
159 if (!empty($metadata)) { |
|
160 $data['metadata']= $metadata; |
|
161 } |
|
162 $data['flavorId']= (integer) $data['flavorId']; |
|
163 $data['imageId']= (integer) $data['imageId']; |
|
164 if (!empty($files)) { |
|
165 foreach ($files as $serverPath => $filePath) { |
|
166 if (!file_exists($filePath)) { |
|
167 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
168 throw new Zend_Service_Rackspace_Exception( |
|
169 sprintf("The file %s doesn't exist",$filePath)); |
|
170 } |
|
171 $content= file_get_contents($filePath); |
|
172 if (strlen($content) > self::LIMIT_FILE_SIZE) { |
|
173 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
174 throw new Zend_Service_Rackspace_Exception( |
|
175 sprintf("The size of the file %s is greater than the max size of %d bytes", |
|
176 $filePath,self::LIMIT_FILE_SIZE)); |
|
177 } |
|
178 $data['personality'][] = array ( |
|
179 'path' => $serverPath, |
|
180 'contents' => base64_encode(file_get_contents($filePath)) |
|
181 ); |
|
182 } |
|
183 } |
|
184 $result = $this->httpCall($this->getManagementUrl().'/servers','POST', |
|
185 null,null,json_encode(array ('server' => $data))); |
|
186 $status = $result->getStatus(); |
|
187 switch ($status) { |
|
188 case '200' : |
|
189 case '202' : // break intentionally omitted |
|
190 $server = json_decode($result->getBody(),true); |
|
191 return new Zend_Service_Rackspace_Servers_Server($this,$server['server']); |
|
192 case '503' : |
|
193 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
194 break; |
|
195 case '401' : |
|
196 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
197 break; |
|
198 case '404' : |
|
199 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
200 break; |
|
201 case '413' : |
|
202 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
203 break; |
|
204 default: |
|
205 $this->errorMsg= $result->getBody(); |
|
206 break; |
|
207 } |
|
208 $this->errorCode= $status; |
|
209 return false; |
|
210 } |
|
211 /** |
|
212 * Change the name or the admin password for a server |
|
213 * |
|
214 * @param string $id |
|
215 * @param string $name |
|
216 * @param string $password |
|
217 * @return boolean |
|
218 */ |
|
219 protected function updateServer($id,$name=null,$password=null) |
|
220 { |
|
221 if (empty($id)) { |
|
222 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
223 throw new Zend_Service_Rackspace_Exception('You must specify the ID of the server'); |
|
224 } |
|
225 if (empty($name) && empty($password)) { |
|
226 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
227 throw new Zend_Service_Rackspace_Exception("You must specify the new name or password of server"); |
|
228 } |
|
229 $data= array(); |
|
230 if (!empty($name)) { |
|
231 $data['name']= $name; |
|
232 } |
|
233 if (!empty($password)) { |
|
234 $data['adminPass']= $password; |
|
235 } |
|
236 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id),'PUT', |
|
237 null,null,json_encode(array('server' => $data))); |
|
238 $status = $result->getStatus(); |
|
239 switch ($status) { |
|
240 case '204' : // break intentionally omitted |
|
241 return true; |
|
242 case '503' : |
|
243 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
244 break; |
|
245 case '401' : |
|
246 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
247 break; |
|
248 case '404' : |
|
249 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
250 break; |
|
251 case '409' : |
|
252 $this->errorMsg= self::ERROR_IN_PROGRESS; |
|
253 break; |
|
254 case '413' : |
|
255 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
256 break; |
|
257 default: |
|
258 $this->errorMsg= $result->getBody(); |
|
259 break; |
|
260 } |
|
261 $this->errorCode= $status; |
|
262 return false; |
|
263 } |
|
264 /** |
|
265 * Change the server's name |
|
266 * |
|
267 * @param string $id |
|
268 * @param string $name |
|
269 * @return boolean |
|
270 */ |
|
271 public function changeServerName($id,$name) |
|
272 { |
|
273 if (empty($id)) { |
|
274 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
275 throw new Zend_Service_Rackspace_Exception('You must specify the ID of the server'); |
|
276 } |
|
277 if (empty($name)) { |
|
278 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
279 throw new Zend_Service_Rackspace_Exception("You must specify the new name of the server"); |
|
280 } |
|
281 return $this->updateServer($id, $name); |
|
282 } |
|
283 /** |
|
284 * Change the admin password of the server |
|
285 * |
|
286 * @param string $id |
|
287 * @param string $password |
|
288 * @return boolean |
|
289 */ |
|
290 public function changeServerPassword($id,$password) |
|
291 { |
|
292 if (empty($id)) { |
|
293 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
294 throw new Zend_Service_Rackspace_Exception('You must specify the ID of the server'); |
|
295 } |
|
296 if (empty($password)) { |
|
297 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
298 throw new Zend_Service_Rackspace_Exception("You must specify the new password of the server"); |
|
299 } |
|
300 return $this->updateServer($id, null,$password); |
|
301 } |
|
302 /** |
|
303 * Delete a server |
|
304 * |
|
305 * @param string $id |
|
306 * @return boolean |
|
307 */ |
|
308 public function deleteServer($id) |
|
309 { |
|
310 if (empty($id)) { |
|
311 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
312 throw new Zend_Service_Rackspace_Exception('You must specify the ID of the server'); |
|
313 } |
|
314 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id),'DELETE'); |
|
315 $status = $result->getStatus(); |
|
316 switch ($status) { |
|
317 case '202' : // break intentionally omitted |
|
318 return true; |
|
319 case '503' : |
|
320 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
321 break; |
|
322 case '401' : |
|
323 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
324 break; |
|
325 case '404' : |
|
326 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
327 break; |
|
328 case '409' : |
|
329 $this->errorMsg= self::ERROR_IN_PROGRESS; |
|
330 break; |
|
331 case '413' : |
|
332 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
333 break; |
|
334 default: |
|
335 $this->errorMsg= $result->getBody(); |
|
336 break; |
|
337 } |
|
338 $this->errorCode= $status; |
|
339 return false; |
|
340 } |
|
341 /** |
|
342 * Get the server's IPs (public and private) |
|
343 * |
|
344 * @param string $id |
|
345 * @return array|boolean |
|
346 */ |
|
347 public function getServerIp($id) |
|
348 { |
|
349 $result= $this->getServer($id); |
|
350 if ($result===false) { |
|
351 return false; |
|
352 } |
|
353 $result= $result->toArray(); |
|
354 return $result['addresses']; |
|
355 } |
|
356 /** |
|
357 * Get the Public IPs of a server |
|
358 * |
|
359 * @param string $id |
|
360 * @return array|boolean |
|
361 */ |
|
362 public function getServerPublicIp($id) |
|
363 { |
|
364 $addresses= $this->getServerIp($id); |
|
365 if ($addresses===false) { |
|
366 return false; |
|
367 } |
|
368 return $addresses['public']; |
|
369 } |
|
370 /** |
|
371 * Get the Private IPs of a server |
|
372 * |
|
373 * @param string $id |
|
374 * @return array|boolean |
|
375 */ |
|
376 public function getServerPrivateIp($id) |
|
377 { |
|
378 $addresses= $this->getServerIp($id); |
|
379 if ($addresses===false) { |
|
380 return false; |
|
381 } |
|
382 return $addresses['private']; |
|
383 } |
|
384 /** |
|
385 * Share an ip address for a server (id) |
|
386 * |
|
387 * @param string $id server |
|
388 * @param string $ip |
|
389 * @param string $groupId |
|
390 * @return boolean |
|
391 */ |
|
392 public function shareIpAddress($id,$ip,$groupId,$configure=true) |
|
393 { |
|
394 if (empty($id)) { |
|
395 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
396 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server'); |
|
397 } |
|
398 if (empty($ip)) { |
|
399 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
400 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the IP address to share'); |
|
401 } |
|
402 $validator = new Zend_Validate_Ip(); |
|
403 if (!$validator->isValid($ip)) { |
|
404 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
405 throw new Zend_Service_Rackspace_Exception("The parameter $ip specified is not a valid IP address"); |
|
406 } |
|
407 if (empty($groupId)) { |
|
408 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
409 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the group id to use'); |
|
410 } |
|
411 $data= array ( |
|
412 'sharedIpGroupId' => (integer) $groupId, |
|
413 'configureServer' => $configure |
|
414 ); |
|
415 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/ips/public/'.rawurlencode($ip),'PUT', |
|
416 null,null,json_encode(array('shareIp' => $data))); |
|
417 $status = $result->getStatus(); |
|
418 switch ($status) { |
|
419 case '202' : // break intentionally omitted |
|
420 return true; |
|
421 case '503' : |
|
422 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
423 break; |
|
424 case '401' : |
|
425 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
426 break; |
|
427 case '404' : |
|
428 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
429 break; |
|
430 case '413' : |
|
431 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
432 break; |
|
433 default: |
|
434 $this->errorMsg= $result->getBody(); |
|
435 break; |
|
436 } |
|
437 $this->errorCode= $status; |
|
438 return false; |
|
439 } |
|
440 /** |
|
441 * Unshare IP address for a server ($id) |
|
442 * |
|
443 * @param string $id |
|
444 * @param string $ip |
|
445 * @return boolean |
|
446 */ |
|
447 public function unshareIpAddress($id,$ip) |
|
448 { |
|
449 if (empty($id)) { |
|
450 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
451 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server'); |
|
452 } |
|
453 if (empty($ip)) { |
|
454 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
455 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the IP address to share'); |
|
456 } |
|
457 $validator = new Zend_Validate_Ip(); |
|
458 if (!$validator->isValid($ip)) { |
|
459 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
460 throw new Zend_Service_Rackspace_Exception("The parameter $ip specified is not a valid IP address"); |
|
461 } |
|
462 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/ips/public/'.rawurlencode($ip), |
|
463 'DELETE'); |
|
464 $status = $result->getStatus(); |
|
465 switch ($status) { |
|
466 case '202' : // break intentionally omitted |
|
467 return true; |
|
468 case '503' : |
|
469 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
470 break; |
|
471 case '401' : |
|
472 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
473 break; |
|
474 case '404' : |
|
475 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
476 break; |
|
477 case '413' : |
|
478 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
479 break; |
|
480 default: |
|
481 $this->errorMsg= $result->getBody(); |
|
482 break; |
|
483 } |
|
484 $this->errorCode= $status; |
|
485 return false; |
|
486 } |
|
487 /** |
|
488 * Reboot a server |
|
489 * |
|
490 * $hard true is the equivalent of power cycling the server |
|
491 * $hard false is a graceful shutdown |
|
492 * |
|
493 * @param string $id |
|
494 * @param boolean $hard |
|
495 * @return boolean |
|
496 */ |
|
497 public function rebootServer($id,$hard=false) |
|
498 { |
|
499 if (empty($id)) { |
|
500 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
501 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server'); |
|
502 } |
|
503 if (!$hard) { |
|
504 $type= 'SOFT'; |
|
505 } else { |
|
506 $type= 'HARD'; |
|
507 } |
|
508 $data= array ( |
|
509 'reboot' => array ( |
|
510 'type' => $type |
|
511 ) |
|
512 ); |
|
513 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/action', |
|
514 'POST', null, null, json_encode($data)); |
|
515 $status = $result->getStatus(); |
|
516 switch ($status) { |
|
517 case '200' : |
|
518 case '202' : // break intentionally omitted |
|
519 return true; |
|
520 case '503' : |
|
521 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
522 break; |
|
523 case '401' : |
|
524 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
525 break; |
|
526 case '404' : |
|
527 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
528 break; |
|
529 case '409' : |
|
530 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
531 break; |
|
532 case '413' : |
|
533 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
534 break; |
|
535 default: |
|
536 $this->errorMsg= $result->getBody(); |
|
537 break; |
|
538 } |
|
539 $this->errorCode= $status; |
|
540 return false; |
|
541 } |
|
542 /** |
|
543 * Rebuild a server |
|
544 * |
|
545 * The rebuild function removes all data on the server and replaces it with the specified image, |
|
546 * serverId and IP addresses will remain the same. |
|
547 * |
|
548 * @param string $id |
|
549 * @param string $imageId |
|
550 * @return boolean |
|
551 */ |
|
552 public function rebuildServer($id,$imageId) |
|
553 { |
|
554 if (empty($id)) { |
|
555 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
556 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server'); |
|
557 } |
|
558 if (empty($imageId)) { |
|
559 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
560 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the new imageId of the server'); |
|
561 } |
|
562 $data= array ( |
|
563 'rebuild' => array ( |
|
564 'imageId' => (integer) $imageId |
|
565 ) |
|
566 ); |
|
567 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/action', |
|
568 'POST', null, null, json_encode($data)); |
|
569 $status = $result->getStatus(); |
|
570 switch ($status) { |
|
571 case '202' : // break intentionally omitted |
|
572 return true; |
|
573 case '503' : |
|
574 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
575 break; |
|
576 case '401' : |
|
577 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
578 break; |
|
579 case '404' : |
|
580 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
581 break; |
|
582 case '409' : |
|
583 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
584 break; |
|
585 case '413' : |
|
586 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
587 break; |
|
588 default: |
|
589 $this->errorMsg= $result->getBody(); |
|
590 break; |
|
591 } |
|
592 $this->errorCode= $status; |
|
593 return false; |
|
594 } |
|
595 /** |
|
596 * Resize a server |
|
597 * |
|
598 * The resize function converts an existing server to a different flavor, in essence, scaling the |
|
599 * server up or down. The original server is saved for a period of time to allow rollback if there |
|
600 * is a problem. All resizes should be tested and explicitly confirmed, at which time the original |
|
601 * server is removed. All resizes are automatically confirmed after 24 hours if they are not |
|
602 * explicitly confirmed or reverted. |
|
603 * |
|
604 * @param string $id |
|
605 * @param string $flavorId |
|
606 * @return boolean |
|
607 */ |
|
608 public function resizeServer($id,$flavorId) |
|
609 { |
|
610 if (empty($id)) { |
|
611 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
612 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server'); |
|
613 } |
|
614 if (empty($flavorId)) { |
|
615 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
616 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the new flavorId of the server'); |
|
617 } |
|
618 $data= array ( |
|
619 'resize' => array ( |
|
620 'flavorId' => (integer) $flavorId |
|
621 ) |
|
622 ); |
|
623 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/action', |
|
624 'POST', null, null, json_encode($data)); |
|
625 $status = $result->getStatus(); |
|
626 switch ($status) { |
|
627 case '202' : // break intentionally omitted |
|
628 return true; |
|
629 case '503' : |
|
630 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
631 break; |
|
632 case '401' : |
|
633 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
634 break; |
|
635 case '403' : |
|
636 $this->errorMsg= self::ERROR_RESIZE_NOT_ALLOWED; |
|
637 break; |
|
638 case '404' : |
|
639 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
640 break; |
|
641 case '409' : |
|
642 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
643 break; |
|
644 case '413' : |
|
645 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
646 break; |
|
647 default: |
|
648 $this->errorMsg= $result->getBody(); |
|
649 break; |
|
650 } |
|
651 $this->errorCode= $status; |
|
652 return false; |
|
653 } |
|
654 /** |
|
655 * Confirm resize of a server |
|
656 * |
|
657 * During a resize operation, the original server is saved for a period of time to allow roll |
|
658 * back if there is a problem. Once the newly resized server is tested and has been confirmed |
|
659 * to be functioning properly, use this operation to confirm the resize. After confirmation, |
|
660 * the original server is removed and cannot be rolled back to. All resizes are automatically |
|
661 * confirmed after 24 hours if they are not explicitly confirmed or reverted. |
|
662 * |
|
663 * @param string $id |
|
664 * @return boolean |
|
665 */ |
|
666 public function confirmResizeServer($id) |
|
667 { |
|
668 if (empty($id)) { |
|
669 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
670 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server'); |
|
671 } |
|
672 $data= array ( |
|
673 'confirmResize' => null |
|
674 ); |
|
675 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/action', |
|
676 'POST', null, null, json_encode($data)); |
|
677 $status = $result->getStatus(); |
|
678 switch ($status) { |
|
679 case '204' : // break intentionally omitted |
|
680 return true; |
|
681 case '503' : |
|
682 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
683 break; |
|
684 case '401' : |
|
685 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
686 break; |
|
687 case '403' : |
|
688 $this->errorMsg= self::ERROR_RESIZE_NOT_ALLOWED; |
|
689 break; |
|
690 case '404' : |
|
691 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
692 break; |
|
693 case '409' : |
|
694 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
695 break; |
|
696 case '413' : |
|
697 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
698 break; |
|
699 default: |
|
700 $this->errorMsg= $result->getBody(); |
|
701 break; |
|
702 } |
|
703 $this->errorCode= $status; |
|
704 return false; |
|
705 } |
|
706 /** |
|
707 * Revert resize of a server |
|
708 * |
|
709 * During a resize operation, the original server is saved for a period of time to allow for roll |
|
710 * back if there is a problem. If you determine there is a problem with a newly resized server, |
|
711 * use this operation to revert the resize and roll back to the original server. All resizes are |
|
712 * automatically confirmed after 24 hours if they have not already been confirmed explicitly or |
|
713 * reverted. |
|
714 * |
|
715 * @param string $id |
|
716 * @return boolean |
|
717 */ |
|
718 public function revertResizeServer($id) |
|
719 { |
|
720 if (empty($id)) { |
|
721 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
722 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the ID of the server'); |
|
723 } |
|
724 $data= array ( |
|
725 'revertResize' => null |
|
726 ); |
|
727 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/action', |
|
728 'POST', null, null, json_encode($data)); |
|
729 $status = $result->getStatus(); |
|
730 switch ($status) { |
|
731 case '202' : // break intentionally omitted |
|
732 return true; |
|
733 case '503' : |
|
734 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
735 break; |
|
736 case '401' : |
|
737 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
738 break; |
|
739 case '403' : |
|
740 $this->errorMsg= self::ERROR_RESIZE_NOT_ALLOWED; |
|
741 break; |
|
742 case '404' : |
|
743 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
744 break; |
|
745 case '409' : |
|
746 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
747 break; |
|
748 case '413' : |
|
749 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
750 break; |
|
751 default: |
|
752 $this->errorMsg= $result->getBody(); |
|
753 break; |
|
754 } |
|
755 $this->errorCode= $status; |
|
756 return false; |
|
757 } |
|
758 /** |
|
759 * Get the list of the flavors |
|
760 * |
|
761 * If $details is true returns detail info |
|
762 * |
|
763 * @param boolean $details |
|
764 * @return array|boolean |
|
765 */ |
|
766 public function listFlavors($details=false) |
|
767 { |
|
768 $url= '/flavors'; |
|
769 if ($details) { |
|
770 $url.= '/detail'; |
|
771 } |
|
772 $result= $this->httpCall($this->getManagementUrl().$url,'GET'); |
|
773 $status= $result->getStatus(); |
|
774 switch ($status) { |
|
775 case '200' : |
|
776 case '203' : // break intentionally omitted |
|
777 $flavors= json_decode($result->getBody(),true); |
|
778 return $flavors['flavors']; |
|
779 case '503' : |
|
780 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
781 break; |
|
782 case '401' : |
|
783 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
784 break; |
|
785 case '413' : |
|
786 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
787 break; |
|
788 default: |
|
789 $this->errorMsg= $result->getBody(); |
|
790 break; |
|
791 } |
|
792 $this->errorCode= $status; |
|
793 return false; |
|
794 } |
|
795 /** |
|
796 * Get the detail of a flavor |
|
797 * |
|
798 * @param string $flavorId |
|
799 * @return array|boolean |
|
800 */ |
|
801 public function getFlavor($flavorId) |
|
802 { |
|
803 if (empty($flavorId)) { |
|
804 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
805 throw new Zend_Service_Rackspace_Exception('You didn\'t specified the new flavorId of the server'); |
|
806 } |
|
807 $result= $this->httpCall($this->getManagementUrl().'/flavors/'.rawurlencode($flavorId),'GET'); |
|
808 $status= $result->getStatus(); |
|
809 switch ($status) { |
|
810 case '200' : |
|
811 case '203' : // break intentionally omitted |
|
812 $flavor= json_decode($result->getBody(),true); |
|
813 return $flavor['flavor']; |
|
814 case '503' : |
|
815 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
816 break; |
|
817 case '401' : |
|
818 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
819 break; |
|
820 case '413' : |
|
821 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
822 break; |
|
823 default: |
|
824 $this->errorMsg= $result->getBody(); |
|
825 break; |
|
826 } |
|
827 $this->errorCode= $status; |
|
828 return false; |
|
829 } |
|
830 /** |
|
831 * Get the list of the images |
|
832 * |
|
833 * @param boolean $details |
|
834 * @return Zend_Service_Rackspace_Servers_ImageList|boolean |
|
835 */ |
|
836 public function listImages($details=false) |
|
837 { |
|
838 $url= '/images'; |
|
839 if ($details) { |
|
840 $url.= '/detail'; |
|
841 } |
|
842 $result= $this->httpCall($this->getManagementUrl().$url,'GET'); |
|
843 $status= $result->getStatus(); |
|
844 switch ($status) { |
|
845 case '200' : |
|
846 case '203' : // break intentionally omitted |
|
847 $images= json_decode($result->getBody(),true); |
|
848 return new Zend_Service_Rackspace_Servers_ImageList($this,$images['images']); |
|
849 case '503' : |
|
850 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
851 break; |
|
852 case '401' : |
|
853 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
854 break; |
|
855 case '413' : |
|
856 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
857 break; |
|
858 default: |
|
859 $this->errorMsg= $result->getBody(); |
|
860 break; |
|
861 } |
|
862 $this->errorCode= $status; |
|
863 return false; |
|
864 } |
|
865 /** |
|
866 * Get detail about an image |
|
867 * |
|
868 * @param string $id |
|
869 * @return Zend_Service_Rackspace_Servers_Image|boolean |
|
870 */ |
|
871 public function getImage($id) |
|
872 { |
|
873 $result= $this->httpCall($this->getManagementUrl().'/images/'.rawurlencode($id),'GET'); |
|
874 $status= $result->getStatus(); |
|
875 switch ($status) { |
|
876 case '200' : |
|
877 case '203' : // break intentionally omitted |
|
878 $image= json_decode($result->getBody(),true); |
|
879 return new Zend_Service_Rackspace_Servers_Image($this,$image['image']); |
|
880 case '503' : |
|
881 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
882 break; |
|
883 case '401' : |
|
884 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
885 break; |
|
886 case '404' : |
|
887 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
888 break; |
|
889 case '413' : |
|
890 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
891 break; |
|
892 default: |
|
893 $this->errorMsg= $result->getBody(); |
|
894 break; |
|
895 } |
|
896 $this->errorCode= $status; |
|
897 return false; |
|
898 } |
|
899 /** |
|
900 * Create an image for a serverId |
|
901 * |
|
902 * @param string $serverId |
|
903 * @param string $name |
|
904 * @return Zend_Service_Rackspace_Servers_Image |
|
905 */ |
|
906 public function createImage($serverId,$name) |
|
907 { |
|
908 if (empty($serverId)) { |
|
909 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
910 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_SERVERID); |
|
911 } |
|
912 if (empty($name)) { |
|
913 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
914 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME); |
|
915 } |
|
916 $data = array( |
|
917 'image' => array ( |
|
918 'serverId' => (integer) $serverId, |
|
919 'name' => $name |
|
920 ) |
|
921 ); |
|
922 $result = $this->httpCall($this->getManagementUrl().'/images', 'POST', |
|
923 null, null, json_encode($data)); |
|
924 $status = $result->getStatus(); |
|
925 switch ($status) { |
|
926 case '202' : // break intentionally omitted |
|
927 $image= json_decode($result->getBody(),true); |
|
928 return new Zend_Service_Rackspace_Servers_Image($this,$image['image']); |
|
929 case '503' : |
|
930 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
931 break; |
|
932 case '401' : |
|
933 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
934 break; |
|
935 case '403' : |
|
936 $this->errorMsg= self::ERROR_RESIZE_NOT_ALLOWED; |
|
937 break; |
|
938 case '404' : |
|
939 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
940 break; |
|
941 case '409' : |
|
942 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
943 break; |
|
944 case '413' : |
|
945 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
946 break; |
|
947 default: |
|
948 $this->errorMsg= $result->getBody(); |
|
949 break; |
|
950 } |
|
951 $this->errorCode= $status; |
|
952 return false; |
|
953 } |
|
954 /** |
|
955 * Delete an image |
|
956 * |
|
957 * @param string $id |
|
958 * @return boolean |
|
959 */ |
|
960 public function deleteImage($id) |
|
961 { |
|
962 if (empty($id)) { |
|
963 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
964 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
965 } |
|
966 $result = $this->httpCall($this->getManagementUrl().'/images/'.rawurlencode($id),'DELETE'); |
|
967 $status = $result->getStatus(); |
|
968 switch ($status) { |
|
969 case '204' : // break intentionally omitted |
|
970 return true; |
|
971 case '503' : |
|
972 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
973 break; |
|
974 case '401' : |
|
975 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
976 break; |
|
977 case '404' : |
|
978 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
979 break; |
|
980 case '413' : |
|
981 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
982 break; |
|
983 default: |
|
984 $this->errorMsg= $result->getBody(); |
|
985 break; |
|
986 } |
|
987 $this->errorCode= $status; |
|
988 return false; |
|
989 } |
|
990 /** |
|
991 * Get the backup schedule of a server |
|
992 * |
|
993 * @param string $id server's Id |
|
994 * @return array|boolean |
|
995 */ |
|
996 public function getBackupSchedule($id) |
|
997 { |
|
998 if (empty($id)) { |
|
999 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1000 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
1001 } |
|
1002 $result= $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/backup_schedule', |
|
1003 'GET'); |
|
1004 $status= $result->getStatus(); |
|
1005 switch ($status) { |
|
1006 case '200' : |
|
1007 case '203' : // break intentionally omitted |
|
1008 $backup = json_decode($result->getBody(),true); |
|
1009 return $backup['backupSchedule']; |
|
1010 case '503' : |
|
1011 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
1012 break; |
|
1013 case '401' : |
|
1014 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
1015 break; |
|
1016 case '404' : |
|
1017 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
1018 break; |
|
1019 case '413' : |
|
1020 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
1021 break; |
|
1022 default: |
|
1023 $this->errorMsg= $result->getBody(); |
|
1024 break; |
|
1025 } |
|
1026 $this->errorCode= $status; |
|
1027 return false; |
|
1028 } |
|
1029 /** |
|
1030 * Change the backup schedule of a server |
|
1031 * |
|
1032 * @param string $id server's Id |
|
1033 * @param string $weekly |
|
1034 * @param string $daily |
|
1035 * @return boolean |
|
1036 */ |
|
1037 public function changeBackupSchedule($id,$weekly,$daily) |
|
1038 { |
|
1039 if (empty($id)) { |
|
1040 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1041 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
1042 } |
|
1043 if (empty($weekly)) { |
|
1044 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1045 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_WEEKLY); |
|
1046 } |
|
1047 if (empty($daily)) { |
|
1048 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1049 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_DAILY); |
|
1050 } |
|
1051 $data = array ( |
|
1052 'backupSchedule' => array ( |
|
1053 'enabled' => true, |
|
1054 'weekly' => $weekly, |
|
1055 'daily' => $daily |
|
1056 ) |
|
1057 ); |
|
1058 $result= $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/backup_schedule', |
|
1059 'POST',null,null,json_encode($data)); |
|
1060 $status= $result->getStatus(); |
|
1061 switch ($status) { |
|
1062 case '204' : // break intentionally omitted |
|
1063 return true; |
|
1064 case '503' : |
|
1065 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
1066 break; |
|
1067 case '401' : |
|
1068 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
1069 break; |
|
1070 case '404' : |
|
1071 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
1072 break; |
|
1073 case '409' : |
|
1074 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
1075 break; |
|
1076 case '413' : |
|
1077 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
1078 break; |
|
1079 default: |
|
1080 $this->errorMsg= $result->getBody(); |
|
1081 break; |
|
1082 } |
|
1083 $this->errorCode= $status; |
|
1084 return false; |
|
1085 } |
|
1086 /** |
|
1087 * Disable the backup schedule for a server |
|
1088 * |
|
1089 * @param string $id server's Id |
|
1090 * @return boolean |
|
1091 */ |
|
1092 public function disableBackupSchedule($id) |
|
1093 { |
|
1094 if (empty($id)) { |
|
1095 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1096 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
1097 } |
|
1098 $result = $this->httpCall($this->getManagementUrl().'/servers/'.rawurlencode($id).'/backup_schedule', |
|
1099 'DELETE'); |
|
1100 $status = $result->getStatus(); |
|
1101 switch ($status) { |
|
1102 case '204' : // break intentionally omitted |
|
1103 return true; |
|
1104 case '503' : |
|
1105 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
1106 break; |
|
1107 case '401' : |
|
1108 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
1109 break; |
|
1110 case '404' : |
|
1111 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
1112 break; |
|
1113 case '409' : |
|
1114 $this->errorMsg= self::ERROR_BUILD_IN_PROGRESS; |
|
1115 break; |
|
1116 case '413' : |
|
1117 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
1118 break; |
|
1119 default: |
|
1120 $this->errorMsg= $result->getBody(); |
|
1121 break; |
|
1122 } |
|
1123 $this->errorCode= $status; |
|
1124 return false; |
|
1125 } |
|
1126 /** |
|
1127 * Get the list of shared IP groups |
|
1128 * |
|
1129 * @param boolean $details |
|
1130 * @return Zend_Service_Rackspace_Servers_SharedIpGroupList|boolean |
|
1131 */ |
|
1132 public function listSharedIpGroups($details=false) |
|
1133 { |
|
1134 $url= '/shared_ip_groups'; |
|
1135 if ($details) { |
|
1136 $url.= '/detail'; |
|
1137 } |
|
1138 $result= $this->httpCall($this->getManagementUrl().$url,'GET'); |
|
1139 $status= $result->getStatus(); |
|
1140 switch ($status) { |
|
1141 case '200' : |
|
1142 case '203' : // break intentionally omitted |
|
1143 $groups= json_decode($result->getBody(),true); |
|
1144 return new Zend_Service_Rackspace_Servers_SharedIpGroupList($this,$groups['sharedIpGroups']); |
|
1145 case '503' : |
|
1146 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
1147 break; |
|
1148 case '401' : |
|
1149 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
1150 break; |
|
1151 case '413' : |
|
1152 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
1153 break; |
|
1154 default: |
|
1155 $this->errorMsg= $result->getBody(); |
|
1156 break; |
|
1157 } |
|
1158 $this->errorCode= $status; |
|
1159 return false; |
|
1160 } |
|
1161 /** |
|
1162 * Get the shared IP group |
|
1163 * |
|
1164 * @param integer $id |
|
1165 * @return Zend_Service_Rackspace_Servers_SharedIpGroup|boolean |
|
1166 */ |
|
1167 public function getSharedIpGroup($id) |
|
1168 { |
|
1169 if (empty($id)) { |
|
1170 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1171 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
1172 } |
|
1173 $result= $this->httpCall($this->getManagementUrl().'/shared_ip_groups/'.rawurlencode($id),'GET'); |
|
1174 $status= $result->getStatus(); |
|
1175 switch ($status) { |
|
1176 case '200' : |
|
1177 case '203' : // break intentionally omitted |
|
1178 $group= json_decode($result->getBody(),true); |
|
1179 return new Zend_Service_Rackspace_Servers_SharedIpGroup($this,$group['sharedIpGroup']); |
|
1180 case '503' : |
|
1181 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
1182 break; |
|
1183 case '401' : |
|
1184 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
1185 break; |
|
1186 case '404' : |
|
1187 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
1188 break; |
|
1189 case '413' : |
|
1190 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
1191 break; |
|
1192 default: |
|
1193 $this->errorMsg= $result->getBody(); |
|
1194 break; |
|
1195 } |
|
1196 $this->errorCode= $status; |
|
1197 return false; |
|
1198 } |
|
1199 /** |
|
1200 * Create a shared Ip group |
|
1201 * |
|
1202 * @param string $name |
|
1203 * @param string $serverId |
|
1204 * @return array|boolean |
|
1205 */ |
|
1206 public function createSharedIpGroup($name,$serverId) |
|
1207 { |
|
1208 if (empty($name)) { |
|
1209 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1210 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_NAME); |
|
1211 } |
|
1212 if (empty($serverId)) { |
|
1213 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1214 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
1215 } |
|
1216 $data = array ( |
|
1217 'sharedIpGroup' => array ( |
|
1218 'name' => $name, |
|
1219 'server' => (integer) $serverId |
|
1220 ) |
|
1221 ); |
|
1222 $result= $this->httpCall($this->getManagementUrl().'/shared_ip_groups', |
|
1223 'POST',null,null,json_encode($data)); |
|
1224 $status= $result->getStatus(); |
|
1225 switch ($status) { |
|
1226 case '201' : // break intentionally omitted |
|
1227 $group = json_decode($result->getBody(),true); |
|
1228 return new Zend_Service_Rackspace_Servers_SharedIpGroup($this,$group['sharedIpGroup']); |
|
1229 case '503' : |
|
1230 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
1231 break; |
|
1232 case '401' : |
|
1233 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
1234 break; |
|
1235 case '413' : |
|
1236 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
1237 break; |
|
1238 default: |
|
1239 $this->errorMsg= $result->getBody(); |
|
1240 break; |
|
1241 } |
|
1242 $this->errorCode= $status; |
|
1243 return false; |
|
1244 } |
|
1245 /** |
|
1246 * Delete a Shared Ip Group |
|
1247 * |
|
1248 * @param integer $id |
|
1249 * @return boolean |
|
1250 */ |
|
1251 public function deleteSharedIpGroup($id) |
|
1252 { |
|
1253 if (empty($id)) { |
|
1254 require_once 'Zend/Service/Rackspace/Exception.php'; |
|
1255 throw new Zend_Service_Rackspace_Exception(self::ERROR_PARAM_NO_ID); |
|
1256 } |
|
1257 $result= $this->httpCall($this->getManagementUrl().'/shared_ip_groups/'.rawurlencode($id),'DELETE'); |
|
1258 $status= $result->getStatus(); |
|
1259 switch ($status) { |
|
1260 case '204' : // break intentionally omitted |
|
1261 return true; |
|
1262 case '503' : |
|
1263 $this->errorMsg= self::ERROR_SERVICE_UNAVAILABLE; |
|
1264 break; |
|
1265 case '401' : |
|
1266 $this->errorMsg= self::ERROR_UNAUTHORIZED; |
|
1267 break; |
|
1268 case '404' : |
|
1269 $this->errorMsg= self::ERROR_ITEM_NOT_FOUND; |
|
1270 break; |
|
1271 case '413' : |
|
1272 $this->errorMsg= self::ERROR_OVERLIMIT; |
|
1273 break; |
|
1274 default: |
|
1275 $this->errorMsg= $result->getBody(); |
|
1276 break; |
|
1277 } |
|
1278 $this->errorCode= $status; |
|
1279 return false; |
|
1280 } |
|
1281 } |