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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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": "NMN",
  265. * "description": "Multiple network support.",
  266. * "links": [],
  267. * "name": "Multinic",
  268. * "namespace": "http://docs.openstack.org/compute/ext/multinic/api/v1.1",
  269. * "updated": "2011-06-09T00:00:00Z"
  270. * }
  271. * ]
  272. * }
  273. * @returns {Object} The result of the API call
  274. */
  275. function getExtensions(config) {
  276. return apiService.get('/api/cinder/extensions/', config)
  277. .error(function () {
  278. toastService.add('error', gettext('Unable to retrieve the extensions.'));
  279. });
  280. }
  281. // Cinder Services
  282. /**
  283. * @name getServices
  284. * @description Get the list of Cinder services.
  285. *
  286. * @returns {Object} An object with property "services." Each item is
  287. * a service.
  288. */
  289. function getServices() {
  290. return apiService.get('/api/cinder/services/')
  291. .error(function () {
  292. toastService.add('error', gettext('Unable to retrieve the cinder services.'));
  293. });
  294. }
  295. /**
  296. * @name getQoSSpecs
  297. * @description
  298. * Get a list of Quality of Service.
  299. *
  300. * The listing result is an object with property "items." Each item is
  301. * a Quality of Service Spec.
  302. *
  303. * @param {Object} params
  304. * Query parameters. Optional.
  305. * @returns {Object} The result of the API call
  306. *
  307. */
  308. function getQoSSpecs(params) {
  309. var config = params ? {'params': params} : {};
  310. return apiService.get('/api/cinder/qosspecs/', config)
  311. .error(function () {
  312. toastService.add('error',
  313. gettext('Unable to retrieve the QoS Specs.'));
  314. });
  315. }
  316. /**
  317. * @name getAbsoluteLimits
  318. * @description
  319. * Get the limits for the current tenant.
  320. *
  321. * @returns {Object} The result of the API call
  322. */
  323. function getAbsoluteLimits() {
  324. return apiService.get('/api/cinder/tenantabsolutelimits/')
  325. .error(function () {
  326. toastService.add('error',
  327. gettext('Unable to retrieve the Absolute Limits.'));
  328. });
  329. }
  330. // Default Quota Sets
  331. /**
  332. * @name horizon.app.core.openstack-service-api.cinder.getDefaultQuotaSets
  333. * @description
  334. * Get default quotasets
  335. *
  336. * The listing result is an object with property "items." Each item is
  337. * a quota.
  338. *
  339. */
  340. function getDefaultQuotaSets() {
  341. return apiService.get('/api/cinder/quota-sets/defaults/')
  342. .error(function () {
  343. toastService.add('error', gettext('Unable to retrieve the default quotas.'));
  344. });
  345. }
  346. /**
  347. * @name horizon.app.core.openstack-service-api.cinder.setDefaultQuotaSets
  348. * @description
  349. * Set default quota sets
  350. *
  351. */
  352. function setDefaultQuotaSets(quotas) {
  353. return apiService.patch('/api/cinder/quota-sets/defaults/', quotas)
  354. .error(function () {
  355. toastService.add('error', gettext('Unable to set the default quotas.'));
  356. });
  357. }
  358. // Quota Sets
  359. /**
  360. * @name updateProjectQuota
  361. * @description
  362. * Update a single project quota data.
  363. * @param {application/json} quota
  364. * A JSON object with the attributes to set to new quota values.
  365. * @param {string} projectId
  366. * Specifies the id of the project that'll have the quota data updated.
  367. */
  368. function updateProjectQuota(quota, projectId) {
  369. var url = '/api/cinder/quota-sets/' + projectId;
  370. return apiService.patch(url, quota)
  371. .error(function() {
  372. toastService.add('error', gettext('Unable to update project quota data.'));
  373. });
  374. }
  375. // Availability Zones
  376. /**
  377. * @name getAvailabilityZones
  378. * @description
  379. * Get a list of Availability Zones.
  380. *
  381. * The listing result is an object with property "items". Each item is
  382. * an availability zone.
  383. * @returns {Object} The result of the API call
  384. */
  385. function getAvailabilityZones() {
  386. return apiService.get('/api/cinder/availzones/')
  387. .error(function () {
  388. toastService.add('error',
  389. gettext('Unable to retrieve the volume availability zones.'));
  390. });
  391. }
  392. }
  393. }());