Added Regions 'drawer' to show hosts in region

The list of hosts is not available in the region's
drawer
This commit is contained in:
Luis Daniel Castellanos 2016-09-01 10:41:27 -05:00
parent e22ac14bb1
commit 58f4fab180
11 changed files with 169 additions and 47 deletions

View File

@ -1,6 +1,9 @@
CHANGES
=======
* Added regions resource table to the Inventory panel
* Directory for i18n
* Reordered panels
* Add JavaScript unit tests code base
* Move the panel dashboard outside of the project section
* Removed the docstrings from the start of file

View File

@ -27,14 +27,18 @@ def get_auth_params_from_request(request):
request.user.username,
request.user.token.id,
request.user.tenant_id,
base.url_for(request, 'craton')
base.url_for(request, 'fleetmanagement'),
request.session
)
@memoized_with_request(get_auth_params_from_request)
def cratonclient(request_auth_params):
username, token, project_id, url = request_auth_params
session = craton_session.Session(username=username, token=token)
username, token, project_id, url, session = request_auth_params
session = craton_session.Session(session=session,
username=username,
token=token)
c = craton_client.Client(session=session, url=url)
return c
@ -124,8 +128,14 @@ def host_delete(request, **kwargs):
pass
@memoized
def host_list(request, **kwargs):
pass
project_id = getattr(kwargs, 'project_id', None)
if project_id:
delattr(kwargs, 'project_id')
return cratonclient(request).hosts.list(project_id=project_id,
**kwargs)
return []
def host_show(request, **kwargs):

View File

@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from craton_dashboard.api.rest import craton # noqa
from craton_dashboard.api.rest import craton # noqa

View File

@ -38,7 +38,9 @@
function cratonAPI($q, apiService, toastService) {
var service = {
getRegions: getRegions
getRegions: getRegions,
getHosts: getHosts,
getRegion: getRegion
};
/**
@ -54,6 +56,33 @@
});
}
/**
* @name getRegion
* @param identifier Region Id
* @returns {Object} api call result
*/
function getRegion(identifier) {
return apiService.get('api/craton/regions/' + identifier + '/')
.error(function error() {
toastService.add('error', gettext("Unable to get the Craton Region"));
});
}
/**
* @name getHosts
* @description Gets a list of hosts
* @param params {Object} query filter params
* @returns {Object} an object with 'items'
*/
function getHosts(params) {
var config = params ? {'params': params} : {};
return apiService.get('api/craton/hosts', config)
.error(function error() {
toastService.add('error', gettext('Unable to retrieve the hosts'));
});
}
return service;
}

View File

@ -46,6 +46,20 @@
method: "get",
path: "api/craton/regions",
error: "Unable to get the Craton regions listing"
},
{
func: "getRegion",
method: "get",
path: "api/craton/regions/spam/",
error: "Unable to get the Craton Region",
testInput: ["spam"]
},
{
func: "getHosts",
method: "get",
path: "api/craton/hosts",
error: "Unable to retrieve the hosts",
data: {}
}
];

View File

@ -1,5 +1,10 @@
<div class="row">
<div class="row" ng-controller="horizon.dashboard.project.fleet_management.regions.RegionDrawerController as ctrl">
<div class="col-sm-12">
<!--TODO(lcastell) figure out how to add hosts list here-->
<div class="col-sm-1" ng-if="ctrl.region.hosts.length > 0" ng-repeat="host in ctrl.region.hosts track by host.id">
<a href="#" class="btn btn-sm btn-default">{$ host.name $}</a>
</div>
<p ng-if="ctrl.region.hosts.length == 0">
<translate>No items to display.</translate>
</p>
</div>
</div>

View File

@ -0,0 +1,47 @@
/**
* Copyright 2016 Intel Corporation
*
* 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.fleet_management.regions')
.controller('horizon.dashboard.project.fleet_management.regions.RegionDrawerController',
RegionDrawerController);
RegionDrawerController.$inject = [
'horizon.dashboard.project.fleet_management.regions.resourceType',
'horizon.framework.conf.resource-type-registry.service',
'horizon.app.core.openstack-service-api.craton',
'$scope'
];
function RegionDrawerController(regionResourceType, registry, cratonApi, $scope) {
var ctrl = this;
ctrl.region = $scope.item || {};
ctrl.region.hosts = [];
ctrl.resourceType = registry.getResourceType(regionResourceType);
getHosts();
function getHosts() {
cratonApi.getHosts({region_id: ctrl.region.id }).then(function resolve(data) {
ctrl.region.hosts = data.data.items;
});
}
}
})();

View File

@ -0,0 +1,50 @@
/**
* Copyright 2016 Intel Corporation
*
* 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('horizon.dashboard.project.fleet_management.regions RegionsDrawerController',
function () {
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module('horizon.framework'));
beforeEach(module('horizon.dashboard.project'));
beforeEach(module('horizon.dashboard.project.fleet_management'));
var /*$q, $rootScope,*/ scope, cratonAPI, controller;
beforeEach(inject( function ($injector, _$q_, _$rootScope_) {
controller = $injector.get('$controller');
// $q = _$q_;
// $rootScope = _$rootScope_;
scope = _$rootScope_.$new();
cratonAPI = $injector.get('horizon.app.core.openstack-service-api.craton');
}));
function createController() {
return controller(
'horizon.dashboard.project.fleet_management.regions.RegionDrawerController',
{$scope: scope});
}
it('should call api getHosts when created', function test() {
spyOn(cratonAPI, 'getHosts').and.callThrough();
createController();
expect(cratonAPI.getHosts).toHaveBeenCalled();
});
});
})();

View File

@ -1,15 +0,0 @@
/**
* Copyright 2016 Intel Corporation
*
* 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.
*/

View File

@ -1,22 +0,0 @@
/**
* Copyright 2016 Intel Corporation
*
* 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';
//TODO: ADD TESTS!!
})();

View File

@ -29,7 +29,8 @@
angular
.module('horizon.dashboard.project.fleet_management.regions', ['ngRoute'])
.constant('horizon.dashboard.project.fleet_management.resourceType', 'OS::Craton::Region')
.constant('horizon.dashboard.project.fleet_management.regions.resourceType',
'OS::Craton::Region')
.run(run)
.config(config);
@ -37,7 +38,7 @@
'horizon.framework.conf.resource-type-registry.service',
'horizon.app.core.openstack-service-api.craton',
'horizon.dashboard.project.fleet_management.basePath',
'horizon.dashboard.project.fleet_management.resourceType'
'horizon.dashboard.project.fleet_management.regions.resourceType'
];
function run(registry, craton, basePath, cratonResourceType) {