ironic-ui/ironic_ui/static/dashboard/admin/ironic/enroll-node/enroll-node.controller.js
Peter Piela ed87e4f117 Improvements to enroll-node service
- Rename the modal function to enrollNode which better desribes its role
- The enrollNode function returns a promise that when successfully
resolved will contain the newly enrolled node. This change can be
used to support more efficient UI updates.

Change-Id: Id8f46cf85b6a1adb65c87d3c10729aea123241e7
2017-01-27 12:30:00 -05:00

84 lines
2.7 KiB
JavaScript

/*
* Copyright 2016 Cray Inc.
*
* 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';
/**
* Controller used to enroll a node in the Ironic database
*/
angular
.module('horizon.dashboard.admin.ironic')
.controller('EnrollNodeController', EnrollNodeController);
EnrollNodeController.$inject = [
'$rootScope',
'$controller',
'$uibModalInstance',
'horizon.app.core.openstack-service-api.ironic',
'horizon.dashboard.admin.ironic.events',
'$log'
];
function EnrollNodeController($rootScope,
$controller,
$uibModalInstance,
ironic,
ironicEvents,
$log) {
var ctrl = this;
$controller('BaseNodeController',
{ctrl: ctrl,
$uibModalInstance: $uibModalInstance});
ctrl.modalTitle = gettext("Enroll Node");
ctrl.submitButtonTitle = ctrl.modalTitle;
init();
function init() {
ctrl._loadDrivers();
ctrl._getImages();
}
ctrl.submit = function() {
$log.debug(">> EnrollNodeController.submit()");
angular.forEach(ctrl.driverProperties, function(property, name) {
$log.debug(name +
", required = " + property.isRequired() +
", active = " + property.isActive() +
", input-value = " + property.getInputValue() +
", default-value = " + property.getDefaultValue());
if (property.isActive() &&
property.getInputValue() &&
property.getInputValue() !== property.getDefaultValue()) {
$log.debug("Setting driver property " + name + " to " +
property.inputValue);
ctrl.node.driver_info[name] = property.inputValue;
}
});
ironic.createNode(ctrl.node).then(
function(response) {
$log.info("create node response = " + JSON.stringify(response));
$rootScope.$emit(ironicEvents.ENROLL_NODE_SUCCESS);
$uibModalInstance.close(response.data);
});
$log.debug("<< EnrollNodeController.submit()");
};
}
})();