PageRenderTime 46ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/scalr-2/tags/scalr-2.1.0/app/src/Scalr/Service/Cloud/Rackspace/CS.php

http://scalr.googlecode.com/
PHP | 475 lines | 172 code | 73 blank | 230 comment | 6 complexity | 2e5a7ff53aa3de5e8a7423bb7d3e2faa MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, GPL-3.0
  1. <?php
  2. class Scalr_Service_Cloud_Rackspace_CS extends Scalr_Service_Cloud_Rackspace_Connection
  3. {
  4. public function __construct ($user, $key)
  5. {
  6. parent::__construct($user, $key);
  7. }
  8. /**
  9. * returns version of current api
  10. *
  11. * @name apiVersion
  12. * @return mixed $response
  13. */
  14. public function apiVersion($version = null)
  15. {
  16. if(!$version)
  17. $version = "v1.0";
  18. // api version can be recieved only from by root URL request
  19. return $this->request("GET", null, null, "https://servers.api.rackspacecloud.com/{$version}/");
  20. }
  21. /**
  22. * fter confirmation, the original server is removed and cannot be
  23. * rolled back to. All resizes are automatically confirmed
  24. * after 24 hours if they are not explicitly confirmed or reverted.
  25. *
  26. * @name confirmResizedServer
  27. * @param mixed $serverId
  28. */
  29. public function confirmResizedServer($serverId )
  30. {
  31. $args = array("confirmResize" => null);
  32. return $this->request("POST","servers/{$serverId}/action",$args);
  33. }
  34. /**
  35. * This operation creates a new backup schedule or updates an existing backup schedule
  36. * for the specified server. Backup schedules will occur only when
  37. * the enabled attribute is set to true. The weekly and daily attributes can be
  38. * used to set or to disable individual backup schedules
  39. *
  40. * @name createBackupSchedule
  41. * @param mixed $serverId
  42. * @param mixed $dayOftheWeek
  43. * @param mixed $hour
  44. * @return mixed $response
  45. */
  46. public function createBackupSchedule($serverId, $dayOftheWeek, $hour )
  47. {
  48. $args = array("backupSchedule" => array(
  49. "enabled" => true,
  50. "weekly" => $dayOftheWeek,
  51. "daily" => $hour)
  52. );
  53. return $this->request("POST","servers/{$serverId}/backup_schedule",$args);
  54. }
  55. /**
  56. * creates a new image for the given server ID.
  57. * Once complete, a new image will be available that can be used
  58. * to rebuild or create servers.
  59. *
  60. * @name createImage
  61. * @param mixed $serverId
  62. * @param mixed $name
  63. * @return mixed $response
  64. */
  65. public function createImage($serverId, $name )
  66. {
  67. $args = array("image" => array(
  68. "serverId" => $serverId,
  69. "name" => $name)
  70. );
  71. return $this->request("POST","images",$args);
  72. }
  73. /**
  74. * asynchronously provisions a new server.
  75. *
  76. * @name createServer
  77. * @return mixed $response
  78. */
  79. public function createServer($name, $imageId, $flavorId, $metadata = array(), $personality = array() )
  80. {
  81. $args['server'] = array(
  82. 'name' => $name,
  83. 'imageId' => (int)$imageId,
  84. 'flavorId' => (int)$flavorId
  85. );
  86. if (!empty($personality))
  87. {
  88. $args['server']['personality'][] = array('path' => $personality['path'], 'contents' => $personality['contents']);
  89. }
  90. return $this->request("POST", "servers", $args);
  91. }
  92. /**
  93. * creates a new shared IP group. Please note, all responses to requests
  94. * for shared_ip_groups return an array of servers. However, on a create request,
  95. * the shared IP group can be created empty or can be initially populated
  96. * with a single server.
  97. *
  98. * @name createSharedIpGroup
  99. * @param mixed $serverId
  100. * @param mixed $name
  101. * @return mixed $response
  102. */
  103. public function createSharedIpGroup($serverId, $name )
  104. {
  105. $args = array("sharedIpGroup" => array(
  106. "name" => $name,
  107. "server" => $serverId)
  108. );
  109. return $this->request("POST","shared_ip_groups",$args);
  110. }
  111. /**
  112. * deletes an image from the system.
  113. *
  114. * @name deleteImage
  115. * @param mixed $imageId
  116. */
  117. public function deleteImage($imageId)
  118. {
  119. $this->request("DELETE", "images/{$imageId}");
  120. }
  121. /**
  122. * This operation deletes a cloud server instance from the system
  123. *
  124. * @name deleteServer
  125. * @param mixed $serverId
  126. */
  127. public function deleteServer($serverId)
  128. {
  129. $this->request("DELETE", "servers/{$serverId}");
  130. }
  131. /**
  132. * This operation deletes the specified shared IP group.
  133. * This operation will ONLY succeed if
  134. * 1) there are no active servers in the group (i.e. they have all been terminated) or
  135. * 2) no servers in the group are actively sharing IPs.
  136. *
  137. * @name deleteSharedIpGroup
  138. * @param mixed $groupId
  139. */
  140. public function deleteSharedIpGroup($groupId)
  141. {
  142. $this->request("DELETE", "shared_ip_groups/{$groupId}");
  143. }
  144. /**
  145. * disables the backup schedule for the specified server
  146. *
  147. * @name disableBackupSchedule
  148. * @param mixed $serverId
  149. */
  150. public function disableBackupSchedule($serverId)
  151. {
  152. $this->request("DELETE", "servers/{$serverId}/backup_schedule");
  153. }
  154. /**
  155. * This operation returns details of the specified image
  156. *
  157. * @name getFlavorDetails
  158. * @param mixed $flavorId
  159. * @return mixed $response
  160. */
  161. public function getFlavorDetails($flavorId)
  162. {
  163. return $this->request("GET","flavors/{$flavorId}");
  164. }
  165. /**
  166. * returns details of the specified image
  167. *
  168. * @name getImageDetails
  169. * @param mixed $imageId
  170. * @return mixed $response
  171. */
  172. public function getImageDetails($imageId)
  173. {
  174. return $this->request("GET","images/{$imageId}");
  175. }
  176. /**
  177. * returns the details of a specific server by its ID
  178. *
  179. * @name getServerDetails
  180. * @param mixed $serverId
  181. * @return mixed $response
  182. */
  183. public function getServerDetails($serverId)
  184. {
  185. return $this->request("GET","servers/{$serverId}");
  186. }
  187. /**
  188. * This operation returns details of the specified shared IP group
  189. *
  190. * @param mixed $ipId
  191. * @return mixed $response
  192. */
  193. public function getSharedIpGroupsDetails($ipId)
  194. {
  195. return $this->request("GET","shared_ip_groups/{$ipId}");
  196. }
  197. /**
  198. * show limits of the account
  199. *
  200. * @name limits
  201. * @return mixed $response
  202. */
  203. public function limits()
  204. {
  205. return $this->request("GET","limits");
  206. }
  207. /**
  208. * Returns a list of IP addresses
  209. *
  210. * @name listAddresses
  211. * @param mixed $serverId
  212. * @return mixed $response
  213. */
  214. public function listAddresses($serverId)
  215. {
  216. return $response = $this->request("GET", "servers/{$serverId}/ips");
  217. }
  218. /**
  219. * lists the backup schedule for the specified server.
  220. *
  221. * @name listBackupSchedule
  222. * @param mixed $serverId
  223. * @return mixed $response
  224. */
  225. public function listBackupSchedule($serverId)
  226. {
  227. return $response = $this->request("GET", "servers/{$serverId}/backup_schedule");
  228. }
  229. /**
  230. * This operation will list all available flavors with details (if detail == true)
  231. *
  232. * @name listFlavors
  233. * @param boolean $detail
  234. * @return mixed $response
  235. */
  236. public function listFlavors($detail = false)
  237. {
  238. if($detail)
  239. $detail = "/detail";
  240. return $response = $this->request("GET", "flavors{$detail}");
  241. }
  242. /**
  243. * List available images
  244. *
  245. * @name listImages
  246. * @param mixed $detail
  247. * @return mixed $response
  248. */
  249. public function listImages($detail = false)
  250. {
  251. if($detail)
  252. $detail = "/detail";
  253. return $response = $this->request("GET", "images{$detail}");
  254. }
  255. /**
  256. * Returns a list of private IP addresses
  257. *
  258. * @name listPrivateAddresses
  259. * @param mixed $serverId
  260. * @return mixed $response
  261. */
  262. public function listPrivateAddresses($serverId)
  263. {
  264. return $response = $this->request("GET", "servers/{$serverId}/ips/private");
  265. }
  266. /**
  267. * Returns a list of public IP addresses
  268. *
  269. * @name listPublicAddresses
  270. * @param mixed $serverId
  271. * @return mixed $response
  272. */
  273. public function listPublicAddresses($serverId)
  274. {
  275. return $response = $this->request("GET", "servers/{$serverId}/ips/public");
  276. }
  277. /**
  278. *
  279. * provides a list of servers associated with your account
  280. * deleted servres can be shown with parameter $detail = true
  281. *
  282. * @name listServers
  283. * @param mixed $detail
  284. * @return mixed $response
  285. */
  286. public function listServers($details = false)
  287. {
  288. $details_uri = ($details) ? "/detail" : "";
  289. return $this->request("GET", "servers{$details_uri}");
  290. }
  291. /**
  292. * provides a list of shared IP groups associated with your account
  293. *
  294. * @name listSharedIpGroups
  295. * @param mixed $detail
  296. * @return mixed $response
  297. */
  298. public function listSharedIpGroups($detail = null)
  299. {
  300. if($detail)
  301. $detail = "/detail";
  302. return $response = $this->request("GET","shared_ip_groups{$detail}");
  303. }
  304. /**
  305. * allows for either a soft or hard reboot of a server.
  306. * With a soft reboot (SOFT), the operating system is signaled to restart,
  307. * which allows for a graceful shutdown of all processes.
  308. * A hard reboot (HARD) is the equivalent of power cycling the server
  309. *
  310. * @name rebootServer
  311. * @param mixed $serverId
  312. * @param mixed $rebootType
  313. */
  314. public function rebootServer($serverId, $rebootType = "SOFT")
  315. {
  316. $args = array("reboot" => array("type" =>$rebootType));
  317. $this->request("POST", "servers/{$serverId}/action",$args);
  318. }
  319. /**
  320. * The rebuild function removes all data on the server
  321. * and replaces it with the specified image. serverId and IP addresses
  322. * will remain the same.
  323. *
  324. * @name rebuildServer
  325. * @param mixed $serverId
  326. * @param mixed $imageId
  327. */
  328. public function rebuildServer($serverId, $imageId)
  329. {
  330. $args = array("rebuild" => array("imageId" =>$imageId));
  331. $this->request("POST", "servers/{$serverId}/action",$args);
  332. }
  333. /**
  334. * converts an existing server to a different flavor, in essence, scaling the server up or down
  335. *
  336. * @name resizeServer
  337. * @param mixed $serverId
  338. * @param mixed $flavorId
  339. */
  340. public function resizeServer($serverId, $flavorId)
  341. {
  342. $args = array("resize" => array("flavorId" =>$flavorId));
  343. $this->request("POST", "servers/{$serverId}/action",$args);
  344. }
  345. /**
  346. * Cancel and revert a pending resize action
  347. *
  348. * @name revertResizedServer
  349. * @param mixed $serverId
  350. */
  351. public function revertResizedServer($serverId)
  352. {
  353. $args = array("revertResize" => null);
  354. $this->request("POST", "servers/{$serverId}/action",$args);
  355. }
  356. /**
  357. * shares an IP from an existing server in the specified shared IP group to
  358. * another specified server in the same group. By default, the operation
  359. * modifies cloud network restrictions to allow IP traffic for the given
  360. * IP to/from the server specified, but does not bind the IP to the server itself.
  361. *
  362. * @name shareIpAddress
  363. * @param mixed $serverId
  364. * @param mixed $sharedIpGroupId
  365. */
  366. public function shareIpAddress($serverId, $sharedIpGroupId, $address)
  367. {
  368. $args = array('shareIp' => array(
  369. 'sharedIpGroupId' => $sharedIpGroupId,
  370. 'configureServer' => true)
  371. );
  372. $this->request("PUT", "servers/{$serverId}/ips/public/{$address}", $args);
  373. }
  374. /**
  375. * Removes a shared IP address from the specified server
  376. *
  377. * @name unshareIpAddress
  378. * @param mixed $serverId
  379. */
  380. public function unshareIpAddress($serverId)
  381. {
  382. $this->request("DELETE", "servers/{$serverId}/ips/public/address");
  383. }
  384. /**
  385. * allows you to update the name of the server and/or change the administrative password.
  386. * This operation changes the name of the server in the Cloud Servers system and
  387. * does not change the server host name itself.
  388. *
  389. * @name updateServerName
  390. * @param mixed $serverId
  391. * @param mixed $name
  392. * @param mixed $password
  393. */
  394. public function updateServerName($serverId, $name, $adminPass)
  395. {
  396. $args = array('server' => array('name' => $name));
  397. if($adminPass)
  398. $args['adminPass'] = $adminPass;
  399. $this->request("PUT", "servers/{$serverId}", $args);
  400. }
  401. }
  402. ?>