diff --git a/neutron_lbaas_dashboard/api/rest/lbaasv2.py b/neutron_lbaas_dashboard/api/rest/lbaasv2.py index c47f756a..6181e4af 100644 --- a/neutron_lbaas_dashboard/api/rest/lbaasv2.py +++ b/neutron_lbaas_dashboard/api/rest/lbaasv2.py @@ -293,3 +293,20 @@ class Listener(generic.View): """ lb = neutronclient(request).show_listener(listener_id) return lb.get('listener') + + +@urls.register +class Pool(generic.View): + """API for retrieving a single pool. + + """ + url_regex = r'lbaas/pools/(?P[^/]+)/$' + + @rest_utils.ajax() + def get(self, request, pool_id): + """Get a specific pool. + + http://localhost/api/lbaas/pools/cc758c90-3d98-4ea1-af44-aab405c9c915 + """ + lb = neutronclient(request).show_lbaas_pool(pool_id) + return lb.get('pool') diff --git a/neutron_lbaas_dashboard/enabled/_1481_project_ng_loadbalancersv2_panel.py b/neutron_lbaas_dashboard/enabled/_1481_project_ng_loadbalancersv2_panel.py index 0cacdc5f..98cdd60e 100644 --- a/neutron_lbaas_dashboard/enabled/_1481_project_ng_loadbalancersv2_panel.py +++ b/neutron_lbaas_dashboard/enabled/_1481_project_ng_loadbalancersv2_panel.py @@ -55,7 +55,9 @@ ADD_JS_FILES = [ 'dashboard/project/lbaasv2/listeners/listeners.module.js', 'dashboard/project/lbaasv2/listeners/table.controller.js', 'dashboard/project/lbaasv2/listeners/detail.controller.js', - 'dashboard/project/lbaasv2/listeners/filters.js' + 'dashboard/project/lbaasv2/listeners/filters.js', + 'dashboard/project/lbaasv2/pools/pools.module.js', + 'dashboard/project/lbaasv2/pools/detail.controller.js' ] ADD_JS_SPEC_FILES = [ @@ -85,7 +87,9 @@ ADD_JS_SPEC_FILES = [ 'dashboard/project/lbaasv2/listeners/listeners.module.spec.js', 'dashboard/project/lbaasv2/listeners/table.controller.spec.js', 'dashboard/project/lbaasv2/listeners/detail.controller.spec.js', - 'dashboard/project/lbaasv2/listeners/filters.spec.js' + 'dashboard/project/lbassv2/listeners/filters.spec.js', + 'dashboard/project/lbaasv2/pools/pools.module.spec.js', + 'dashboard/project/lbaasv2/pools/detail.controller.spec.js' ] ADD_SCSS_FILES = [ diff --git a/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.js b/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.js index 90b3df6b..0f546d94 100644 --- a/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.js +++ b/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.js @@ -41,7 +41,8 @@ createLoadBalancer: createLoadBalancer, editLoadBalancer: editLoadBalancer, getListeners: getListeners, - getListener: getListener + getListener: getListener, + getPool: getPool }; return service; @@ -151,5 +152,20 @@ }); } + /** + * @name horizon.app.core.openstack-service-api.lbaasv2.getPool + * @description + * Get a single Pool by ID. + * @param {string} id + * Specifies the id of the pool to request. + */ + + function getPool(id) { + return apiService.get('/api/lbaas/pools/' + id) + .error(function () { + toastService.add('error', gettext('Unable to retrieve pool.')); + }); + } + } }()); diff --git a/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.spec.js b/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.spec.js index b03aa8f0..9b3cee5f 100644 --- a/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.spec.js +++ b/neutron_lbaas_dashboard/static/app/core/openstack-service-api/lbaasv2.service.spec.js @@ -81,6 +81,15 @@ '1234' ] }, + { + "func": "getPool", + "method": "get", + "path": "/api/lbaas/pools/1234", + "error": "Unable to retrieve pool.", + "testInput": [ + '1234' + ] + }, { "func": "createLoadBalancer", "method": "post", diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js index 81f7d952..7112c624 100644 --- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js @@ -27,7 +27,8 @@ .module('horizon.dashboard.project.lbaasv2', [ 'ngRoute', 'horizon.dashboard.project.lbaasv2.loadbalancers', - 'horizon.dashboard.project.lbaasv2.listeners' + 'horizon.dashboard.project.lbaasv2.listeners', + 'horizon.dashboard.project.lbaasv2.pools' ]) .config(config) .constant('horizon.dashboard.project.lbaasv2.patterns', { @@ -64,6 +65,9 @@ }) .when(href + 'listeners/detail/:listenerId', { templateUrl: basePath + 'listeners/detail.html' + }) + .when(href + 'pools/detail/:poolId', { + templateUrl: basePath + 'pools/detail.html' }); } diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js index 2a297d97..8a6b7ae7 100644 --- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js @@ -114,10 +114,16 @@ { templateUrl: basePath + 'listeners/detail.html' } + ], + [ + href + 'pools/detail/:poolId', + { + templateUrl: basePath + 'pools/detail.html' + } ] ]; - expect($routeProvider.when.calls.count()).toBe(3); + expect($routeProvider.when.calls.count()).toBe(4); angular.forEach($routeProvider.when.calls.all(), function(call, i) { expect(call.args).toEqual(routes[i]); }); diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html index cb1ee91b..b0a60537 100644 --- a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html @@ -36,10 +36,10 @@
Default Pool ID
-
+
{$ ::ctrl.listener.default_pool_id $}
-
+
{$ 'None' | translate $}
diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.controller.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.controller.js new file mode 100644 index 00000000..cbcfe75b --- /dev/null +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.controller.js @@ -0,0 +1,94 @@ +/* + * Copyright 2016 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.dashboard.project.lbaasv2.pools') + .controller('PoolDetailController', PoolDetailController); + + PoolDetailController.$inject = [ + 'horizon.app.core.openstack-service-api.lbaasv2', + '$routeParams', + 'horizon.framework.util.i18n.gettext' + ]; + + /** + * @ngdoc controller + * @name PoolDetailController + * + * @description + * Controller for the LBaaS v2 pool detail page. + * + * @param api The LBaaS v2 API service. + * @param $routeParams The angular $routeParams service. + * @param gettext The horizon gettext function for translation. + * @returns undefined + */ + + function PoolDetailController(api, $routeParams, gettext) { + var ctrl = this; + ctrl.pool = {}; + ctrl.listener = {}; + ctrl.loadbalancer = {}; + ctrl.lb_algorithm_mappings = { + 'ROUND_ROBIN': gettext('Round Robin'), + 'LEAST_CONNECTIONS': gettext('Least Connections'), + 'SOURCE_IP': gettext('Source IP') + }; + + var poolId = $routeParams.poolId; + + init(); + + //////////////////////////////// + + function init() { + api.getPool(poolId).success(poolSuccess); + } + + function poolSuccess(response) { + ctrl.pool = response; + if (ctrl.pool.hasOwnProperty('listeners') && + ctrl.pool.listeners.length > 0) { + getListenerDetails(ctrl.pool.listeners[0].id); + } + } + + function getListenerDetails(listenerId) { + api.getListener(listenerId).success(listenerSuccess); + } + + function listenerSuccess(response) { + ctrl.listener = response; + + if (ctrl.listener.hasOwnProperty('loadbalancers') && + ctrl.listener.loadbalancers.length > 0) { + getLoadBalancerDetails(ctrl.listener.loadbalancers[0].id); + } + } + + function getLoadBalancerDetails(loadbalancerId) { + api.getLoadBalancer(loadbalancerId).success(loadbalancerSuccess); + } + + function loadbalancerSuccess(response) { + ctrl.loadbalancer = response; + } + + } + +})(); diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.controller.spec.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.controller.spec.js new file mode 100644 index 00000000..3491dddc --- /dev/null +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.controller.spec.js @@ -0,0 +1,101 @@ +/* + * Copyright 2016 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'; + + describe('LBaaS v2 Pool Detail Controller', function() { + var controller, lbaasv2API, gettextService, pool, listener, loadbalancer; + + function fakePoolAPI() { + return { + success: function(callback) { + callback(pool); + } + }; + } + + function fakeListenerAPI() { + return { + success: function(callback) { + callback(listener); + } + }; + } + + function fakeLoadBalancerAPI() { + return { + success: function(callback) { + callback(loadbalancer); + } + }; + } + + /////////////////////// + + beforeEach(module('horizon.framework.util.http')); + beforeEach(module('horizon.framework.widgets.toast')); + beforeEach(module('horizon.framework.conf')); + beforeEach(module('horizon.app.core.openstack-service-api')); + beforeEach(module('horizon.dashboard.project.lbaasv2')); + beforeEach(module('horizon.framework.util.i18n')); + + beforeEach(inject(function($injector) { + gettextService = $injector.get('horizon.framework.util.i18n.gettext'); + lbaasv2API = $injector.get('horizon.app.core.openstack-service-api.lbaasv2'); + controller = $injector.get('$controller'); + spyOn(lbaasv2API, 'getPool').and.callFake(fakePoolAPI); + spyOn(lbaasv2API, 'getListener').and.callFake(fakeListenerAPI); + spyOn(lbaasv2API, 'getLoadBalancer').and.callFake(fakeLoadBalancerAPI); + })); + + function createController() { + return controller('PoolDetailController', { + api: lbaasv2API, + $routeParams: { poolId: 'poolId' }, + gettext: gettextService + }); + } + + it('should invoke lbaasv2 apis', function() { + pool = { id: 'poolId', listeners: [{id: 'listenerId'}] }; + listener = { id: 'listenerId', loadbalancers: [{id: 'loadbalancerId'}] }; + loadbalancer = { id: 'loadbalancerId' }; + createController(); + expect(lbaasv2API.getPool).toHaveBeenCalledWith('poolId'); + expect(lbaasv2API.getListener).toHaveBeenCalledWith('listenerId'); + expect(lbaasv2API.getLoadBalancer).toHaveBeenCalledWith('loadbalancerId'); + }); + + it('should not invoke the getListener or getLoadBalancer lbaasv2 api', function() { + pool = { id: 'poolId', listeners: [] }; + createController(); + expect(lbaasv2API.getPool).toHaveBeenCalledWith('poolId'); + expect(lbaasv2API.getListener).not.toHaveBeenCalled(); + expect(lbaasv2API.getLoadBalancer).not.toHaveBeenCalled(); + }); + + it('should not invoke getLoadBalancer lbaasv2 api', function() { + pool = { id: 'poolId', listeners: [{id: 'listenerId'}] }; + listener = { id: 'listenerId', loadbalancers: [] }; + createController(); + expect(lbaasv2API.getPool).toHaveBeenCalledWith('poolId'); + expect(lbaasv2API.getListener).toHaveBeenCalledWith('listenerId'); + expect(lbaasv2API.getLoadBalancer).not.toHaveBeenCalled(); + }); + + }); + +})(); diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.html b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.html new file mode 100644 index 00000000..772a390a --- /dev/null +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/detail.html @@ -0,0 +1,65 @@ +
+ +
+ + +
+
+
Pool ID
+
{$ ::ctrl.pool.id $}
+
+
+
Admin State Up
+
{$ ::ctrl.pool.admin_state_up | yesno $}
+
+
+
Tenant ID
+
{$ ::ctrl.pool.tenant_id $}
+
+
+
Protocol
+
{$ ::ctrl.pool.protocol $}
+
+
+
Load Balancer Algorithm
+
{$ ctrl.pool.lb_algorithm | decode:ctrl.lb_algorithm_mappings $}
+
+
+
Session Persistence
+
+
+ {$ ::ctrl.pool.session_persistence $} +
+
+ {$ 'None' | translate $} +
+
+
+
+
Health Monitor ID
+
+ +
+ {$ 'None' | translate $} +
+
+
+
+
+ + + + +
+
+
\ No newline at end of file diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/pools.module.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/pools.module.js new file mode 100644 index 00000000..ee56bb41 --- /dev/null +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/pools.module.js @@ -0,0 +1,31 @@ +/* + * Copyright 2016 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 overview + * @ngname horizon.dashboard.project.lbaasv2.pools + * + * @description + * Provides the services and widgets required to support and display the project pools + * for the load balancers v2 panel. + */ + + angular + .module('horizon.dashboard.project.lbaasv2.pools', []); + +})(); diff --git a/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/pools.module.spec.js b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/pools.module.spec.js new file mode 100644 index 00000000..58497c48 --- /dev/null +++ b/neutron_lbaas_dashboard/static/dashboard/project/lbaasv2/pools/pools.module.spec.js @@ -0,0 +1,25 @@ +/* + * Copyright 2016 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'; + + describe('LBaaS v2 Pools Module', function() { + it('should exist', function() { + expect(angular.module('horizon.dashboard.project.lbaasv2.pools')).toBeDefined(); + }); + }); + +})();