diff --git a/horizon/karma.conf.js b/horizon/karma.conf.js index 9972fe5a89..65801ca421 100644 --- a/horizon/karma.conf.js +++ b/horizon/karma.conf.js @@ -66,9 +66,7 @@ module.exports = function(config) { // from jasmine_tests.py; only those that are deps for others 'horizon/js/horizon.js', - 'horizon/js/angular/hz.api.module.js', - 'horizon/js/angular/services/**/*.js', - 'horizon/js/angular/hz.api.module.js', + '../../openstack_dashboard/static/openstack-service-api/openstack-service-api.module.js', 'dashboard-app/dashboard-app.module.js', 'dashboard-app/**/*.js', 'auth/auth.module.js', diff --git a/horizon/static/dashboard-app/dashboard-app.module.js b/horizon/static/dashboard-app/dashboard-app.module.js index 1ce06c48c7..1aef3f5cb9 100644 --- a/horizon/static/dashboard-app/dashboard-app.module.js +++ b/horizon/static/dashboard-app/dashboard-app.module.js @@ -5,7 +5,7 @@ angular.module('horizon.dashboard-app', [ 'horizon.framework', 'horizon.auth', - 'hz.api', + 'horizon.openstack-service-api', 'ngCookies'].concat(angularModuleExtension)) .constant('horizon.dashboard-app.conf', { diff --git a/horizon/static/horizon/js/angular/services/hz.api.common.js b/horizon/static/framework/util/http/http.js similarity index 90% rename from horizon/static/horizon/js/angular/services/hz.api.common.js rename to horizon/static/framework/util/http/http.js index 6a2a659c1d..682c89cffe 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.common.js +++ b/horizon/static/framework/util/http/http.js @@ -16,6 +16,13 @@ limitations under the License. (function () { 'use strict'; + + angular + .module('horizon.framework.util.http', []) + .service('horizon.framework.util.http.service', ApiService); + + ApiService.$inject = ['$http']; + function ApiService($http) { var httpCall = function (method, url, data, config) { @@ -49,7 +56,4 @@ limitations under the License. return httpCall('DELETE', url, data, config); }; } - - angular.module('hz.api.common', []) - .service('hz.api.common.service', ['$http', '$log', ApiService]); }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.common.spec.js b/horizon/static/framework/util/http/http.spec.js similarity index 89% rename from horizon/static/horizon/js/angular/services/hz.api.common.spec.js rename to horizon/static/framework/util/http/http.spec.js index d84a983017..5a849a3e16 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.common.spec.js +++ b/horizon/static/framework/util/http/http.spec.js @@ -1,18 +1,18 @@ (function () { 'use strict'; - describe('hz.api.common module', function() { + describe('horizon.framework.util.http module', function() { it('should have been defined', function () { - expect(angular.module('hz.api.common')).toBeDefined(); + expect(angular.module('horizon.framework.util.http')).toBeDefined(); }); }); describe('api service', function () { var api, $httpBackend; - beforeEach(module('hz.api.common')); + beforeEach(module('horizon.framework.util.http')); beforeEach(inject(function ($injector) { - api = $injector.get('hz.api.common.service'); + api = $injector.get('horizon.framework.util.http.service'); $httpBackend = $injector.get('$httpBackend'); })); diff --git a/horizon/static/framework/util/util.module.js b/horizon/static/framework/util/util.module.js index 1d99465f41..9236038f83 100644 --- a/horizon/static/framework/util/util.module.js +++ b/horizon/static/framework/util/util.module.js @@ -1,9 +1,10 @@ (function () { - 'use strict'; + 'use strict'; angular.module('horizon.framework.util', [ 'horizon.framework.util.bind-scope', 'horizon.framework.util.filters', + 'horizon.framework.util.http', 'horizon.framework.util.i18n', 'horizon.framework.util.tech-debt', 'horizon.framework.util.workflow', diff --git a/horizon/static/horizon/js/angular/services/hz.api.neutron.js b/horizon/static/horizon/js/angular/services/hz.api.neutron.js deleted file mode 100644 index 0cbbe92abd..0000000000 --- a/horizon/static/horizon/js/angular/services/hz.api.neutron.js +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Copyright 2015 IBM Corp. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -(function () { - 'use strict'; - - /** - * @ngdoc service - * @name hz.api.NeutronAPI - * @description Provides access to Neutron APIs. - */ - function NeutronAPI(apiService, toastService) { - - // Networks - - /** - * @name hz.api.neturonAPI.getNetworks - * @description - * Get a list of networks for a tenant. - * - * The listing result is an object with property "items". Each item is - * a network. - */ - this.getNetworks = function() { - return apiService.get('/api/neutron/networks/') - .error(function () { - toastService.add('error', gettext('Unable to retrieve the networks.')); - }); - }; - - /** - * @name hz.api.neutronAPI.createNetwork - * @description - * Create a new network. - * @returns The new network object on success. - * - * @param {Object} newNetwork - * The network to create. Required. - * - * Example new network object - * { - * "name": "myNewNetwork", - * "admin_state_up": true, - * "net_profile_id" : "asdsarafssdaser", - * "shared": true, - * "tenant_id": "4fd44f30292945e481c7b8a0c8908869 - * } - * - * Description of properties on the network object - * - * @property {string} newNetwork.name - * The name of the new network. Optional. - * - * @property {boolean} newNetwork.admin_state_up - * The administrative state of the network, which is up (true) or - * down (false). Optional. - * - * @property {string} newNetwork.net_profile_id - * The network profile id. Optional. - * - * @property {boolean} newNetwork.shared - * Indicates whether this network is shared across all tenants. - * By default, only adminstative users can change this value. Optional. - * - * @property {string} newNetwork.tenant_id - * The UUID of the tenant that will own the network. This tenant can - * be different from the tenant that makes the create network request. - * However, only administative users can specify a tenant ID other than - * their own. You cannot change this value through authorization - * policies. Optional. - * - */ - this.createNetwork = function(newNetwork) { - return apiService.post('/api/neutron/networks/', newNetwork) - .error(function () { - toastService.add('error', gettext('Unable to create the network.')); - }); - }; - - // Subnets - - /** - * @name hz.api.neutronAPI.getSubnets - * @description - * Get a list of subnets for a network. - * - * The listing result is an object with property "items". Each item is - * a subnet. - * - * @param {string} network_id - * The network id to retrieve subnets for. Required. - */ - this.getSubnets = function(network_id) { - return apiService.get('/api/neutron/subnets/', network_id) - .error(function () { - toastService.add('error', gettext('Unable to retrieve the subnets.')); - }); - }; - - /** - * @name hz.api.neutronAPI.createSubnet - * @description - * Create a Subnet for given Network. - * @returns The JSON representation of Subnet on success. - * - * @param {Object} newSubnet - * The subnet to create. - * - * Example new subnet object - * { - * "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", - * "ip_version": 4, - * "cidr": "192.168.199.0/24", - * "name": "mySubnet", - * "tenant_id": "4fd44f30292945e481c7b8a0c8908869, - * "allocation_pools": [ - * { - * "start": "192.168.199.2", - * "end": "192.168.199.254" - * } - * ], - * "gateway_ip": "192.168.199.1", - * "id": "abce", - * "enable_dhcp": true, - * } - * - * Description of properties on the subnet object - * @property {string} newSubnet.network_id - * The id of the attached network. Required. - * - * @property {number} newSubnet.ip_version - * The IP version, which is 4 or 6. Required. - * - * @property {string} newSubnet.cidr - * The CIDR. Required. - * - * @property {string} newSubnet.name - * The name of the new subnet. Optional. - * - * @property {string} newSubnet.tenant_id - * The ID of the tenant who owns the network. Only administrative users - * can specify a tenant ID other than their own. Optional. - * - * @property {string|Array} newSubnet.allocation_pools - * The start and end addresses for the allocation pools. Optional. - * - * @property {string} newSubnet.gateway_ip - * The gateway IP address. Optional. - * - * @property {string} newSubnet.id - * The ID of the subnet. Optional. - * - * @property {boolean} newSubnet.enable_dhcp - * Set to true if DHCP is enabled and false if DHCP is disabled. Optional. - * - */ - this.createSubnet = function(newSubnet) { - return apiService.post('/api/neutron/subnets/', newSubnet) - .error(function () { - toastService.add('error', gettext('Unable to create the subnet.')); - }); - }; - - // Ports - - /** - * @name hz.api.neutronAPI.getPorts - * @description - * Get a list of ports for a network. - * - * The listing result is an object with property "items". Each item is - * a port. - * - * @param {string} network_id - * The network id to retrieve ports for. Required. - */ - this.getPorts = function(network_id) { - return apiService.get('/api/neutron/ports/', network_id) - .error(function () { - toastService.add('error', gettext('Unable to retrieve the ports.')); - }); - }; - - } - - angular.module('hz.api') - .service('hz.api.neutron', ['hz.api.common.service', 'horizon.framework.widgets.toast.service', NeutronAPI]); -}()); diff --git a/horizon/test/jasmine/jasmine_tests.py b/horizon/test/jasmine/jasmine_tests.py index 176d4a7995..80ca295e48 100644 --- a/horizon/test/jasmine/jasmine_tests.py +++ b/horizon/test/jasmine/jasmine_tests.py @@ -17,16 +17,15 @@ from horizon.test import helpers as test class ServicesTests(test.JasmineTests): sources = [ 'horizon/js/horizon.js', - 'horizon/js/angular/hz.api.module.js', - 'horizon/js/angular/services/hz.api.common.js', - 'horizon/js/angular/services/hz.api.cinder.js', - 'horizon/js/angular/services/hz.api.config.js', - 'horizon/js/angular/services/hz.api.glance.js', - 'horizon/js/angular/services/hz.api.keystone.js', - 'horizon/js/angular/services/hz.api.neutron.js', - 'horizon/js/angular/services/hz.api.nova.js', - 'horizon/js/angular/services/hz.api.policy.js', - 'horizon/js/angular/services/hz.api.security-group.js', + 'openstack-service-api/openstack-service-api.module.js', + 'openstack-service-api/settings.service.js', + 'openstack-service-api/cinder.service.js', + 'openstack-service-api/glance.service.js', + 'openstack-service-api/keystone.service.js', + 'openstack-service-api/neutron.service.js', + 'openstack-service-api/nova.service.js', + 'openstack-service-api/policy.service.js', + 'openstack-service-api/security-group.service.js', 'auth/auth.module.js', 'auth/login/login.module.js', @@ -42,6 +41,7 @@ class ServicesTests(test.JasmineTests): 'framework/util/util.module.js', 'framework/util/bind-scope/bind-scope.js', 'framework/util/filters/filters.js', + 'framework/util/http/http.js', 'framework/util/i18n/i18n.js', 'framework/util/validators/validators.js', 'framework/util/workflow/workflow.js', @@ -73,21 +73,21 @@ class ServicesTests(test.JasmineTests): 'framework/widgets/toast/toast.factory.js', ] specs = [ - 'horizon/js/angular/services/hz.api.common.spec.js', - 'horizon/js/angular/services/hz.api.common-test.spec.js', - 'horizon/js/angular/services/hz.api.cinder.spec.js', - 'horizon/js/angular/services/hz.api.config.spec.js', - 'horizon/js/angular/services/hz.api.glance.spec.js', - 'horizon/js/angular/services/hz.api.keystone.spec.js', - 'horizon/js/angular/services/hz.api.neutron.spec.js', - 'horizon/js/angular/services/hz.api.nova.spec.js', - 'horizon/js/angular/services/hz.api.policy.spec.js', - 'horizon/js/angular/services/hz.api.security-group.spec.js', - 'auth/login/login.spec.js', + 'openstack-service-api/common-test.spec.js', + 'openstack-service-api/settings.service.spec.js', + 'openstack-service-api/cinder.service.spec.js', + 'openstack-service-api/glance.service.spec.js', + 'openstack-service-api/keystone.service.spec.js', + 'openstack-service-api/neutron.service.spec.js', + 'openstack-service-api/nova.service.spec.js', + 'openstack-service-api/policy.service.spec.js', + 'openstack-service-api/security-group.service.spec.js', + 'framework/util/bind-scope/bind-scope.spec.js', 'framework/util/filters/filters.spec.js', + 'framework/util/http/http.spec.js', 'framework/util/i18n/i18n.spec.js', 'framework/util/tech-debt/helper-functions.spec.js', 'framework/util/validators/validators.spec.js', diff --git a/openstack_dashboard/karma.conf.js b/openstack_dashboard/karma.conf.js index 16d7c28cf2..bcb2b27063 100644 --- a/openstack_dashboard/karma.conf.js +++ b/openstack_dashboard/karma.conf.js @@ -64,6 +64,13 @@ module.exports = function(config) { xstaticPath + 'spin/data/spin.js', xstaticPath + 'spin/data/spin.jquery.js', + // TODO: Should these be mocked? + '../../horizon/static/horizon/js/horizon.js', + '../../horizon/static/framework/util/http/http.js', + + 'openstack-service-api/openstack-service-api.module.js', + 'openstack-service-api/**/*.js', + // This one seems to have to come first. "dashboard/dashboard.module.js", "dashboard/workflow/workflow.js", diff --git a/openstack_dashboard/static/dashboard/cloud-services/cloud-services.js b/openstack_dashboard/static/dashboard/cloud-services/cloud-services.js index 8c3a054b02..93488017ff 100644 --- a/openstack_dashboard/static/dashboard/cloud-services/cloud-services.js +++ b/openstack_dashboard/static/dashboard/cloud-services/cloud-services.js @@ -42,15 +42,15 @@ */ .factory('cloudServices', [ - 'hz.api.cinder', - 'hz.api.glance', - 'hz.api.keystone', - 'hz.api.neutron', - 'hz.api.nova', - 'hz.api.novaExtensions', - 'hz.api.security-group', - 'hz.api.serviceCatalog', - 'hz.api.settingsService', + 'horizon.openstack-service-api.cinder', + 'horizon.openstack-service-api.glance', + 'horizon.openstack-service-api.keystone', + 'horizon.openstack-service-api.neutron', + 'horizon.openstack-service-api.nova', + 'horizon.openstack-service-api.novaExtensions', + 'horizon.openstack-service-api.security-group', + 'horizon.openstack-service-api.serviceCatalog', + 'horizon.openstack-service-api.settings', function (cinderAPI, glanceAPI, diff --git a/openstack_dashboard/static/dashboard/cloud-services/cloud-services.spec.js b/openstack_dashboard/static/dashboard/cloud-services/cloud-services.spec.js index 236a758942..baa494c9de 100644 --- a/openstack_dashboard/static/dashboard/cloud-services/cloud-services.spec.js +++ b/openstack_dashboard/static/dashboard/cloud-services/cloud-services.spec.js @@ -25,15 +25,15 @@ var cloudServices; beforeEach(module('hz.dashboard', function ($provide) { - $provide.value('hz.api.cinder', {}); - $provide.value('hz.api.glance', {}); - $provide.value('hz.api.keystone', {}); - $provide.value('hz.api.neutron', {}); - $provide.value('hz.api.nova', {}); - $provide.value('hz.api.novaExtensions', {}); - $provide.value('hz.api.security-group', {}); - $provide.value('hz.api.serviceCatalog', {}); - $provide.value('hz.api.settingsService', {}); + $provide.value('horizon.openstack-service-api.cinder', {}); + $provide.value('horizon.openstack-service-api.glance', {}); + $provide.value('horizon.openstack-service-api.keystone', {}); + $provide.value('horizon.openstack-service-api.neutron', {}); + $provide.value('horizon.openstack-service-api.nova', {}); + $provide.value('horizon.openstack-service-api.novaExtensions', {}); + $provide.value('horizon.openstack-service-api.security-group', {}); + $provide.value('horizon.openstack-service-api.serviceCatalog', {}); + $provide.value('horizon.openstack-service-api.settings', {}); })); beforeEach(inject(function ($injector) { diff --git a/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.js b/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.js index 0d4cfd85e5..de38c1d722 100644 --- a/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.js +++ b/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.js @@ -159,7 +159,7 @@ */ module.controller('LaunchInstanceCreateKeyPairCtrl', [ '$modalInstance', - 'hz.api.nova', + 'horizon.openstack-service-api.nova', 'horizon.framework.widgets.toast.service', LaunchInstanceCreateKeyPairCtrl ]); @@ -235,7 +235,7 @@ */ module.controller('LaunchInstanceImportKeyPairCtrl', [ '$modalInstance', - 'hz.api.nova', + 'horizon.openstack-service-api.nova', 'horizon.framework.widgets.toast.service', LaunchInstanceImportKeyPairCtrl ]); diff --git a/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.spec.js b/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.spec.js index a255a649e8..95e8c6cbc2 100644 --- a/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.spec.js +++ b/openstack_dashboard/static/dashboard/launch-instance/keypair/keypair.spec.js @@ -100,7 +100,7 @@ beforeEach(module(function ($provide) { $provide.value('$modalInstance', {}); - $provide.value('hz.api.nova', {}); + $provide.value('horizon.openstack-service-api.nova', {}); $provide.value('horizon.framework.widgets.toast.service', {}); })); @@ -159,7 +159,7 @@ beforeEach(module(function ($provide) { $provide.value('$modalInstance', {}); - $provide.value('hz.api.nova', {}); + $provide.value('horizon.openstack-service-api.nova', {}); $provide.value('horizon.framework.widgets.toast.service', {}); })); diff --git a/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.js b/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.js index d8b4967d1a..76dc14564f 100644 --- a/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.js +++ b/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.js @@ -28,14 +28,14 @@ */ module.factory('launchInstanceModel', ['$q', '$log', - 'hz.api.cinder', - 'hz.api.glance', - 'hz.api.keystone', - 'hz.api.neutron', - 'hz.api.nova', - 'hz.api.novaExtensions', - 'hz.api.security-group', - 'hz.api.serviceCatalog', + 'horizon.openstack-service-api.cinder', + 'horizon.openstack-service-api.glance', + 'horizon.openstack-service-api.keystone', + 'horizon.openstack-service-api.neutron', + 'horizon.openstack-service-api.nova', + 'horizon.openstack-service-api.novaExtensions', + 'horizon.openstack-service-api.security-group', + 'horizon.openstack-service-api.serviceCatalog', function ($q, $log, diff --git a/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.spec.js b/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.spec.js index d6c3c0bd47..5ee8ad2e62 100644 --- a/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.spec.js +++ b/openstack_dashboard/static/dashboard/launch-instance/launch-instance.model.spec.js @@ -29,7 +29,7 @@ beforeEach(module('hz.dashboard.launch-instance')); beforeEach(module(function($provide) { - $provide.value('hz.api.glance', { + $provide.value('horizon.openstack-service-api.glance', { getImages: function() { var images = [ { container_format: 'aki', properties: {} }, @@ -55,7 +55,7 @@ } }); - $provide.value('hz.api.nova', { + $provide.value('horizon.openstack-service-api.nova', { createServer: function(finalSpec) { return finalSpec; }, @@ -99,7 +99,7 @@ } }); - $provide.value('hz.api.security-group', { + $provide.value('horizon.openstack-service-api.security-group', { query: function() { var secGroups = [ { name: 'security-group-1' }, @@ -113,7 +113,7 @@ } }); - $provide.value('hz.api.neutron', { + $provide.value('horizon.openstack-service-api.neutron', { getNetworks: function() { var networks = [ { id: 'net-1' }, { id: 'net-2' } ]; @@ -124,7 +124,7 @@ } }); - $provide.value('hz.api.cinder', { + $provide.value('horizon.openstack-service-api.cinder', { getVolumes: function() { var volumes = [ { id: 'vol-1' }, { id: 'vol-2' } ]; @@ -143,7 +143,7 @@ } }); - $provide.value('hz.api.serviceCatalog', { + $provide.value('horizon.openstack-service-api.serviceCatalog', { ifTypeEnabled: function(theType) { var deferred = $q.defer(); @@ -159,7 +159,7 @@ } }); - $provide.value('hz.api.novaExtensions', { + $provide.value('horizon.openstack-service-api.novaExtensions', { ifNameEnabled: function() { var deferred = $q.defer(); @@ -173,7 +173,7 @@ } }); - $provide.value('hz.api.keystone', {}); + $provide.value('horizon.openstack-service-api.keystone', {}); })); beforeEach(inject(function(launchInstanceModel, $rootScope, _$q_) { diff --git a/openstack_dashboard/static/dashboard/launch-instance/launch-instance.spec.js b/openstack_dashboard/static/dashboard/launch-instance/launch-instance.spec.js index 4485834980..2444891d19 100644 --- a/openstack_dashboard/static/dashboard/launch-instance/launch-instance.spec.js +++ b/openstack_dashboard/static/dashboard/launch-instance/launch-instance.spec.js @@ -36,7 +36,7 @@ return spec; }; - $provide.value('hz.api.serviceCatalog', {}); + $provide.value('horizon.openstack-service-api.serviceCatalog', {}); $provide.value('horizon.framework.util.workflow.service', workflow); })); diff --git a/openstack_dashboard/static/dashboard/workflow/workflow.js b/openstack_dashboard/static/dashboard/workflow/workflow.js index e8c2afc578..afbd8ddc40 100644 --- a/openstack_dashboard/static/dashboard/workflow/workflow.js +++ b/openstack_dashboard/static/dashboard/workflow/workflow.js @@ -34,7 +34,7 @@ * * Injected dependencies: * - $q - * - serviceCatalog hz.api.serviceCatalog + * - serviceCatalog horizon.openstack-service-api.serviceCatalog * * @param {Object} spec The input workflow specification object. * @returns {Object} The decorated workflow specification object, the same @@ -46,7 +46,7 @@ * */ - .factory('dashboardWorkflowDecorator', ['$q', 'hz.api.serviceCatalog', + .factory('dashboardWorkflowDecorator', ['$q', 'horizon.openstack-service-api.serviceCatalog', function ($q, serviceCatalog) { diff --git a/horizon/static/horizon/js/angular/services/hz.api.cinder.js b/openstack_dashboard/static/openstack-service-api/cinder.service.js similarity index 83% rename from horizon/static/horizon/js/angular/services/hz.api.cinder.js rename to openstack_dashboard/static/openstack-service-api/cinder.service.js index 50c1991bad..6ac5456f1e 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.cinder.js +++ b/openstack_dashboard/static/openstack-service-api/cinder.service.js @@ -16,9 +16,16 @@ limitations under the License. (function () { 'use strict'; + angular + .module('horizon.openstack-service-api') + .service('horizon.openstack-service-api.cinder', CinderAPI); + + CinderAPI.$inject = ['horizon.framework.util.http.service', + 'horizon.framework.widgets.toast.service']; + /** * @ngdoc service - * @name hz.api.cinderAPI + * @name horizon.openstack-service-api.cinder * @description Provides direct access to Cinder APIs. */ function CinderAPI(apiService, toastService) { @@ -26,7 +33,7 @@ limitations under the License. // Volumes /** - * @name hz.api.cinderAPI.getVolumes + * @name horizon.openstack-service-api.cinder.getVolumes * @description * Get a list of volumes. * @@ -51,7 +58,7 @@ limitations under the License. // Volume Snapshots /** - * @name hz.api.cinderAPI.getVolumeSnapshots + * @name horizon.openstack-service-api.cinder.getVolumeSnapshots * @description * Get a list of volume snapshots. * @@ -75,9 +82,4 @@ limitations under the License. }); }; } - - // Register it with the API module so that anybody using the - // API module will have access to the Cinder APIs. - angular.module('hz.api') - .service('hz.api.cinder', ['hz.api.common.service', 'horizon.framework.widgets.toast.service', CinderAPI]); }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.cinder.spec.js b/openstack_dashboard/static/openstack-service-api/cinder.service.spec.js similarity index 93% rename from horizon/static/horizon/js/angular/services/hz.api.cinder.spec.js rename to openstack_dashboard/static/openstack-service-api/cinder.service.spec.js index 1ef680bf5b..2e049e039b 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.cinder.spec.js +++ b/openstack_dashboard/static/openstack-service-api/cinder.service.spec.js @@ -22,13 +22,13 @@ var apiService = {}; var toastService = {}; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { window.apiTest.initServices($provide, apiService, toastService); })); - beforeEach(inject(['hz.api.cinder', function(cinderAPI) { + beforeEach(inject(['horizon.openstack-service-api.cinder', function(cinderAPI) { service = cinderAPI; }])); diff --git a/horizon/static/horizon/js/angular/services/hz.api.common-test.spec.js b/openstack_dashboard/static/openstack-service-api/common-test.spec.js similarity index 97% rename from horizon/static/horizon/js/angular/services/hz.api.common-test.spec.js rename to openstack_dashboard/static/openstack-service-api/common-test.spec.js index 59b664a321..9bb30aca4b 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.common-test.spec.js +++ b/openstack_dashboard/static/openstack-service-api/common-test.spec.js @@ -74,7 +74,7 @@ patch: angular.noop, delete: angular.noop }); angular.extend(toastService, { add: angular.noop }); - $provide.value('hz.api.common.service', apiService); + $provide.value('horizon.framework.util.http.service', apiService); $provide.value('horizon.framework.widgets.toast.service', toastService); } diff --git a/horizon/static/horizon/js/angular/services/hz.api.glance.js b/openstack_dashboard/static/openstack-service-api/glance.service.js similarity index 89% rename from horizon/static/horizon/js/angular/services/hz.api.glance.js rename to openstack_dashboard/static/openstack-service-api/glance.service.js index 573791cda0..87787065a6 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.glance.js +++ b/openstack_dashboard/static/openstack-service-api/glance.service.js @@ -16,17 +16,24 @@ limitations under the License. (function () { 'use strict'; + angular + .module('horizon.openstack-service-api') + .service('horizon.openstack-service-api.glance', GlanceAPI); + + GlanceAPI.$inject = ['horizon.framework.util.http.service', + 'horizon.framework.widgets.toast.service']; + /** * @ngdoc service - * @name hz.api.glanceAPI + * @name horizon.openstack-service-api.glance * @description Provides direct pass through to Glance with NO abstraction. */ function GlanceAPI(apiService, toastService) { // Images - /** - * @name hz.api.glanceAPI.getImage + /** + * @name horizon.openstack-service-api.glance.getImage * @description * Get a single image by ID * @param {string} id @@ -36,12 +43,11 @@ limitations under the License. return apiService.get('/api/glance/images/' + id) .error(function () { toastService.add('error', gettext('Unable to retrieve the image.')); - }); + }); }; - /** - * @name hz.api.glanceAPI.getImages + * @name horizon.openstack-service-api.glance.getImages * @description * Get a list of images. * @@ -79,13 +85,13 @@ limitations under the License. return apiService.get('/api/glance/images/', config) .error(function () { toastService.add('error', gettext('Unable to retrieve the images.')); - }); + }); }; // Metadata Definitions - Namespaces /** - * @name hz.api.glanceAPI.getNamespaces + * @name horizon.openstack-service-api.glance.getNamespaces * @description * Get a list of metadata definition namespaces. * @@ -146,11 +152,4 @@ limitations under the License. }; } - - // Register it with the API module so that anybody using the - // API module will have access to the Glance APIs. - - angular.module('hz.api') - .service('hz.api.glance', ['hz.api.common.service', 'horizon.framework.widgets.toast.service', GlanceAPI]); - }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.glance.spec.js b/openstack_dashboard/static/openstack-service-api/glance.service.spec.js similarity index 95% rename from horizon/static/horizon/js/angular/services/hz.api.glance.spec.js rename to openstack_dashboard/static/openstack-service-api/glance.service.spec.js index be5c9f39c0..a308434028 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.glance.spec.js +++ b/openstack_dashboard/static/openstack-service-api/glance.service.spec.js @@ -22,13 +22,13 @@ var apiService = {}; var toastService = {}; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { window.apiTest.initServices($provide, apiService, toastService); })); - beforeEach(inject(['hz.api.glance', function(glanceAPI) { + beforeEach(inject(['horizon.openstack-service-api.glance', function(glanceAPI) { service = glanceAPI; }])); diff --git a/horizon/static/horizon/js/angular/services/hz.api.keystone.js b/openstack_dashboard/static/openstack-service-api/keystone.service.js similarity index 81% rename from horizon/static/horizon/js/angular/services/hz.api.keystone.js rename to openstack_dashboard/static/openstack-service-api/keystone.service.js index 4edfcba2e3..bf62c19c87 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.keystone.js +++ b/openstack_dashboard/static/openstack-service-api/keystone.service.js @@ -15,13 +15,21 @@ limitations under the License. */ (function () { 'use strict'; + + angular + .module('horizon.openstack-service-api') + .service('horizon.openstack-service-api.keystone', KeystoneAPI); + + KeystoneAPI.$inject = ['horizon.framework.util.http.service', + 'horizon.framework.widgets.toast.service']; + function KeystoneAPI(apiService, toastService) { // Users this.getUsers = function(params) { var config = (params) ? {'params': params} : {}; return apiService.get('/api/keystone/users/', config) .error(function () { - toastService.add('error', gettext('Unable to retrieve users.')); + toastService.add('error', gettext('Unable to retrieve the users.')); }); }; @@ -32,15 +40,15 @@ limitations under the License. }); }; - this.deleteUsers = function(user_ids) { - return apiService.delete('/api/keystone/users/', user_ids) + this.deleteUsers = function(userIds) { + return apiService.delete('/api/keystone/users/', userIds) .error(function () { toastService.add('error', gettext('Unable to delete the users.')); }); }; /** - * @name hz.api.keystoneApi.getCurrentUserSession + * @name horizon.openstack-service-api.keystone.getCurrentUserSession * @description * Gets the current User Session Information * @example @@ -74,8 +82,8 @@ limitations under the License. }); }; - this.getUser = function(user_id) { - return apiService.get('/api/keystone/users/' + user_id) + this.getUser = function(userId) { + return apiService.get('/api/keystone/users/' + userId) .error(function () { toastService.add('error', gettext('Unable to retrieve the user.')); }); @@ -89,8 +97,8 @@ limitations under the License. }); }; - this.deleteUser = function(user_id) { - return apiService.delete('/api/keystone/users/' + user_id) + this.deleteUser = function(userId) { + return apiService.delete('/api/keystone/users/' + userId) .error(function () { toastService.add('error', gettext('Unable to delete the user.')); }); @@ -111,15 +119,15 @@ limitations under the License. }); }; - this.deleteRoles = function(role_ids) { - return apiService.delete('/api/keystone/roles/', role_ids) + this.deleteRoles = function(roleIds) { + return apiService.delete('/api/keystone/roles/', roleIds) .error(function () { toastService.add('error', gettext('Unable to delete the roles.')); }); }; - this.getRole = function(role_id) { - return apiService.get('/api/keystone/roles/' + role_id) + this.getRole = function(roleId) { + return apiService.get('/api/keystone/roles/' + roleId) .error(function () { toastService.add('error', gettext('Unable to retrieve the role.')); }); @@ -133,8 +141,8 @@ limitations under the License. }); }; - this.deleteRole = function(role_id) { - return apiService.delete('/api/keystone/roles/' + role_id) + this.deleteRole = function(roleId) { + return apiService.delete('/api/keystone/roles/' + roleId) .error(function () { toastService.add('error', gettext('Unable to delete the role.')); }); @@ -155,15 +163,15 @@ limitations under the License. }); }; - this.deleteDomains = function(domain_ids) { - return apiService.delete('/api/keystone/domains/', domain_ids) + this.deleteDomains = function(domainIds) { + return apiService.delete('/api/keystone/domains/', domainIds) .error(function () { toastService.add('error', gettext('Unable to delete the domains.')); }); }; - this.getDomain = function(domain_id) { - return apiService.get('/api/keystone/domains/' + domain_id) + this.getDomain = function(domainId) { + return apiService.get('/api/keystone/domains/' + domainId) .error(function () { toastService.add('error', gettext('Unable to retrieve the domain.')); }); @@ -177,8 +185,8 @@ limitations under the License. }); }; - this.deleteDomain = function(domain_id) { - return apiService.delete('/api/keystone/domains/' + domain_id) + this.deleteDomain = function(domainId) { + return apiService.delete('/api/keystone/domains/' + domainId) .error(function () { toastService.add('error', gettext('Unable to delete the domain.')); }); @@ -200,15 +208,15 @@ limitations under the License. }); }; - this.deleteProjects = function(project_ids) { - return apiService.delete('/api/keystone/projects/', project_ids) + this.deleteProjects = function(projectIds) { + return apiService.delete('/api/keystone/projects/', projectIds) .error(function () { toastService.add('error', gettext('Unable to delete the projects.')); }); }; - this.getProject = function(project_id) { - return apiService.get('/api/keystone/projects/' + project_id) + this.getProject = function(projectId) { + return apiService.get('/api/keystone/projects/' + projectId) .error(function () { toastService.add('error', gettext('Unable to retrieve the project.')); }); @@ -222,23 +230,23 @@ limitations under the License. }); }; - this.deleteProject = function(project_id) { - return apiService.delete('/api/keystone/projects/' + project_id) + this.deleteProject = function(projectId) { + return apiService.delete('/api/keystone/projects/' + projectId) .error(function () { toastService.add('error', gettext('Unable to delete the project.')); }); }; - this.grantRole = function(project_id, role_id, user_id) { - return apiService.put('/api/keystone/projects/' + project_id + '/' + - role_id + '/' + user_id) + this.grantRole = function(projectId, roleId, userId) { + return apiService.put('/api/keystone/projects/' + projectId + '/' + + roleId + '/' + userId) .error(function () { toastService.add('error', gettext('Unable to grant the role.')); }); }; - /** - * @name hz.api.keyStoneAPI.serviceCatalog + /** + * @name horizon.openstack-service-api.keystone.serviceCatalog * @description * Returns the service catalog. * @param {Object} config @@ -252,12 +260,9 @@ limitations under the License. }; } - angular.module('hz.api') - .service('hz.api.keystone', ['hz.api.common.service', 'horizon.framework.widgets.toast.service', KeystoneAPI]); - - /** + /** * @ngdoc service - * @name hz.api.userSession + * @name horizon.openstack-service-api.userSession * @description * Provides cached access to the user session. The cache may be reset * at any time by accessing the cache and calling removeAll, which means @@ -276,11 +281,17 @@ limitations under the License. * and used transparently where needed without making every single use of it * pass it through as an argument. */ + angular + .module('horizon.openstack-service-api') + .factory('horizon.openstack-service-api.userSession', userSession); + + userSession.$inject = ['$cacheFactory', 'horizon.openstack-service-api.keystone']; + function userSession($cacheFactory, keystoneAPI) { var service = {}; - service.cache = $cacheFactory('hz.api.userSession', {capacity: 1}); + service.cache = $cacheFactory('horizon.openstack-service-api.userSession', {capacity: 1}); service.get = function () { return keystoneAPI.getCurrentUserSession({cache: service.cache}) @@ -293,12 +304,9 @@ limitations under the License. return service; } - angular.module('hz.api') - .factory('hz.api.userSession', ['$cacheFactory', 'hz.api.keystone', userSession]); - /** * @ngdoc service - * @name hz.api.serviceCatalog + * @name horizon.openstack-service-api.serviceCatalog * @description * Provides cached access to the Service Catalog with utilities to help * with asynchronous data loading. The cache may be reset at any time @@ -316,13 +324,22 @@ limitations under the License. * and used transparently where needed without making every single use of it * pass it through as an argument. */ + angular + .module('horizon.openstack-service-api') + .factory('horizon.openstack-service-api.serviceCatalog', serviceCatalog); + + serviceCatalog.$inject = ['$cacheFactory', + '$q', + 'horizon.openstack-service-api.keystone', + 'horizon.openstack-service-api.userSession']; + function serviceCatalog($cacheFactory, $q, keystoneAPI, userSession) { var service = {}; - service.cache = $cacheFactory('hz.api.serviceCatalog', {capacity: 1}); + service.cache = $cacheFactory('horizon.openstack-service-api.serviceCatalog', {capacity: 1}); - /** - * @name hz.api.serviceCatalog.get + /** + * @name horizon.openstack-service-api.serviceCatalog.get * @description * Returns the service catalog. This is cached. * @@ -335,14 +352,14 @@ limitations under the License. */ service.get = function() { return keystoneAPI.serviceCatalog({cache: service.cache}) - .then(function(response){ + .then(function(response) { return response.data; } ); }; /** - * @name hz.api.serviceCatalog.ifTypeEnabled + * @name horizon.openstack-service-api.serviceCatalog.ifTypeEnabled * @description * Checks if the desired service is enabled. If it is enabled, use the * promise returned to execute the desired function. If it is not enabled, @@ -426,12 +443,4 @@ limitations under the License. return service; } - - angular.module('hz.api') - .factory('hz.api.serviceCatalog', ['$cacheFactory', - '$q', - 'hz.api.keystone', - 'hz.api.userSession', - serviceCatalog]); - }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.keystone.spec.js b/openstack_dashboard/static/openstack-service-api/keystone.service.spec.js similarity index 94% rename from horizon/static/horizon/js/angular/services/hz.api.keystone.spec.js rename to openstack_dashboard/static/openstack-service-api/keystone.service.spec.js index b24f5b7707..efe281d25d 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.keystone.spec.js +++ b/openstack_dashboard/static/openstack-service-api/keystone.service.spec.js @@ -22,13 +22,13 @@ var apiService = {}; var toastService = {}; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { window.apiTest.initServices($provide, apiService, toastService); })); - beforeEach(inject(['hz.api.keystone', function(keystoneAPI) { + beforeEach(inject(['horizon.openstack-service-api.keystone', function(keystoneAPI) { service = keystoneAPI; }])); @@ -42,7 +42,7 @@ "method": "get", "path": "/api/keystone/users/", "data": {}, - "error": "Unable to retrieve users." + "error": "Unable to retrieve the users." }, { "func": "getUsers", @@ -53,7 +53,7 @@ "info": true } }, - "error": "Unable to retrieve users.", + "error": "Unable to retrieve the users.", "testInput": [ { "info": true @@ -385,15 +385,15 @@ describe("userSession", function() { var factory, keystoneAPI; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { keystoneAPI = {getCurrentUserSession: angular.noop}; - $provide.value('hz.api.keystone', keystoneAPI); + $provide.value('horizon.openstack-service-api.keystone', keystoneAPI); $provide.value('$cacheFactory', function() { return 'cache'; }); })); - beforeEach(inject(['hz.api.userSession', function(userSession) { + beforeEach(inject(['horizon.openstack-service-api.userSession', function(userSession) { factory = userSession; }])); @@ -433,13 +433,13 @@ describe("serviceCatalog", function() { var factory, q, keystoneAPI, userSession, deferred; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { keystoneAPI = {serviceCatalog: angular.noop}; - $provide.value('hz.api.keystone', keystoneAPI); + $provide.value('horizon.openstack-service-api.keystone', keystoneAPI); userSession = {get: angular.noop}; - $provide.value('hz.api.userSession', userSession); + $provide.value('horizon.openstack-service-api.userSession', userSession); deferred = {promise: angular.noop, reject: angular.noop, resolve: angular.noop}; q = {all: function() {return {then: angular.noop};}, defer: function() { return deferred;}}; @@ -447,7 +447,7 @@ $provide.value('$cacheFactory', function() { return 'cache'; }); })); - beforeEach(inject(['hz.api.serviceCatalog', function(serviceCatalog) { + beforeEach(inject(['horizon.openstack-service-api.serviceCatalog', function(serviceCatalog) { factory = serviceCatalog; }])); diff --git a/openstack_dashboard/static/openstack-service-api/neutron.service.js b/openstack_dashboard/static/openstack-service-api/neutron.service.js new file mode 100644 index 0000000000..1d80c320cc --- /dev/null +++ b/openstack_dashboard/static/openstack-service-api/neutron.service.js @@ -0,0 +1,204 @@ +/** + * Copyright 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +(function () { + 'use strict'; + + angular + .module('horizon.openstack-service-api') + .service('horizon.openstack-service-api.neutron', NeutronAPI); + + NeutronAPI.$inject = ['horizon.framework.util.http.service', + 'horizon.framework.widgets.toast.service']; + + /** + * @ngdoc service + * @name horizon.openstack-service-api.neutron + * @description Provides access to Neutron APIs. + */ + function NeutronAPI(apiService, toastService) { + + // Networks + + /** + * @name horizon.openstack-service-api.neturonAPI.getNetworks + * @description + * Get a list of networks for a tenant. + * + * The listing result is an object with property "items". Each item is + * a network. + */ + this.getNetworks = function() { + return apiService.get('/api/neutron/networks/') + .error(function () { + toastService.add('error', gettext('Unable to retrieve the networks.')); + }); + }; + + /** + * @name horizon.openstack-service-api.neutron.createNetwork + * @description + * Create a new network. + * @returns The new network object on success. + * + * @param {Object} newNetwork + * The network to create. Required. + * + * Example new network object + * { + * "name": "myNewNetwork", + * "admin_state_up": true, + * "net_profile_id" : "asdsarafssdaser", + * "shared": true, + * "tenant_id": "4fd44f30292945e481c7b8a0c8908869 + * } + * + * Description of properties on the network object + * + * @property {string} newNetwork.name + * The name of the new network. Optional. + * + * @property {boolean} newNetwork.admin_state_up + * The administrative state of the network, which is up (true) or + * down (false). Optional. + * + * @property {string} newNetwork.net_profile_id + * The network profile id. Optional. + * + * @property {boolean} newNetwork.shared + * Indicates whether this network is shared across all tenants. + * By default, only adminstative users can change this value. Optional. + * + * @property {string} newNetwork.tenant_id + * The UUID of the tenant that will own the network. This tenant can + * be different from the tenant that makes the create network request. + * However, only administative users can specify a tenant ID other than + * their own. You cannot change this value through authorization + * policies. Optional. + * + */ + this.createNetwork = function(newNetwork) { + return apiService.post('/api/neutron/networks/', newNetwork) + .error(function () { + toastService.add('error', gettext('Unable to create the network.')); + }); + }; + + // Subnets + + /** + * @name horizon.openstack-service-api.neutron.getSubnets + * @description + * Get a list of subnets for a network. + * + * The listing result is an object with property "items". Each item is + * a subnet. + * + * @param {string} networkId + * The network id to retrieve subnets for. Required. + */ + this.getSubnets = function(networkId) { + return apiService.get('/api/neutron/subnets/', networkId) + .error(function () { + toastService.add('error', gettext('Unable to retrieve the subnets.')); + }); + }; + + /** + * @name horizon.openstack-service-api.neutron.createSubnet + * @description + * Create a Subnet for given Network. + * @returns The JSON representation of Subnet on success. + * + * @param {Object} newSubnet + * The subnet to create. + * + * Example new subnet object + * { + * "network_id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", + * "ip_version": 4, + * "cidr": "192.168.199.0/24", + * "name": "mySubnet", + * "tenant_id": "4fd44f30292945e481c7b8a0c8908869, + * "allocation_pools": [ + * { + * "start": "192.168.199.2", + * "end": "192.168.199.254" + * } + * ], + * "gateway_ip": "192.168.199.1", + * "id": "abce", + * "enable_dhcp": true, + * } + * + * Description of properties on the subnet object + * @property {string} newSubnet.network_id + * The id of the attached network. Required. + * + * @property {number} newSubnet.ip_version + * The IP version, which is 4 or 6. Required. + * + * @property {string} newSubnet.cidr + * The CIDR. Required. + * + * @property {string} newSubnet.name + * The name of the new subnet. Optional. + * + * @property {string} newSubnet.tenant_id + * The ID of the tenant who owns the network. Only administrative users + * can specify a tenant ID other than their own. Optional. + * + * @property {string|Array} newSubnet.allocation_pools + * The start and end addresses for the allocation pools. Optional. + * + * @property {string} newSubnet.gateway_ip + * The gateway IP address. Optional. + * + * @property {string} newSubnet.id + * The ID of the subnet. Optional. + * + * @property {boolean} newSubnet.enable_dhcp + * Set to true if DHCP is enabled and false if DHCP is disabled. Optional. + * + */ + this.createSubnet = function(newSubnet) { + return apiService.post('/api/neutron/subnets/', newSubnet) + .error(function () { + toastService.add('error', gettext('Unable to create the subnet.')); + }); + }; + + // Ports + + /** + * @name horizon.openstack-service-api.neutron.getPorts + * @description + * Get a list of ports for a network. + * + * The listing result is an object with property "items". Each item is + * a port. + * + * @param {string} networkId + * The network id to retrieve ports for. Required. + */ + this.getPorts = function(networkId) { + return apiService.get('/api/neutron/ports/', networkId) + .error(function () { + toastService.add('error', gettext('Unable to retrieve the ports.')); + }); + }; + + } +}()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.neutron.spec.js b/openstack_dashboard/static/openstack-service-api/neutron.service.spec.js similarity index 94% rename from horizon/static/horizon/js/angular/services/hz.api.neutron.spec.js rename to openstack_dashboard/static/openstack-service-api/neutron.service.spec.js index bee55e13f0..0e67a8aa70 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.neutron.spec.js +++ b/openstack_dashboard/static/openstack-service-api/neutron.service.spec.js @@ -22,13 +22,13 @@ var apiService = {}; var toastService = {}; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { window.apiTest.initServices($provide, apiService, toastService); })); - beforeEach(inject(['hz.api.neutron', function(neutronAPI) { + beforeEach(inject(['horizon.openstack-service-api.neutron', function(neutronAPI) { service = neutronAPI; }])); diff --git a/horizon/static/horizon/js/angular/services/hz.api.nova.js b/openstack_dashboard/static/openstack-service-api/nova.service.js similarity index 73% rename from horizon/static/horizon/js/angular/services/hz.api.nova.js rename to openstack_dashboard/static/openstack-service-api/nova.service.js index 76fa328998..e77f155a1a 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.nova.js +++ b/openstack_dashboard/static/openstack-service-api/nova.service.js @@ -16,23 +16,30 @@ limitations under the License. (function () { 'use strict'; - /** + angular + .module('horizon.openstack-service-api') + .service('horizon.openstack-service-api.nova', NovaAPI); + + NovaAPI.$inject = ['horizon.framework.util.http.service', + 'horizon.framework.widgets.toast.service']; + + /** * @ngdoc service - * @name hz.api.novaAPI + * @name horizon.openstack-service-api.nova * @description Provides access to Nova APIs. */ function NovaAPI(apiService, toastService) { - // Keypairs + // Keypairs - /** - * @name hz.api.novaAPI.getKeypairs - * @description - * Get a list of keypairs. - * - * The listing result is an object with property "items". Each item is - * a keypair. - */ + /** + * @name horizon.openstack-service-api.nova.getKeypairs + * @description + * Get a list of keypairs. + * + * The listing result is an object with property "items". Each item is + * a keypair. + */ this.getKeypairs = function() { return apiService.get('/api/nova/keypairs/') .error(function () { @@ -40,20 +47,20 @@ limitations under the License. }); }; - /** - * @name hz.api.novaAPI.createKeypair - * @description - * Create a new keypair. This returns the new keypair object on success. - * - * @param {Object} newKeypair - * The keypair to create. - * - * @param {string} newKeypair.name - * The name of the new keypair. Required. - * - * @param {string} newKeypair.public_key - * The public key. Optional. - */ + /** + * @name horizon.openstack-service-api.nova.createKeypair + * @description + * Create a new keypair. This returns the new keypair object on success. + * + * @param {Object} newKeypair + * The keypair to create. + * + * @param {string} newKeypair.name + * The name of the new keypair. Required. + * + * @param {string} newKeypair.public_key + * The public key. Optional. + */ this.createKeypair = function(newKeypair) { return apiService.post('/api/nova/keypairs/', newKeypair) .error(function () { @@ -67,14 +74,14 @@ limitations under the License. // Availability Zones - /** - * @name hz.api.novaAPI.getAvailabilityZones - * @description - * Get a list of Availability Zones. - * - * The listing result is an object with property "items". Each item is - * an availability zone. - */ + /** + * @name horizon.openstack-service-api.nova.getAvailabilityZones + * @description + * Get a list of Availability Zones. + * + * The listing result is an object with property "items". Each item is + * an availability zone. + */ this.getAvailabilityZones = function() { return apiService.get('/api/nova/availzones/') .error(function () { @@ -86,7 +93,7 @@ limitations under the License. // Limits /** - * @name hz.api.novaAPI.getLimits + * @name horizon.openstack-service-api.nova.getLimits * @description * Returns current limits. * @@ -124,7 +131,7 @@ limitations under the License. // Servers /** - * @name hz.api.novaAPI.createServer + * @name horizon.openstack-service-api.nova.createServer * @description * Create a server using the parameters supplied in the * newServer. The required parameters: @@ -149,7 +156,7 @@ limitations under the License. }; /** - * @name hz.api.novaAPI.getServer + * @name horizon.openstack-service-api.nova.getServer * @description * Get a single server by ID * @param {string} id @@ -159,11 +166,11 @@ limitations under the License. return apiService.get('/api/nova/servers/' + id) .error(function () { toastService.add('error', gettext('Unable to retrieve the server.')); - }); + }); }; /** - * @name hz.api.novaAPI.getExtensions + * @name horizon.openstack-service-api.nova.getExtensions * @description * Returns a list of enabled extensions. * @@ -193,7 +200,7 @@ limitations under the License. }; /** - * @name hz.api.novaAPI.getFlavors + * @name horizon.openstack-service-api.nova.getFlavors * @description * Returns a list of flavors. * @@ -238,7 +245,7 @@ limitations under the License. }; /** - * @name hz.api.novaAPI.getFlavor + * @name horizon.openstack-service-api.nova.getFlavor * @description * Get a single flavor by ID. * @param {string} id @@ -252,11 +259,11 @@ limitations under the License. return apiService.get('/api/nova/flavors/' + id, config) .error(function () { toastService.add('error', gettext('Unable to retrieve the flavor.')); - }); + }); }; /** - * @name hz.api.novaAPI.getFlavorExtraSpecs + * @name horizon.openstack-service-api.nova.getFlavorExtraSpecs * @description * Get a single flavor's extra specs by ID. * @param {string} id @@ -266,38 +273,43 @@ limitations under the License. return apiService.get('/api/nova/flavors/' + id + '/extra-specs') .error(function () { toastService.add('error', gettext('Unable to retrieve the flavor extra specs.')); - }); + }); }; } - angular.module('hz.api') - .service('hz.api.nova', ['hz.api.common.service', 'horizon.framework.widgets.toast.service', NovaAPI]); + /** + * @ngdoc service + * @name horizon.openstack-service-api.novaExtensions + * @description + * Provides cached access to Nova Extensions with utilities to help + * with asynchronous data loading. The cache may be reset at any time + * by accessing the cache and calling removeAll. The next call to any + * function will retrieve fresh results. + * + * The enabled extensions do not change often, so using cached data will + * speed up results. Even on a local devstack in informal testing, + * this saved between 30 - 100 ms per request. + */ + angular + .module('horizon.openstack-service-api') + .factory('horizon.openstack-service-api.novaExtensions', NovaExtensionsAPI); - /** - * @ngdoc service - * @name hz.api.novaExtensions - * @description - * Provides cached access to Nova Extensions with utilities to help - * with asynchronous data loading. The cache may be reset at any time - * by accessing the cache and calling removeAll. The next call to any - * function will retrieve fresh results. - * - * The enabled extensions do not change often, so using cached data will - * speed up results. Even on a local devstack in informal testing, - * this saved between 30 - 100 ms per request. - */ - function NovaExtensions($cacheFactory, $q, novaAPI) { - var service = {}; - service.cache = $cacheFactory('hz.api.novaExtensions', {capacity: 1}); + NovaExtensionsAPI.$inject = ['$cacheFactory', + '$q', + 'horizon.openstack-service-api.nova']; - service.get = function () { - return novaAPI.getExtensions({cache: service.cache}) - .then(function (data) { - return data.data.items; - }); - }; + function NovaExtensionsAPI($cacheFactory, $q, novaAPI) { + var service = {}; + service.cache = $cacheFactory('horizon.openstack-service-api.novaExtensions', {capacity: 1}); - service.ifNameEnabled = function(desired) { + service.get = function () { + return novaAPI.getExtensions({cache: service.cache}) + .then(function (data) { + return data.data.items; + }); + }; + + service.ifNameEnabled = function(desired) { var deferred = $q.defer(); service.get().then(onDataLoaded, onDataFailure); @@ -307,14 +319,14 @@ limitations under the License. deferred.resolve(); } else { deferred.reject(interpolate( - gettext('Extension is not enabled: %(extension)s'), + gettext('Extension is not enabled: %(extension)s.'), {extension: desired}, true)); } } function onDataFailure() { - deferred.reject(gettext('Cannot get Nova extension list.')); + deferred.reject(gettext('Cannot get the Nova extension list.')); } return deferred.promise; @@ -324,7 +336,7 @@ limitations under the License. service.ifEnabled = service.ifNameEnabled; function enabled(resources, key, desired) { - if(resources) { + if (resources) { return resources.some(function (resource) { return resource[key] === desired; }); @@ -335,11 +347,4 @@ limitations under the License. return service; } - - angular.module('hz.api') - .factory('hz.api.novaExtensions', ['$cacheFactory', - '$q', - 'hz.api.nova', - NovaExtensions]); - }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.nova.spec.js b/openstack_dashboard/static/openstack-service-api/nova.service.spec.js similarity index 95% rename from horizon/static/horizon/js/angular/services/hz.api.nova.spec.js rename to openstack_dashboard/static/openstack-service-api/nova.service.spec.js index 698b2de633..a29a482836 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.nova.spec.js +++ b/openstack_dashboard/static/openstack-service-api/nova.service.spec.js @@ -22,13 +22,13 @@ var apiService = {}; var toastService = {}; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { window.apiTest.initServices($provide, apiService, toastService); })); - beforeEach(inject(['hz.api.nova', function(novaAPI) { + beforeEach(inject(['horizon.openstack-service-api.nova', function(novaAPI) { service = novaAPI; }])); @@ -247,18 +247,18 @@ describe("novaExtensions", function() { var factory, q, novaAPI; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { novaAPI = {getExtensions: function() {return {then: angular.noop};}}; q = {defer: function() { return {resolve: angular.noop}; }}; $provide.value('$cacheFactory', function() {return "cache";}); $provide.value('$q', q); - $provide.value('hz.api.nova', novaAPI); + $provide.value('horizon.openstack-service-api.nova', novaAPI); })); beforeEach(inject(function($injector) { - factory = $injector.get('hz.api.novaExtensions'); + factory = $injector.get('horizon.openstack-service-api.novaExtensions'); })); it("is defined", function() { @@ -304,7 +304,7 @@ deferred.reject.calls.reset(); func2(); - expect(deferred.reject).toHaveBeenCalledWith('Cannot get Nova extension list.'); + expect(deferred.reject).toHaveBeenCalledWith('Cannot get the Nova extension list.'); }); it("defines .ifEnabled", function() { diff --git a/horizon/static/horizon/js/angular/hz.api.module.js b/openstack_dashboard/static/openstack-service-api/openstack-service-api.module.js similarity index 89% rename from horizon/static/horizon/js/angular/hz.api.module.js rename to openstack_dashboard/static/openstack-service-api/openstack-service-api.module.js index c3b6d981f6..f57aeb6207 100644 --- a/horizon/static/horizon/js/angular/hz.api.module.js +++ b/openstack_dashboard/static/openstack-service-api/openstack-service-api.module.js @@ -13,8 +13,9 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -/*global angular*/ (function () { 'use strict'; - angular.module('hz.api', ['hz.api.common']); -}()); \ No newline at end of file + + angular + .module('horizon.openstack-service-api', []); +}()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.policy.js b/openstack_dashboard/static/openstack-service-api/policy.service.js similarity index 82% rename from horizon/static/horizon/js/angular/services/hz.api.policy.js rename to openstack_dashboard/static/openstack-service-api/policy.service.js index 2f219ff011..533583e625 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.policy.js +++ b/openstack_dashboard/static/openstack-service-api/policy.service.js @@ -14,16 +14,23 @@ limitations under the License. (function() { 'use strict'; + angular + .module('horizon.openstack-service-api') + .service('horizon.openstack-service-api.policy', PolicyService); + + PolicyService.$inject = ['horizon.framework.util.http.service', + 'horizon.framework.widgets.toast.service']; + /** * @ngdoc service - * @name hz.api.policyAPI + * @name horizon.openstack-service-api.policy * @description Provides a direct pass through to the policy engine in * Horizon. */ function PolicyService(apiService, toastService) { /** - * @name hz.api.policyAPI.check + * @name horizon.openstack-service-api.policy.check * @description * Check the passed in policy rule list to determine if the user has * permission to perform the actions specified by the rules. The service @@ -59,14 +66,11 @@ limitations under the License. * "allowed": false * } */ - this.check = function (policy_rules) { - return apiService.post('/api/policy/', policy_rules) + this.check = function (policyRules) { + return apiService.post('/api/policy/', policyRules) .error(function() { toastService.add('warning', gettext('Policy check failed.')); }); }; } - - angular.module('hz.api') - .service('hz.api.policy', ['hz.api.common.service', 'horizon.framework.widgets.toast.service', PolicyService]); }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.policy.spec.js b/openstack_dashboard/static/openstack-service-api/policy.service.spec.js similarity index 92% rename from horizon/static/horizon/js/angular/services/hz.api.policy.spec.js rename to openstack_dashboard/static/openstack-service-api/policy.service.spec.js index b262606431..dd1c43ca7e 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.policy.spec.js +++ b/openstack_dashboard/static/openstack-service-api/policy.service.spec.js @@ -22,13 +22,13 @@ var apiService = {}; var toastService = {}; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { window.apiTest.initServices($provide, apiService, toastService); })); - beforeEach(inject(['hz.api.policy', function(policyAPI) { + beforeEach(inject(['horizon.openstack-service-api.policy', function(policyAPI) { service = policyAPI; }])); diff --git a/horizon/static/horizon/js/angular/services/hz.api.security-group.js b/openstack_dashboard/static/openstack-service-api/security-group.service.js similarity index 82% rename from horizon/static/horizon/js/angular/services/hz.api.security-group.js rename to openstack_dashboard/static/openstack-service-api/security-group.service.js index fe9f8f2285..338acca678 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.security-group.js +++ b/openstack_dashboard/static/openstack-service-api/security-group.service.js @@ -16,15 +16,21 @@ limitations under the License. (function () { 'use strict'; + angular.module('horizon.openstack-service-api') + .service('horizon.openstack-service-api.security-group', SecurityGroupAPI); + + SecurityGroupAPI.$inject = ['horizon.framework.util.http.service', + 'horizon.framework.widgets.toast.service']; + /** * @ngdoc service - * @name hz.api.SecurityGroup + * @name horizon.openstack-service-api.security-group * @description Provides access to Security Groups */ - function SecurityGroup(apiService, toastService) { + function SecurityGroupAPI(apiService, toastService) { /** - * @name hz.api.SecurityGroup.list + * @name horizon.openstack-service-api.security-group.list * @description * Get a list of security groups. * @@ -62,14 +68,7 @@ limitations under the License. return apiService.get('/api/network/securitygroups/') .error(function () { toastService.add('error', gettext('Unable to retrieve the security groups.')); - }); + }); }; } - - // Register it with the API module so that anybody using the - // API module will have access to the Security Group APIs. - - angular.module('hz.api') - .service('hz.api.security-group', ['hz.api.common.service', 'horizon.framework.widgets.toast.service', SecurityGroup]); - }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.security-group.spec.js b/openstack_dashboard/static/openstack-service-api/security-group.service.spec.js similarity index 91% rename from horizon/static/horizon/js/angular/services/hz.api.security-group.spec.js rename to openstack_dashboard/static/openstack-service-api/security-group.service.spec.js index 585d27c24f..c58b917db1 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.security-group.spec.js +++ b/openstack_dashboard/static/openstack-service-api/security-group.service.spec.js @@ -22,13 +22,13 @@ var apiService = {}; var toastService = {}; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); beforeEach(module(function($provide) { window.apiTest.initServices($provide, apiService, toastService); })); - beforeEach(inject(['hz.api.security-group', function(securityGroup) { + beforeEach(inject(['horizon.openstack-service-api.security-group', function(securityGroup) { service = securityGroup; }])); diff --git a/horizon/static/horizon/js/angular/services/hz.api.config.js b/openstack_dashboard/static/openstack-service-api/settings.service.js similarity index 83% rename from horizon/static/horizon/js/angular/services/hz.api.config.js rename to openstack_dashboard/static/openstack-service-api/settings.service.js index 2db7a4c6c5..354a73c2bb 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.config.js +++ b/openstack_dashboard/static/openstack-service-api/settings.service.js @@ -17,9 +17,15 @@ (function () { 'use strict'; + angular + .module('horizon.openstack-service-api') + .factory('horizon.openstack-service-api.settings', settingsService); + + settingsService.$inject = ['$q', 'horizon.framework.util.http.service']; + /** * @ngdoc service - * @name hz.api.settingsService + * @name horizon.openstack-service-api.settings * @description * Provides utilities to the cached settings data. This helps * with asynchronous data loading. @@ -39,43 +45,43 @@ var service = {}; - /** - * @name hz.api.configAPI.getSettings + /** + * @name horizon.openstack-service-api.config.getSettings * @description * Gets all the allowed settings * * Returns an object with settings. */ - service.getSettings = function (suppressError) { + service.getSettings = function (suppressError) { - function onError() { - var message = gettext('Unable to retrieve settings.'); - if (!suppressError && horizon.alert) { - horizon.alert('error', message); - } + function onError() { + var message = gettext('Unable to retrieve settings.'); + if (!suppressError && horizon.alert) { + horizon.alert('error', message); + } - return message; - } + return message; + } - // The below ensures that errors are handled like other - // service errors (for better or worse), but when successful - // unwraps the success result data for direct consumption. - return apiService.get('/api/settings/', {cache: true}) - .error(onError) - .then(function (response) { - return response.data; - }); - }; + // The below ensures that errors are handled like other + // service errors (for better or worse), but when successful + // unwraps the success result data for direct consumption. + return apiService.get('/api/settings/', {cache: true}) + .error(onError) + .then(function (response) { + return response.data; + }); + }; /** - * @name hz.api.settingsService.getSetting + * @name horizon.openstack-service-api.settings.getSetting * @description * This retrieves a specific setting. * * If the setting isn't found, it will return undefined unless a default * is specified. In that case, the default will be returned. * - * @param {string} setting The path to the setting to get. + * @param {string} path The path to the setting to get. * * local_settings.py allows you to create settings such as: * @@ -91,7 +97,7 @@ * OPENSTACK_HYPERVISOR_FEATURES.can_set_mount_point * OPENSTACK_HYPERVISOR_FEATURES.can_set_password * - * @param {object=} defaultSetting If the requested setting does not exist, + * @param {Object} defaultSetting If the requested setting does not exist, * the defaultSetting will be returned. This is optional. * * @example @@ -105,9 +111,9 @@ ``` */ service.getSetting = function (path, defaultSetting) { - var deferred = $q.defer(), - pathElements = path.split("."), - settingAtRequestedPath; + var deferred = $q.defer(); + var pathElements = path.split("."); + var settingAtRequestedPath; function onSettingsLoaded(settings) { // This recursively traverses the object hierarchy until either all the @@ -137,7 +143,7 @@ }; /** - * @name hz.api.settingsService.ifEnabled + * @name horizon.openstack-service-api.settings.ifEnabled * @description * Checks if the desired setting is enabled. This returns a promise. * If the setting is enabled, the promise will be resolved. @@ -159,12 +165,12 @@ * OPENSTACK_HYPERVISOR_FEATURES.can_set_mount_point * OPENSTACK_HYPERVISOR_FEATURES.can_set_password * - * @param (object=} expected Used to determine if the setting is + * @param {Object} [expected=true] Used to determine if the setting is * enabled. The actual setting will be evaluated against the expected * value using angular.equals(). If they are equal, then it will be * considered enabled. This is optional and defaults to True. * - * @param {object=} defaultSetting If the requested setting does not exist, + * @param {Object} [defaultSetting=true] If the requested setting does not exist, * the defaultSetting will be used for evaluation. This is optional. If * not specified and the setting is not specified, then the setting will * not be considered to be enabled. @@ -253,8 +259,4 @@ return service; } - - angular.module('hz.api') - .factory('hz.api.settingsService', ['$q', 'hz.api.common.service', settingsService]); - }()); diff --git a/horizon/static/horizon/js/angular/services/hz.api.config.spec.js b/openstack_dashboard/static/openstack-service-api/settings.service.spec.js similarity index 97% rename from horizon/static/horizon/js/angular/services/hz.api.config.spec.js rename to openstack_dashboard/static/openstack-service-api/settings.service.spec.js index f446e86c05..416ec741ab 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.config.spec.js +++ b/openstack_dashboard/static/openstack-service-api/settings.service.spec.js @@ -32,13 +32,14 @@ return responseMockOpts.succeed ? [200, testData, {}] : [500, 'Fail', {}]; } - describe('settingsService', function () { + describe('horizon.openstack-service-api.settings', function () { var settingsService; - beforeEach(module('hz.api')); + beforeEach(module('horizon.openstack-service-api')); + beforeEach(module('horizon.framework.util.http')); beforeEach(inject(function (_$httpBackend_, $injector) { responseMockOpts.succeed = true; - settingsService = $injector.get('hz.api.settingsService'); + settingsService = $injector.get('horizon.openstack-service-api.settings'); $httpBackend = _$httpBackend_; $httpBackend.whenGET('/api/settings/').respond(responseMockReturn); $httpBackend.expectGET('/api/settings/'); diff --git a/openstack_dashboard/templates/horizon/_scripts.html b/openstack_dashboard/templates/horizon/_scripts.html index fe63942731..2d7f2e93cb 100644 --- a/openstack_dashboard/templates/horizon/_scripts.html +++ b/openstack_dashboard/templates/horizon/_scripts.html @@ -19,16 +19,15 @@ - - - - - - - - - - + + + + + + + + + @@ -39,6 +38,7 @@ +