OpenStack Dashboard (Horizon)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cinder.service.js 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /**
  2. * Copyright 2015 IBM Corp.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. (function () {
  17. 'use strict';
  18. angular
  19. .module('horizon.app.core.openstack-service-api')
  20. .factory('horizon.app.core.openstack-service-api.cinder', cinderAPI);
  21. cinderAPI.$inject = [
  22. 'horizon.framework.util.http.service',
  23. 'horizon.framework.widgets.toast.service'
  24. ];
  25. /**
  26. * @ngdoc service
  27. * @param {Object} apiService
  28. * @param {Object} toastService
  29. * @name cinder
  30. * @description Provides direct access to Cinder APIs.
  31. * @returns {Object} The service
  32. */
  33. function cinderAPI(apiService, toastService) {
  34. var service = {
  35. getVolumes: getVolumes,
  36. getVolume: getVolume,
  37. getVolumeTypes: getVolumeTypes,
  38. getVolumeMetadata: getVolumeMetadata,
  39. getVolumeSnapshotMetadata: getVolumeSnapshotMetadata,
  40. getVolumeTypeMetadata: getVolumeTypeMetadata,
  41. getVolumeType: getVolumeType,
  42. getDefaultVolumeType: getDefaultVolumeType,
  43. getVolumeSnapshots: getVolumeSnapshots,
  44. getExtensions: getExtensions,
  45. getQoSSpecs: getQoSSpecs,
  46. getAvailabilityZones:getAvailabilityZones,
  47. createVolume: createVolume,
  48. getAbsoluteLimits: getAbsoluteLimits,
  49. getServices: getServices,
  50. getDefaultQuotaSets: getDefaultQuotaSets,
  51. setDefaultQuotaSets: setDefaultQuotaSets,
  52. updateProjectQuota: updateProjectQuota,
  53. editVolumeMetadata: editVolumeMetadata,
  54. editVolumeSnapshotMetadata: editVolumeSnapshotMetadata,
  55. editVolumeTypeMetadata:editVolumeTypeMetadata
  56. };
  57. return service;
  58. ///////////////
  59. // Volumes
  60. /**
  61. * @name getVolumes
  62. * @description
  63. * Get a list of volumes.
  64. *
  65. * The listing result is an object with property "items." Each item is
  66. * a volume.
  67. *
  68. * @param {Object} params
  69. * Query parameters. Optional.
  70. *
  71. * @param {boolean} params.paginate
  72. * True to paginate automatically.
  73. *
  74. * @param {string} params.marker
  75. * Specifies the image of the last-seen image.
  76. *
  77. * The typical pattern of limit and marker is to make an
  78. * initial limited request and then to use the last
  79. * image from the response as the marker parameter
  80. * in a subsequent limited request. With paginate, limit
  81. * is automatically set.
  82. *
  83. * @param {string} params.sort_dir
  84. * The sort direction ('asc' or 'desc').
  85. *
  86. * @param {string} param.search_opts
  87. * Filters to pass through the API.
  88. * For example, "status": "available" will show all available volumes.
  89. * @returns {Object} The result of the API call
  90. */
  91. function getVolumes(params) {
  92. var config = params ? {'params': params} : {};
  93. return apiService.get('/api/cinder/volumes/', config)
  94. .error(function () {
  95. toastService.add('error', gettext('Unable to retrieve the volumes.'));
  96. });
  97. }
  98. /**
  99. * @name getVolume
  100. * @description
  101. * Get a single Volume by ID.
  102. *
  103. * @param {string} id
  104. * Specifies the id of the Volume to request.
  105. *
  106. * @returns {Object} The result of the API call
  107. */
  108. function getVolume(id) {
  109. return apiService.get('/api/cinder/volumes/' + id)
  110. .error(function () {
  111. toastService.add('error', gettext('Unable to retrieve the volume.'));
  112. });
  113. }
  114. /**
  115. * @name createVolume
  116. * @param {Object} newVolume - The new volume object
  117. * @description
  118. * Create a volume.
  119. * @returns {Object} The result of the API call
  120. */
  121. function createVolume(newVolume) {
  122. return apiService.post('/api/cinder/volumes/', newVolume)
  123. .error(function () {
  124. toastService.add('error', gettext('Unable to create the volume.'));
  125. });
  126. }
  127. // Volume Types
  128. /**
  129. * @name getVolumeTypes
  130. * @description
  131. * Get a list of volume types.
  132. *
  133. * The listing result is an object with property "items." Each item is
  134. * a volume type.
  135. *
  136. * @returns {Object} The result of the API call
  137. */
  138. function getVolumeTypes() {
  139. return apiService.get('/api/cinder/volumetypes/')
  140. .error(function () {
  141. toastService.add('error', gettext('Unable to retrieve the volume types.'));
  142. });
  143. }
  144. function getVolumeMetadata(id) {
  145. return apiService.get('/api/cinder/volumes/' + id + '/metadata')
  146. .error(function () {
  147. toastService.add('error', gettext('Unable to retrieve the volume metadata.'));
  148. });
  149. }
  150. function getVolumeSnapshotMetadata(id) {
  151. return apiService.get('/api/cinder/volumesnapshots/' + id + '/metadata')
  152. .error(function () {
  153. toastService.add('error', gettext('Unable to retrieve the snapshot metadata.'));
  154. });
  155. }
  156. function getVolumeTypeMetadata(id) {
  157. return apiService.get('/api/cinder/volumetypes/' + id + '/metadata')
  158. .error(function () {
  159. toastService.add('error', gettext('Unable to retrieve the volume type metadata.'));
  160. });
  161. }
  162. function editVolumeMetadata(id, updated, removed) {
  163. return apiService.patch(
  164. '/api/cinder/volumes/' + id + '/metadata',
  165. {
  166. updated: updated,
  167. removed: removed
  168. }
  169. ).error(function () {
  170. toastService.add('error', gettext('Unable to edit volume metadata.'));
  171. });
  172. }
  173. function editVolumeSnapshotMetadata(id, updated, removed) {
  174. return apiService.patch(
  175. '/api/cinder/volumesnapshots/' + id + '/metadata',
  176. {
  177. updated: updated,
  178. removed: removed
  179. }
  180. ).error(function () {
  181. toastService.add('error', gettext('Unable to edit snapshot metadata.'));
  182. });
  183. }
  184. function editVolumeTypeMetadata(id, updated, removed) {
  185. return apiService.patch(
  186. '/api/cinder/volumetypes/' + id + '/metadata',
  187. {
  188. updated: updated,
  189. removed: removed
  190. }
  191. ).error(function () {
  192. toastService.add('error', gettext('Unable to edit volume type metadata.'));
  193. });
  194. }
  195. /**
  196. * @name getVolumeType
  197. * @description
  198. * Get a single Volume Type by ID.
  199. *
  200. * @param {string} id
  201. * Specifies the id of the Volume Type to request.
  202. *
  203. * @returns {Object} The result of the API call
  204. */
  205. function getVolumeType(id) {
  206. return apiService.get('/api/cinder/volumetypes/' + id)
  207. .error(function () {
  208. toastService.add('error', gettext('Unable to retrieve the volume type.'));
  209. });
  210. }
  211. /**
  212. * @name getDefaultVolumeType
  213. * @description
  214. * Get the default Volume Type
  215. *
  216. * @returns {Object} The result of the API call
  217. */
  218. function getDefaultVolumeType() {
  219. return apiService.get('/api/cinder/volumetypes/default')
  220. .error(function () {
  221. toastService.add('error', gettext('Unable to retrieve the default volume type.'));
  222. });
  223. }
  224. // Volume Snapshots
  225. /**
  226. * @name getVolumeSnapshots
  227. * @description
  228. * Get a list of volume snapshots.
  229. *
  230. * The listing result is an object with property "items." Each item is
  231. * a volume snapshot.
  232. *
  233. * @param {Object} params
  234. * Query parameters. Optional.
  235. *
  236. * @param {string} param.search_opts
  237. * Filters to pass through the API.
  238. * For example, "status": "available" will show all available volume
  239. * snapshots.
  240. * @returns {Object} The result of the API call
  241. */
  242. function getVolumeSnapshots(params) {
  243. var config = params ? {'params': params} : {};
  244. return apiService.get('/api/cinder/volumesnapshots/', config)
  245. .error(function () {
  246. toastService.add('error', gettext('Unable to retrieve the volume snapshots.'));
  247. });
  248. }
  249. // Cinder Extensions
  250. /**
  251. * @name getExtensions
  252. * @param {Object} config - The configuration for retrieving the extensions
  253. * @description
  254. * Returns a list of enabled extensions.
  255. *
  256. * The listing result is an object with property "items". Each item is
  257. * an extension.
  258. * @example
  259. * The following is an example response:
  260. *
  261. * {
  262. * "items": [
  263. * {
  264. * "alias": "OS-SCH-HNT",
  265. * "description": "Pass arbitrary key/value pairs to the scheduler.",
  266. * "links": [],
  267. * "name": "SchedulerHints",
  268. * "updated": "2013-04-18T00:00:00+00:00"
  269. * }
  270. * ]
  271. * }
  272. * @returns {Object} The result of the API call
  273. */
  274. function getExtensions(config) {
  275. return apiService.get('/api/cinder/extensions/', config)
  276. .error(function () {
  277. toastService.add('error', gettext('Unable to retrieve the extensions.'));
  278. });
  279. }
  280. // Cinder Services
  281. /**
  282. * @name getServices
  283. * @description Get the list of Cinder services.
  284. *
  285. * @returns {Object} An object with property "services." Each item is
  286. * a service.
  287. */
  288. function getServices() {
  289. return apiService.get('/api/cinder/services/')
  290. .error(function () {
  291. toastService.add('error', gettext('Unable to retrieve the cinder services.'));
  292. });
  293. }
  294. /**
  295. * @name getQoSSpecs
  296. * @description
  297. * Get a list of Quality of Service.
  298. *
  299. * The listing result is an object with property "items." Each item is
  300. * a Quality of Service Spec.
  301. *
  302. * @param {Object} params
  303. * Query parameters. Optional.
  304. * @returns {Object} The result of the API call
  305. *
  306. */
  307. function getQoSSpecs(params) {
  308. var config = params ? {'params': params} : {};
  309. return apiService.get('/api/cinder/qosspecs/', config)
  310. .error(function () {
  311. toastService.add('error',
  312. gettext('Unable to retrieve the QoS Specs.'));
  313. });
  314. }
  315. /**
  316. * @name getAbsoluteLimits
  317. * @description
  318. * Get the limits for the current tenant.
  319. *
  320. * @returns {Object} The result of the API call
  321. */
  322. function getAbsoluteLimits() {
  323. return apiService.get('/api/cinder/tenantabsolutelimits/')
  324. .error(function () {
  325. toastService.add('error',
  326. gettext('Unable to retrieve the Absolute Limits.'));
  327. });
  328. }
  329. // Default Quota Sets
  330. /**
  331. * @name horizon.app.core.openstack-service-api.cinder.getDefaultQuotaSets
  332. * @description
  333. * Get default quotasets
  334. *
  335. * The listing result is an object with property "items." Each item is
  336. * a quota.
  337. *
  338. */
  339. function getDefaultQuotaSets() {
  340. return apiService.get('/api/cinder/quota-sets/defaults/')
  341. .error(function () {
  342. toastService.add('error', gettext('Unable to retrieve the default quotas.'));
  343. });
  344. }
  345. /**
  346. * @name horizon.app.core.openstack-service-api.cinder.setDefaultQuotaSets
  347. * @description
  348. * Set default quota sets
  349. *
  350. */
  351. function setDefaultQuotaSets(quotas) {
  352. return apiService.patch('/api/cinder/quota-sets/defaults/', quotas)
  353. .error(function () {
  354. toastService.add('error', gettext('Unable to set the default quotas.'));
  355. });
  356. }
  357. // Quota Sets
  358. /**
  359. * @name updateProjectQuota
  360. * @description
  361. * Update a single project quota data.
  362. * @param {application/json} quota
  363. * A JSON object with the attributes to set to new quota values.
  364. * @param {string} projectId
  365. * Specifies the id of the project that'll have the quota data updated.
  366. */
  367. function updateProjectQuota(quota, projectId) {
  368. var url = '/api/cinder/quota-sets/' + projectId;
  369. return apiService.patch(url, quota)
  370. .error(function() {
  371. toastService.add('error', gettext('Unable to update project quota data.'));
  372. });
  373. }
  374. // Availability Zones
  375. /**
  376. * @name getAvailabilityZones
  377. * @description
  378. * Get a list of Availability Zones.
  379. *
  380. * The listing result is an object with property "items". Each item is
  381. * an availability zone.
  382. * @returns {Object} The result of the API call
  383. */
  384. function getAvailabilityZones() {
  385. return apiService.get('/api/cinder/availzones/')
  386. .error(function () {
  387. toastService.add('error',
  388. gettext('Unable to retrieve the volume availability zones.'));
  389. });
  390. }
  391. }
  392. }());