Merge "Added support for editing Ironic nodes"
This commit is contained in:
commit
cd743584fa
@ -158,6 +158,19 @@ def node_delete(request, node_id):
|
||||
return ironicclient(request).node.delete(node_id)
|
||||
|
||||
|
||||
def node_update(request, node_id, patch):
|
||||
"""Update a specified node.
|
||||
|
||||
:param request: HTTP request.
|
||||
:param node_id: The UUID of the node.
|
||||
:param patch: Sequence of update operations
|
||||
:return: node.
|
||||
|
||||
http://docs.openstack.org/developer/python-ironicclient/api/ironicclient.v1.node.html#ironicclient.v1.node.NodeManager.update
|
||||
"""
|
||||
ironicclient(request).node.update(node_id, patch)
|
||||
|
||||
|
||||
def driver_list(request):
|
||||
"""Retrieve a list of drivers.
|
||||
|
||||
|
@ -69,11 +69,21 @@ class Node(generic.View):
|
||||
"""Get information on a specific node.
|
||||
|
||||
:param request: HTTP request.
|
||||
:param node_id: Node name or uuid.
|
||||
:param node_id: Node id.
|
||||
:return: node.
|
||||
"""
|
||||
return ironic.node_get(request, node_id).to_dict()
|
||||
|
||||
@rest_utils.ajax(data_required=True)
|
||||
def patch(self, request, node_id):
|
||||
"""Update an Ironic node
|
||||
|
||||
:param request: HTTP request
|
||||
:param node_uuid: Node uuid.
|
||||
"""
|
||||
patch = request.DATA.get('patch')
|
||||
return ironic.node_update(request, node_id, patch)
|
||||
|
||||
|
||||
@urls.register
|
||||
class Ports(generic.View):
|
||||
|
@ -0,0 +1,303 @@
|
||||
/*
|
||||
* 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 support operations on an Ironic node
|
||||
*/
|
||||
angular
|
||||
.module('horizon.dashboard.admin.ironic')
|
||||
.controller('BaseNodeController', BaseNodeController);
|
||||
|
||||
BaseNodeController.$inject = [
|
||||
'$modalInstance',
|
||||
'horizon.app.core.openstack-service-api.ironic',
|
||||
'horizon.app.core.openstack-service-api.glance',
|
||||
'horizon.dashboard.admin.ironic.base-node.service',
|
||||
'horizon.dashboard.admin.ironic.validHostNamePattern',
|
||||
'$log',
|
||||
'ctrl'
|
||||
];
|
||||
|
||||
function BaseNodeController($modalInstance,
|
||||
ironic,
|
||||
glance,
|
||||
baseNodeService,
|
||||
validHostNamePattern,
|
||||
$log,
|
||||
ctrl) {
|
||||
ctrl.validHostNameRegex = new RegExp(validHostNamePattern);
|
||||
ctrl.drivers = null;
|
||||
ctrl.images = null;
|
||||
ctrl.loadingDriverProperties = false;
|
||||
// Object containing the set of properties associated with the currently
|
||||
// selected driver
|
||||
ctrl.driverProperties = null;
|
||||
ctrl.driverPropertyGroups = null;
|
||||
|
||||
ctrl.modalTitle = gettext("Node");
|
||||
ctrl.submitButtonTitle = gettext("Submit");
|
||||
ctrl.showInstanceInfo = false;
|
||||
|
||||
// Node object suitable for Ironic api
|
||||
ctrl.node = {
|
||||
name: null,
|
||||
driver: null,
|
||||
driver_info: {},
|
||||
properties: {},
|
||||
extra: {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the list of currently active Ironic drivers
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl._loadDrivers = function() {
|
||||
return ironic.getDrivers().then(function(response) {
|
||||
ctrl.drivers = response.data.items;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the list of images from Glance
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl._getImages = function() {
|
||||
glance.getImages().then(function(response) {
|
||||
ctrl.images = response.data.items;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether a group contains required properties
|
||||
*
|
||||
* @param {DriverProperty[]} group - Property group
|
||||
* @return {boolean} Return true if the group contains required
|
||||
* properties, false otherwise
|
||||
*/
|
||||
function driverPropertyGroupHasRequired(group) {
|
||||
var hasRequired = false;
|
||||
for (var i = 0; i < group.length; i++) {
|
||||
if (group[i].required) {
|
||||
hasRequired = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hasRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convert array of driver property groups to a string
|
||||
*
|
||||
* @param {array[]} groups - Array for driver property groups
|
||||
* @return {string} Output string
|
||||
*/
|
||||
function driverPropertyGroupsToString(groups) {
|
||||
var output = [];
|
||||
angular.forEach(groups, function(group) {
|
||||
var groupStr = [];
|
||||
angular.forEach(group, function(property) {
|
||||
groupStr.push(property.name);
|
||||
});
|
||||
groupStr = groupStr.join(", ");
|
||||
output.push(['[', groupStr, ']'].join(""));
|
||||
});
|
||||
output = output.join(", ");
|
||||
return ['[', output, ']'].join("");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Comaprison function used to sort driver property groups
|
||||
*
|
||||
* @param {DriverProperty[]} group1 - First group
|
||||
* @param {DriverProperty[]} group2 - Second group
|
||||
* @return {integer} Return:
|
||||
* < 0 if group1 should precede group2 in an ascending ordering
|
||||
* > 0 if group2 should precede group1
|
||||
* 0 if group1 and group2 are considered equal from ordering perpsective
|
||||
*/
|
||||
function compareDriverPropertyGroups(group1, group2) {
|
||||
var group1HasRequired = driverPropertyGroupHasRequired(group1);
|
||||
var group2HasRequired = driverPropertyGroupHasRequired(group2);
|
||||
|
||||
if (group1HasRequired === group2HasRequired) {
|
||||
if (group1.length === group2.length) {
|
||||
return group1[0].name.localeCompare(group2[0].name);
|
||||
} else {
|
||||
return group1.length - group2.length;
|
||||
}
|
||||
} else {
|
||||
return group1HasRequired ? -1 : 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Order driver properties in the form using the following
|
||||
* rules:
|
||||
*
|
||||
* (1) Properties that are related to one another should occupy adjacent
|
||||
* locations in the form
|
||||
*
|
||||
* (2) Required properties with no dependents should be located at the
|
||||
* top of the form
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl._sortDriverProperties = function() {
|
||||
// Build dependency graph between driver properties
|
||||
var graph = new baseNodeService.Graph();
|
||||
|
||||
// Create vertices
|
||||
angular.forEach(ctrl.driverProperties, function(property, name) {
|
||||
graph.addVertex(name, property);
|
||||
});
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
// Create edges
|
||||
angular.forEach(ctrl.driverProperties,
|
||||
function(property, name) {
|
||||
var activators = property.getActivators();
|
||||
if (activators) {
|
||||
angular.forEach(activators,
|
||||
function(unused, activatorName) {
|
||||
graph.addEdge(name, activatorName);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
// Perform depth-first-search to find groups of related properties
|
||||
var groups = [];
|
||||
graph.dfs(
|
||||
function(vertexList, components) {
|
||||
// Sort properties so that those with the largest number of
|
||||
// immediate dependents are the top of the list
|
||||
vertexList.sort(function(vertex1, vertex2) {
|
||||
return vertex2.adjacents.length - vertex1.adjacents.length;
|
||||
});
|
||||
|
||||
// Build component and add to list
|
||||
var component = new Array(vertexList.length);
|
||||
angular.forEach(vertexList, function(vertex, index) {
|
||||
component[index] = vertex.data;
|
||||
});
|
||||
components.push(component);
|
||||
},
|
||||
groups);
|
||||
groups.sort(compareDriverPropertyGroups);
|
||||
|
||||
$log.debug("Found the following property groups: " +
|
||||
driverPropertyGroupsToString(groups));
|
||||
return groups;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the properties associated with a specified driver
|
||||
*
|
||||
* @param {string} driverName - Name of driver
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.loadDriverProperties = function(driverName) {
|
||||
ctrl.node.driver = driverName;
|
||||
ctrl.node.driver_info = {};
|
||||
|
||||
ctrl.loadingDriverProperties = true;
|
||||
ctrl.driverProperties = null;
|
||||
ctrl.driverPropertyGroups = null;
|
||||
|
||||
return ironic.getDriverProperties(driverName).then(function(response) {
|
||||
ctrl.driverProperties = {};
|
||||
angular.forEach(response.data, function(desc, property) {
|
||||
ctrl.driverProperties[property] =
|
||||
new baseNodeService.DriverProperty(property,
|
||||
desc,
|
||||
ctrl.driverProperties);
|
||||
});
|
||||
ctrl.driverPropertyGroups = ctrl._sortDriverProperties();
|
||||
ctrl.loadingDriverProperties = false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Cancel the current node operation
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.cancel = function() {
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
/**
|
||||
* @desription Delete a node property
|
||||
*
|
||||
* @param {string} propertyName - Name of the property
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.deleteProperty = function(propertyName) {
|
||||
delete ctrl.node.properties[propertyName];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether the specified node property already exists
|
||||
*
|
||||
* @param {string} propertyName - Name of the property
|
||||
* @return {boolean} True if the property already exists,
|
||||
* otherwise false
|
||||
*/
|
||||
ctrl.checkPropertyUnique = function(propertyName) {
|
||||
return !(propertyName in ctrl.node.properties);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Delete a node metadata property
|
||||
*
|
||||
* @param {string} propertyName - Name of the property
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.deleteExtra = function(propertyName) {
|
||||
delete ctrl.node.extra[propertyName];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether the specified node metadata property
|
||||
* already exists
|
||||
*
|
||||
* @param {string} propertyName - Name of the metadata property
|
||||
* @return {boolean} True if the property already exists,
|
||||
* otherwise false
|
||||
*/
|
||||
ctrl.checkExtraUnique = function(propertyName) {
|
||||
return !(propertyName in ctrl.node.extra);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether a specified driver property is
|
||||
* currently active
|
||||
*
|
||||
* @param {string} property - Driver property
|
||||
* @return {boolean} True if the property is active, false otherwise
|
||||
*/
|
||||
ctrl.isDriverPropertyActive = function(property) {
|
||||
return property.isActive();
|
||||
};
|
||||
}
|
||||
})();
|
@ -6,7 +6,7 @@
|
||||
aria-label="Close">
|
||||
<span aria-hidden="true" class="fa fa-times"></span>
|
||||
</button>
|
||||
<h3 class="modal-title" translate>Enroll Node</h3>
|
||||
<h3 class="modal-title" translate>{$ ctrl.modalTitle $}</h3>
|
||||
</div>
|
||||
<!-- begin general node info modal -->
|
||||
<div class="modal-body">
|
||||
@ -28,9 +28,9 @@
|
||||
translate>Driver Details</a></li>
|
||||
</ul>
|
||||
|
||||
<!--enroll node form-->
|
||||
<form id="enrollNodeForm"
|
||||
name="enrollNodeForm">
|
||||
<!--base node form-->
|
||||
<form id="baseNodeForm"
|
||||
name="baseNodeForm">
|
||||
|
||||
<!--tabbed content-->
|
||||
<div class="tab-content">
|
||||
@ -38,8 +38,8 @@
|
||||
<div class="tab-pane active" id="nodeInfo">
|
||||
<!--node name-->
|
||||
<div class="form-group"
|
||||
ng-class="{'has-error': enrollNodeForm.name.$invalid &&
|
||||
enrollNodeForm.name.$dirty}">
|
||||
ng-class="{'has-error': baseNodeForm.name.$invalid &&
|
||||
baseNodeForm.name.$dirty}">
|
||||
<label for="name"
|
||||
class="control-label"
|
||||
translate>Node Name</label>
|
||||
@ -69,9 +69,9 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<!--properties-->
|
||||
<form id="AddPropertyForm"
|
||||
name="AddPropertyForm">
|
||||
<!--properties add-property-->
|
||||
<form id="addPropertyForm"
|
||||
name="addPropertyForm">
|
||||
<div class="form-group">
|
||||
<label for="properties"
|
||||
class="control-label"
|
||||
@ -90,7 +90,7 @@
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary"
|
||||
type="button"
|
||||
ng-disabled="!propertyName || AddPropertyForm.$invalid"
|
||||
ng-disabled="!propertyName || addPropertyForm.$invalid"
|
||||
ng-click="ctrl.node.properties[propertyName] = null;
|
||||
propertyName = null">
|
||||
<span class="fa fa-plus"> </span>
|
||||
@ -99,9 +99,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!--properties list-->
|
||||
<form id="PropertiesForm"
|
||||
name="PropertiesForm">
|
||||
<!--properties property-list-->
|
||||
<form id="propertiesForm"
|
||||
name="propertiesForm">
|
||||
<div class="form-group">
|
||||
<div class="input-group input-group-sm"
|
||||
ng-repeat="(propertyName, propertyValue) in ctrl.node.properties">
|
||||
@ -123,9 +123,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!--extras-->
|
||||
<form id="AddExtraForm"
|
||||
name="AddExtraForm">
|
||||
<!--extras add-property-->
|
||||
<form id="addExtraForm"
|
||||
name="addExtraForm">
|
||||
<div class="form-group">
|
||||
<label for="extras"
|
||||
class="control-label"
|
||||
@ -144,7 +144,7 @@
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary"
|
||||
type="button"
|
||||
ng-disabled="!extraName || AddExtraForm.$invalid"
|
||||
ng-disabled="!extraName || addExtraForm.$invalid"
|
||||
ng-click="ctrl.node.extra[extraName] = null;
|
||||
extraName = null">
|
||||
<span class="fa fa-plus"> </span>
|
||||
@ -153,9 +153,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!--extras list-->
|
||||
<form id="ExtraForm"
|
||||
name="ExtraForm">
|
||||
<!--extras property-list-->
|
||||
<form id="extraForm"
|
||||
name="extraForm">
|
||||
<div class="form-group">
|
||||
<div class="input-group input-group-sm"
|
||||
ng-repeat="(propertyName, propertyValue) in ctrl.node.extra">
|
||||
@ -177,6 +177,63 @@
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!--instance-info add-property-->
|
||||
<form ng-if="ctrl.showInstanceInfo"
|
||||
id="addInstancePropertyForm"
|
||||
name="addInstancePropertyForm">
|
||||
<div class="form-group">
|
||||
<label for="instanceProperty"
|
||||
class="control-label"
|
||||
translate>Instance Info</label>
|
||||
<div class="input-group input-group-sm">
|
||||
<span class="input-group-addon"
|
||||
style="width:25%;text-align:right"
|
||||
translate>
|
||||
Add New Instance Property:</span>
|
||||
<input class="form-control"
|
||||
id="instanceProperty"
|
||||
type="text"
|
||||
ng-model="instancePropertyName"
|
||||
validate-unique="ctrl.checkInstancePropertyUnique"
|
||||
placeholder="{$ 'Instance Property Name' | translate $}"/>
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-primary"
|
||||
type="button"
|
||||
ng-disabled="!instancePropertyName ||
|
||||
addInstancePropertyForm.$invalid"
|
||||
ng-click="ctrl.node.instance_info[instancePropertyName] = null;
|
||||
instancePropertyName = null">
|
||||
<span class="fa fa-plus"> </span>
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<!--instance-info property-list-->
|
||||
<form ng-if="ctrl.showInstanceInfo"
|
||||
id="instanceInfoForm"
|
||||
name="instanceInfoForm">
|
||||
<div class="form-group">
|
||||
<div class="input-group input-group-sm"
|
||||
ng-repeat="(propertyName, propertyValue) in ctrl.node.instance_info">
|
||||
<span class="input-group-addon"
|
||||
style="width:25%;text-align:right">
|
||||
{$ propertyName $}
|
||||
</span>
|
||||
<input class="form-control"
|
||||
type="text"
|
||||
name="{$ propertyName $}"
|
||||
ng-model="ctrl.node.instance_info[propertyName]"
|
||||
ng-required="true"/>
|
||||
<div class="input-group-btn">
|
||||
<a class="btn btn-default"
|
||||
ng-click="ctrl.deleteInstanceProperty(propertyName)">
|
||||
<span class="fa fa-minus"> </span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<!--end node info tab-->
|
||||
|
||||
@ -192,8 +249,8 @@
|
||||
ng-repeat="property in propertyGroup | filter:ctrl.isDriverPropertyActive"
|
||||
ng-init="name = property.name;
|
||||
selectOptions = property.getSelectOptions()"
|
||||
ng-class="{'has-error': enrollNodeForm.{$ name $}.$invalid &&
|
||||
enrollNodeForm.{$ name $}.$dirty}">
|
||||
ng-class="{'has-error': baseNodeForm.{$ name $}.$invalid &&
|
||||
baseNodeForm.{$ name $}.$dirty}">
|
||||
<label for="{$ name $}"
|
||||
class="control-label"
|
||||
style="white-space: nowrap">
|
||||
@ -269,7 +326,7 @@
|
||||
</div>
|
||||
<!--end tabbed content-->
|
||||
</form>
|
||||
<!--end enroll node form-->
|
||||
<!--end base node form-->
|
||||
</div>
|
||||
</div>
|
||||
<!--modal footer-->
|
||||
@ -282,13 +339,12 @@
|
||||
|
||||
<button type="submit"
|
||||
ng-disabled="!ctrl.driverProperties ||
|
||||
enrollNodeForm.$invalid ||
|
||||
PropertiesForm.$invalid ||
|
||||
ExtraForm.$invalid ||
|
||||
InstanceInfoForm.$invalid"
|
||||
ng-click="ctrl.enroll()"
|
||||
propertiesForm.$invalid ||
|
||||
extraForm.$invalid ||
|
||||
instanceInfoForm.$invalid"
|
||||
ng-click="ctrl.submit()"
|
||||
class="btn btn-primary"
|
||||
translate>
|
||||
Enroll Node
|
||||
{$ ctrl.submitButtonTitle $}
|
||||
</button>
|
||||
</div>
|
@ -0,0 +1,673 @@
|
||||
/*
|
||||
* 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';
|
||||
|
||||
var REQUIRED = " " + gettext("Required") + ".";
|
||||
|
||||
var SELECT_OPTIONS_REGEX =
|
||||
new RegExp(
|
||||
gettext('(?:[Oo]ne of )(?!this)((?:(?:"[^"]+"|[^,\\. ]+)(?:, |\\.))+)'));
|
||||
|
||||
var DEFAULT_IS_REGEX =
|
||||
new RegExp(gettext('default (?:value )?is ([^"\\. ]+|"[^"]+")'));
|
||||
|
||||
var DEFAULTS_TO_REGEX =
|
||||
new RegExp(gettext('Defaults to ([^"\\. ]+|"[^"]+")'));
|
||||
|
||||
var DEFAULT_IN_PARENS_REGEX =
|
||||
new RegExp(gettext(' ([^" ]+|"[^"]+") \\(Default\\)'));
|
||||
|
||||
var DEFAULT_REGEX_LIST = [DEFAULT_IS_REGEX,
|
||||
DEFAULTS_TO_REGEX,
|
||||
DEFAULT_IN_PARENS_REGEX];
|
||||
var ONE_OF_REGEX =
|
||||
new RegExp(gettext('One of this, (.*) must be specified\\.'));
|
||||
|
||||
var NOT_INSIDE_MATCH = -1;
|
||||
|
||||
var VALID_PORT_REGEX = new RegExp('^\\d+$');
|
||||
|
||||
var VALID_IPV4_ADDRESS = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; // eslint-disable-line max-len
|
||||
|
||||
var VALID_IPV6_ADDRESS = "^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"; // eslint-disable-line max-len
|
||||
|
||||
angular
|
||||
.module('horizon.dashboard.admin.ironic')
|
||||
.factory('horizon.dashboard.admin.ironic.base-node.service',
|
||||
baseNodeService);
|
||||
|
||||
baseNodeService.$inject = [
|
||||
'$modal',
|
||||
'$log',
|
||||
'horizon.dashboard.admin.ironic.validHostNamePattern',
|
||||
'horizon.dashboard.admin.ironic.validUuidPattern'
|
||||
];
|
||||
|
||||
function baseNodeService($modal,
|
||||
$log,
|
||||
validHostNamePattern,
|
||||
validUuidPattern) {
|
||||
var service = {
|
||||
DriverProperty: DriverProperty,
|
||||
Graph: Graph
|
||||
};
|
||||
|
||||
var VALID_ADDRESS_HOSTNAME_REGEX = new RegExp(VALID_IPV4_ADDRESS + "|" +
|
||||
VALID_IPV6_ADDRESS + "|" +
|
||||
validHostNamePattern);
|
||||
|
||||
var VALID_IMAGE_REGEX = new RegExp(validUuidPattern + "|" +
|
||||
"^(https?|file)://.+$");
|
||||
|
||||
/**
|
||||
The DriverProperty class is used to represent an ironic driver
|
||||
property. It is currently used by the base-node form to
|
||||
support property display, value assignment and validation.
|
||||
|
||||
The following rules are used to extract information about a property
|
||||
from the description returned by the driver.
|
||||
|
||||
1. If the description ends with " Required." a value must be
|
||||
supplied for the property.
|
||||
|
||||
2. The following syntax is used to extract default values
|
||||
from property descriptions.
|
||||
|
||||
Default is <value>(<space>|.)
|
||||
default is “<value>”
|
||||
default value is <value>(<space>|.)
|
||||
default value is “<value>”
|
||||
Defaults to <value>(<space>|.)
|
||||
Defaults to “<value>”
|
||||
<value> (Default)
|
||||
|
||||
3. The following syntax is used to determine whether a property
|
||||
is considered active. In the example below if the user specifies
|
||||
a value for <property-name-1>, properties 2 to n will be tagged
|
||||
inactive, and hidden from view. All properties are considered
|
||||
to be required.
|
||||
|
||||
One of this, <property-name-1>, <property-name-2>, …, or
|
||||
<property-name-n> must be specified.
|
||||
|
||||
4. The following syntax is used to determine whether a property
|
||||
is restricted to a set of enumerated values. The property will
|
||||
be displayed as an HTML select element.
|
||||
|
||||
[Oo]ne of <value-1>, "<value-2>", …, <value-n>.
|
||||
|
||||
5. The following syntax is used to determine whether a property is
|
||||
active and required based on the value of another property.
|
||||
If the property is not active it will not be displayed.
|
||||
|
||||
Required|Used only if <property-name> is set to <value-1>
|
||||
(or "<value-2>")*.
|
||||
|
||||
Notes:
|
||||
1. The properties "deploy_kernel" and "deploy_ramdisk" are
|
||||
assumed to accept Glance image uuids as valid values.
|
||||
|
||||
2. Property names ending in _port are assumed to only accept
|
||||
postive integer values
|
||||
|
||||
3. Property names ending in _address are assumed to only accept
|
||||
valid IPv4 and IPv6 addresses; and hostnames
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description Construct a new driver property
|
||||
*
|
||||
* @class DriverProperty
|
||||
* @param {string} name - Name of property
|
||||
* @param {string} desc - Description of property
|
||||
* @param {object} propertySet - Set of properties to which this one belongs
|
||||
*
|
||||
* @property {string} defaultValue - Default value of the property
|
||||
* @property {string[]} selectOptions - If the property is limited to a
|
||||
* set of enumerated values then selectOptions will be an array of those
|
||||
* values, otherwise null
|
||||
* @property {boolean} required - Boolean value indicating whether a value
|
||||
* must be supplied for this property if it is active
|
||||
* @property {PostfixExpr} isActiveExpr - Null if this property is always
|
||||
* active; otherwise, a boolean expression that when evaluated will
|
||||
* return whether this variable is active. A property is considered
|
||||
* active if its role is not eliminated by the values of other
|
||||
* properties in the property-set.
|
||||
* @property {string} inputValue - User assigned value for this property
|
||||
* @property {regexp} validValueRegex - Regular expression used to
|
||||
* determine whether an input value is valid.
|
||||
* @returns {object} Driver property
|
||||
*/
|
||||
function DriverProperty(name, desc, propertySet) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.propertySet = propertySet;
|
||||
|
||||
// Determine whether this property should be presented as a selection
|
||||
this.selectOptions = this._analyzeSelectOptions();
|
||||
|
||||
this.required = null; // Initialize to unknown
|
||||
// Expression to be evaluated to determine whether property is active.
|
||||
// By default the property is considered active.
|
||||
this.isActiveExpr = null;
|
||||
var result = this._analyzeRequiredOnlyDependencies();
|
||||
if (result) {
|
||||
this.required = result[0];
|
||||
this.isActiveExpr = result[1];
|
||||
}
|
||||
if (!this.isActiveExpr) {
|
||||
result = this._analyzeOneOfDependencies();
|
||||
if (result) {
|
||||
this.required = result[0];
|
||||
this.isActiveExpr = result[1];
|
||||
}
|
||||
}
|
||||
if (this.required === null) {
|
||||
this.required = desc.endsWith(REQUIRED);
|
||||
}
|
||||
|
||||
this.defaultValue = this._getDefaultValue();
|
||||
this.inputValue = this.defaultValue;
|
||||
|
||||
// Infer that property is a boolean that can be represented as a
|
||||
// True/False selection
|
||||
if (this.selectOptions === null &&
|
||||
(this.defaultValue === "True" || this.defaultValue === "False")) {
|
||||
this.selectOptions = ["True", "False"];
|
||||
}
|
||||
|
||||
this.validValueRegex = _determineValidValueRegex(this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Return a regular expression that can be used to
|
||||
* validate the value of a specified property
|
||||
*
|
||||
* @param {string} propertyName - Name of property
|
||||
* @return {regexp} Regular expression object or undefined
|
||||
*/
|
||||
function _determineValidValueRegex(propertyName) {
|
||||
var regex;
|
||||
if (propertyName.endsWith("_port")) {
|
||||
regex = VALID_PORT_REGEX;
|
||||
} else if (propertyName.endsWith("_address")) {
|
||||
regex = VALID_ADDRESS_HOSTNAME_REGEX;
|
||||
} else if (propertyName === "deploy_kernel") {
|
||||
regex = VALID_IMAGE_REGEX;
|
||||
} else if (propertyName === "deploy_ramdisk") {
|
||||
regex = VALID_IMAGE_REGEX;
|
||||
}
|
||||
|
||||
return regex;
|
||||
}
|
||||
|
||||
DriverProperty.prototype.isActive = function() {
|
||||
if (!this.isActiveExpr) {
|
||||
return true;
|
||||
}
|
||||
var ret = this.isActiveExpr.evaluate(this.propertySet);
|
||||
return ret[0] === PostfixExpr.status.OK &&
|
||||
typeof ret[1] === "boolean" ? ret[1] : true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get a regular expression object that can be used to
|
||||
* determine whether a value is valid for this property
|
||||
*
|
||||
* @return {regexp} Regular expression object or undefined
|
||||
*/
|
||||
DriverProperty.prototype.getValidValueRegex = function() {
|
||||
return this.validValueRegex;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Must a value be provided for this property
|
||||
*
|
||||
* @return {boolean} True if a value must be provided for this property
|
||||
*/
|
||||
DriverProperty.prototype.isRequired = function() {
|
||||
return this.required;
|
||||
};
|
||||
|
||||
DriverProperty.prototype._analyzeSelectOptions = function() {
|
||||
var match = this.desc.match(SELECT_OPTIONS_REGEX);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var matches = match[1].substring(0, match[1].length - 1).split(", ");
|
||||
var options = [];
|
||||
angular.forEach(matches, function(match) {
|
||||
options.push(trimQuotes(match));
|
||||
});
|
||||
return options;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the list of select options for this property
|
||||
*
|
||||
* @return {string[]} null if this property is not selectable; else,
|
||||
* an array of selectable options
|
||||
*/
|
||||
DriverProperty.prototype.getSelectOptions = function() {
|
||||
return this.selectOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Remove leading/trailing double-quotes from a string
|
||||
*
|
||||
* @param {string} str - String to be trimmed
|
||||
* @return {string} trim'd string
|
||||
*/
|
||||
function trimQuotes(str) {
|
||||
return str.charAt(0) === '"'
|
||||
? str.substring(1, str.length - 1) : str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the default value of this property
|
||||
*
|
||||
* @return {string} Default value of this property
|
||||
*/
|
||||
DriverProperty.prototype._getDefaultValue = function() {
|
||||
var value;
|
||||
for (var i = 0; i < DEFAULT_REGEX_LIST.length; i++) {
|
||||
var match = this.desc.match(DEFAULT_REGEX_LIST[i]);
|
||||
if (match) {
|
||||
value = trimQuotes(match[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$log.debug("_getDefaultValue | " + this.desc + " | " + value);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the input value of this property
|
||||
*
|
||||
* @return {string} the input value of this property
|
||||
*/
|
||||
DriverProperty.prototype.getInputValue = function() {
|
||||
return this.inputValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the default value of this property
|
||||
*
|
||||
* @return {string} the default value of this property
|
||||
*/
|
||||
DriverProperty.prototype.getDefaultValue = function() {
|
||||
return this.defaultValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the description of this property
|
||||
*
|
||||
* @return {string} Description of this property
|
||||
*/
|
||||
DriverProperty.prototype.getDescription = function() {
|
||||
return this.desc;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Use the property description to build an expression
|
||||
* that will evaluate to a boolean result indicating whether the
|
||||
* property is active
|
||||
*
|
||||
* @return {array} null if this property is not dependent on any others;
|
||||
* otherwise,
|
||||
* [0] boolean indicating whether if active a value must be
|
||||
* supplied for this property.
|
||||
* [1] an expression that when evaluated will return a boolean
|
||||
* result indicating whether this property is active
|
||||
*/
|
||||
DriverProperty.prototype._analyzeRequiredOnlyDependencies = function() {
|
||||
var re = /(Required|Used) only if ([^ ]+) is set to /g;
|
||||
var match = re.exec(this.desc);
|
||||
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build logical expression to describe under what conditions this
|
||||
// property is active
|
||||
var expr = new PostfixExpr();
|
||||
var numAdds = 0;
|
||||
|
||||
var i = NOT_INSIDE_MATCH;
|
||||
var j = re.lastIndex;
|
||||
while (j < this.desc.length) {
|
||||
if (i === NOT_INSIDE_MATCH && this.desc.charAt(j) === ".") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.desc.charAt(j) === '"') {
|
||||
if (i === NOT_INSIDE_MATCH) {
|
||||
i = j + 1;
|
||||
} else {
|
||||
expr.addProperty(match[2]);
|
||||
expr.addValue(this.desc.substring(i, j));
|
||||
expr.addOperator(PostfixExpr.op.EQ);
|
||||
numAdds++;
|
||||
if (numAdds > 1) {
|
||||
expr.addOperator(PostfixExpr.op.OR);
|
||||
}
|
||||
i = NOT_INSIDE_MATCH;
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
$log.debug("_analyzeRequiredOnlyDependencies | " +
|
||||
this.desc + " | " +
|
||||
match[2] + ", " +
|
||||
JSON.stringify(expr));
|
||||
return [match[1] === "Required", expr];
|
||||
};
|
||||
|
||||
DriverProperty.prototype._analyzeOneOfDependencies = function() {
|
||||
var match = this.desc.match(ONE_OF_REGEX);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build logical expression to describe under what conditions this
|
||||
// property is active
|
||||
var expr = new PostfixExpr();
|
||||
|
||||
var parts = match[1].split(", or ");
|
||||
expr.addProperty(parts[1]);
|
||||
expr.addValue(undefined);
|
||||
expr.addOperator(PostfixExpr.op.EQ);
|
||||
|
||||
parts = parts[0].split(", ");
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
expr.addProperty(parts[i]);
|
||||
expr.addValue(undefined);
|
||||
expr.addOperator(PostfixExpr.op.EQ);
|
||||
expr.addOperator(PostfixExpr.op.AND);
|
||||
}
|
||||
$log.debug("_analyzeOneOfDependencies | " +
|
||||
this.desc + " | " +
|
||||
JSON.stringify(match) + ", " +
|
||||
JSON.stringify(expr));
|
||||
return [true, expr];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the names of the driver-properties whose values
|
||||
* determine whether this property is active
|
||||
*
|
||||
* @return {object} Object the properties of which are names of
|
||||
* activating driver-properties or null
|
||||
*/
|
||||
DriverProperty.prototype.getActivators = function() {
|
||||
return this.isActiveExpr ? this.isActiveExpr.getProperties() : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* PostFixExpr is a class primarily developed to support the
|
||||
* evaluation of boolean expressions that determine whether a
|
||||
* particular property is active.
|
||||
*
|
||||
* The expression is stored as a postfix sequence of operands and
|
||||
* operators. Operands are currently limited to the literal values
|
||||
* and the values of properties in a specified set. Currently
|
||||
* supported operands are ==, or, and.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function PostfixExpr() {
|
||||
this.elem = [];
|
||||
}
|
||||
|
||||
PostfixExpr.op = {
|
||||
EQ: "==",
|
||||
AND: "and",
|
||||
OR: "or"
|
||||
};
|
||||
|
||||
PostfixExpr.UNDEFINED = undefined;
|
||||
|
||||
PostfixExpr.status = {
|
||||
OK: 0,
|
||||
ERROR: 1,
|
||||
BAD_ARG: 2,
|
||||
UNKNOWN_OP: 3,
|
||||
MALFORMED: 4
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add a property to the expression
|
||||
*
|
||||
* @param {string} propertyName - Property name
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
PostfixExpr.prototype.addProperty = function(propertyName) {
|
||||
this.elem.push({name: propertyName});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add a value to the expression
|
||||
*
|
||||
* @param {object} value - value
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
PostfixExpr.prototype.addValue = function(value) {
|
||||
this.elem.push({value: value});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add an operator to the expression
|
||||
*
|
||||
* @param {PostfixExpr.op} opId - operator
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
PostfixExpr.prototype.addOperator = function(opId) {
|
||||
this.elem.push({op: opId});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get a list of property names referenced by this
|
||||
* expression
|
||||
*
|
||||
* @return {object} An object each property of which corresponds to
|
||||
* a property in the expression
|
||||
*/
|
||||
PostfixExpr.prototype.getProperties = function() {
|
||||
var properties = {};
|
||||
angular.forEach(this.elem, function(elem) {
|
||||
if (angular.isDefined(elem.name)) {
|
||||
properties[elem.name] = true;
|
||||
}
|
||||
});
|
||||
return properties;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Evaluate a boolean binary operation
|
||||
*
|
||||
* @param {array} valStack - Stack of values to operate on
|
||||
* @param {string} opId - operator id
|
||||
*
|
||||
* @return {integer} Return code
|
||||
*/
|
||||
function _evaluateBoolBinaryOp(valStack, opId) {
|
||||
var retCode = PostfixExpr.status.OK;
|
||||
var val1 = valStack.pop();
|
||||
var val2 = valStack.pop();
|
||||
if (typeof val1 === "boolean" &&
|
||||
typeof val2 === "boolean") {
|
||||
switch (opId) {
|
||||
case PostfixExpr.op.AND:
|
||||
valStack.push(val1 && val2);
|
||||
break;
|
||||
case PostfixExpr.op.OR:
|
||||
valStack.push(val1 || val2);
|
||||
break;
|
||||
default:
|
||||
retCode = PostfixExpr.status.UNKNOWN_OP;
|
||||
}
|
||||
} else {
|
||||
retCode = PostfixExpr.status.BAD_ARG;
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Evaluate the experssion using property values from
|
||||
* a specified set
|
||||
*
|
||||
* @param {object} propertySet - Dictionary of DriverProperty instances
|
||||
*
|
||||
* @return {array} Return code and Value of the expression
|
||||
*/
|
||||
PostfixExpr.prototype.evaluate = function(propertySet) {
|
||||
var resultStack = [];
|
||||
for (var i = 0, len = this.elem.length; i < len; i++) {
|
||||
var elem = this.elem[i];
|
||||
if (elem.hasOwnProperty("name")) {
|
||||
resultStack.push(propertySet[elem.name].getInputValue());
|
||||
} else if (elem.hasOwnProperty("value")) {
|
||||
resultStack.push(elem.value);
|
||||
} else if (elem.hasOwnProperty("op")) {
|
||||
if (elem.op === PostfixExpr.op.EQ) {
|
||||
var val1 = resultStack.pop();
|
||||
var val2 = resultStack.pop();
|
||||
resultStack.push(val1 === val2);
|
||||
} else {
|
||||
var ret = _evaluateBoolBinaryOp(resultStack, elem.op);
|
||||
if (ret !== PostfixExpr.status.OK) {
|
||||
return [ret, PostfixExpr.UNDEFINED];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return [PostfixExpr.status.UNKNOWN_ELEMENT, PostfixExpr.UNDEFINED];
|
||||
}
|
||||
}
|
||||
return resultStack.length === 1
|
||||
? [PostfixExpr.status.OK, resultStack.pop()]
|
||||
: [PostfixExpr.status.MALFORMED, PostfixExpr.UNDEFINED];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Class for representing and manipulating undirected
|
||||
* graphs
|
||||
*
|
||||
* @property {object} vertices - Associative array of vertex objects
|
||||
* indexed by property name
|
||||
* @return {object} Graph
|
||||
*/
|
||||
function Graph() {
|
||||
this.vertices = {};
|
||||
}
|
||||
|
||||
Graph.prototype.getVertex = function(vertexName) {
|
||||
var vertex = null;
|
||||
if (this.vertices.hasOwnProperty(vertexName)) {
|
||||
vertex = this.vertices[vertexName];
|
||||
}
|
||||
return vertex;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add a vertex to this graph
|
||||
*
|
||||
* @param {string} name - Vertex name
|
||||
* @param {object} data - Vertex data
|
||||
* @returns {object} - Newly created vertex
|
||||
*/
|
||||
Graph.prototype.addVertex = function(name, data) {
|
||||
var vertex = {name: name, data: data, adjacents: []};
|
||||
this.vertices[name] = vertex;
|
||||
return vertex;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add an undirected edge between two vertices
|
||||
*
|
||||
* @param {string} vertexName1 - Name of first vertex
|
||||
* @param {string} vertexName2 - Name of second vertex
|
||||
* @returns {void}
|
||||
*/
|
||||
Graph.prototype.addEdge = function(vertexName1, vertexName2) {
|
||||
this.vertices[vertexName1].adjacents.push(vertexName2);
|
||||
this.vertices[vertexName2].adjacents.push(vertexName1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Depth-first-search graph traversal utility function
|
||||
*
|
||||
* @param {object} vertex - Root vertex from which traveral will begin.
|
||||
* It is assumed that this vertex has not alreday been visited as part
|
||||
* of this traversal.
|
||||
* @param {object} visited - Associative array. Each named property
|
||||
* corresponds to a vertex with the same name, and has boolean value
|
||||
* indicating whether the vertex has been alreday visited.
|
||||
* @param {object[]} component - Array of vertices that define a strongly
|
||||
* connected component.
|
||||
* @returns {void}
|
||||
*/
|
||||
Graph.prototype._dfsTraverse = function(vertex, visited, component) {
|
||||
var graph = this;
|
||||
visited[vertex.name] = true;
|
||||
component.push(vertex);
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
angular.forEach(vertex.adjacents, function(vertexName) {
|
||||
if (!visited[vertexName]) {
|
||||
graph._dfsTraverse(graph.vertices[vertexName], visited, component);
|
||||
}
|
||||
});
|
||||
/* eslint-enable no-unused-vars */
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Perform a depth-first-search on a specified graph to
|
||||
* find strongly connected components. A user provided function will
|
||||
* be called to process each component.
|
||||
*
|
||||
* @param {function} componentFunc - Function called on each strongly
|
||||
* connected component. Accepts aruments: array of vertex objects, and
|
||||
* user-provided extra data that can be used in processing the component.
|
||||
* @param {object} extra - Extra data that is passed into the component
|
||||
* processing function.
|
||||
* @returns {void}
|
||||
*/
|
||||
Graph.prototype.dfs = function(componentFunc, extra) {
|
||||
var graph = this;
|
||||
var visited = {};
|
||||
angular.forEach(
|
||||
graph.vertices,
|
||||
function(unused, name) {
|
||||
visited[name] = false;
|
||||
});
|
||||
|
||||
angular.forEach(this.vertices, function(vertex, vertexName) {
|
||||
if (!visited[vertexName]) {
|
||||
var component = [];
|
||||
graph._dfsTraverse(vertex, visited, component);
|
||||
componentFunc(component, extra);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return service;
|
||||
}
|
||||
})();
|
@ -18,7 +18,7 @@
|
||||
"use strict";
|
||||
|
||||
describe(
|
||||
'horizon.dashboard.admin.ironic.enroll-node.service',
|
||||
'horizon.dashboard.admin.ironic.base-node.service',
|
||||
function() {
|
||||
var service;
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
|
||||
beforeEach(inject(function($injector) {
|
||||
service =
|
||||
$injector.get('horizon.dashboard.admin.ironic.enroll-node.service');
|
||||
$injector.get('horizon.dashboard.admin.ironic.base-node.service');
|
||||
}));
|
||||
|
||||
it('defines the service', function() {
|
@ -0,0 +1,184 @@
|
||||
/*
|
||||
* 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 edit an existing Ironic node
|
||||
*/
|
||||
angular
|
||||
.module('horizon.dashboard.admin.ironic')
|
||||
.controller('EditNodeController', EditNodeController);
|
||||
|
||||
EditNodeController.$inject = [
|
||||
'$rootScope',
|
||||
'$controller',
|
||||
'$modalInstance',
|
||||
'horizon.framework.widgets.toast.service',
|
||||
'horizon.app.core.openstack-service-api.ironic',
|
||||
'horizon.dashboard.admin.ironic.events',
|
||||
'horizon.dashboard.admin.ironic.edit-node.service',
|
||||
'$log',
|
||||
'node'
|
||||
];
|
||||
|
||||
function EditNodeController($rootScope,
|
||||
$controller,
|
||||
$modalInstance,
|
||||
toastService,
|
||||
ironic,
|
||||
ironicEvents,
|
||||
editNodeService,
|
||||
$log,
|
||||
node) {
|
||||
var ctrl = this;
|
||||
|
||||
$controller('BaseNodeController',
|
||||
{ctrl: ctrl,
|
||||
$modalInstance: $modalInstance});
|
||||
|
||||
ctrl.modalTitle = gettext("Edit Node");
|
||||
ctrl.submitButtonTitle = gettext("Update Node");
|
||||
|
||||
ctrl.node.instance_info = {};
|
||||
ctrl.showInstanceInfo = true;
|
||||
|
||||
ctrl.baseNode = null;
|
||||
|
||||
init(node);
|
||||
|
||||
function init(node) {
|
||||
ctrl._loadDrivers().then(function() {
|
||||
_loadNodeData(node.uuid);
|
||||
});
|
||||
ctrl._getImages();
|
||||
}
|
||||
|
||||
function _loadNodeData(nodeId) {
|
||||
ironic.getNode(nodeId).then(function(response) {
|
||||
var node = response.data;
|
||||
|
||||
ctrl.baseNode = node;
|
||||
|
||||
ctrl.node.name = node.name;
|
||||
for (var i = 0; i < ctrl.drivers.length; i++) {
|
||||
if (ctrl.drivers[i].name === node.driver) {
|
||||
ctrl.selectedDriver = ctrl.drivers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ctrl.loadDriverProperties(node.driver).then(function() {
|
||||
angular.forEach(node.driver_info, function(value, property) {
|
||||
if (angular.isDefined(ctrl.driverProperties[property])) {
|
||||
ctrl.driverProperties[property].inputValue = value;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
ctrl.node.properties = angular.copy(node.properties);
|
||||
ctrl.node.extra = angular.copy(node.extra);
|
||||
ctrl.node.instance_info = angular.copy(node.instance_info);
|
||||
ctrl.node.uuid = node.uuid;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Delete a node instance property
|
||||
*
|
||||
* @param {string} propertyName - Name of the property
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.deleteInstanceProperty = function(propertyName) {
|
||||
delete ctrl.node.instance_info[propertyName];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether the specified node instance property
|
||||
* already exists
|
||||
*
|
||||
* @param {string} propertyName - Name of the instance property
|
||||
* @return {boolean} True if the property already exists,
|
||||
* otherwise false
|
||||
*/
|
||||
ctrl.checkInstancePropertyUnique = function(propertyName) {
|
||||
return !(propertyName in ctrl.node.instance_info);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Construct a patch that converts source node into
|
||||
* target node
|
||||
*
|
||||
* @param {object} sourceNode - Source node
|
||||
* @param {object} targetNode - Target node
|
||||
* @return {object[]} Array of patch instructions
|
||||
*/
|
||||
function buildPatch(sourceNode, targetNode) {
|
||||
var patcher = new editNodeService.NodeUpdatePatch();
|
||||
|
||||
patcher.buildPatch(sourceNode.name, targetNode.name, "/name");
|
||||
patcher.buildPatch(sourceNode.driver, targetNode.driver, "/driver");
|
||||
patcher.buildPatch(sourceNode.properties,
|
||||
targetNode.properties,
|
||||
"/properties");
|
||||
patcher.buildPatch(sourceNode.extra,
|
||||
targetNode.extra,
|
||||
"/extra");
|
||||
patcher.buildPatch(sourceNode.driver_info,
|
||||
targetNode.driver_info,
|
||||
"/driver_info");
|
||||
patcher.buildPatch(sourceNode.instance_info,
|
||||
targetNode.instance_info,
|
||||
"/instance_info");
|
||||
|
||||
return patcher.getPatch();
|
||||
}
|
||||
|
||||
ctrl.submit = function() {
|
||||
$modalInstance.close();
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
$log.info("Updating node " + JSON.stringify(ctrl.baseNode));
|
||||
$log.info("to " + JSON.stringify(ctrl.node));
|
||||
|
||||
var patch = buildPatch(ctrl.baseNode, ctrl.node);
|
||||
$log.info("patch = " + JSON.stringify(patch.patch));
|
||||
if (patch.status === editNodeService.NodeUpdatePatch.status.OK) {
|
||||
ironic.updateNode(ctrl.baseNode.uuid, patch.patch).then(function() {
|
||||
$rootScope.$emit(ironicEvents.EDIT_NODE_SUCCESS);
|
||||
});
|
||||
} else {
|
||||
toastService.add('error',
|
||||
gettext('Unable to create node update patch.'));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
})();
|
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* 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';
|
||||
|
||||
angular
|
||||
.module('horizon.dashboard.admin.ironic')
|
||||
.factory('horizon.dashboard.admin.ironic.edit-node.service',
|
||||
editNodeService);
|
||||
|
||||
editNodeService.$inject = [
|
||||
'$modal',
|
||||
'horizon.dashboard.admin.basePath',
|
||||
'$log'
|
||||
];
|
||||
|
||||
function editNodeService($modal, basePath, $log) {
|
||||
var service = {
|
||||
modal: modal,
|
||||
NodeUpdatePatch: NodeUpdatePatch
|
||||
};
|
||||
|
||||
function modal(node) {
|
||||
var options = {
|
||||
controller: 'EditNodeController as ctrl',
|
||||
backdrop: 'static',
|
||||
resolve: {
|
||||
node: function() {
|
||||
return node;
|
||||
}
|
||||
},
|
||||
templateUrl: basePath + '/ironic/base-node/base-node.html'
|
||||
};
|
||||
return $modal.open(options);
|
||||
}
|
||||
|
||||
/*
|
||||
The NodeUpdatePatch class is used to construct a set of patch
|
||||
instructions that transform a base node into a specified target.
|
||||
This class supports the edit-node functionality.
|
||||
*/
|
||||
function NodeUpdatePatch() {
|
||||
this.patch = [];
|
||||
this.status = NodeUpdatePatch.status.OK;
|
||||
}
|
||||
|
||||
NodeUpdatePatch.status = {
|
||||
OK: 0,
|
||||
ERROR: 1,
|
||||
UNKNOWN_TYPE: 2
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Update the status of the patch with a specified code
|
||||
*
|
||||
* @param {int} status - latest status code
|
||||
* @return {void}
|
||||
*/
|
||||
NodeUpdatePatch.prototype._updateStatus = function(status) {
|
||||
this.status = Match.max(this.status, status);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether an item is a property
|
||||
*
|
||||
* @param {object} item - item to be tested
|
||||
* @return {boolean} True if the item is a number, string, or date
|
||||
*/
|
||||
function isProperty(item) {
|
||||
return angular.isNumber(item) ||
|
||||
angular.isString(item) ||
|
||||
angular.isDate(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Check whether an item is a collection
|
||||
*
|
||||
* @param {object} item - item to be tested
|
||||
* @return {boolean} True if the item is an array or object
|
||||
*/
|
||||
function isCollection(item) {
|
||||
return angular.isArray(item) || angular.isObject(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Add instructions to the patch for processing a
|
||||
* specified item
|
||||
*
|
||||
* @param {object} item - item to be added
|
||||
* @param {string} path - Path to the item being added
|
||||
* @param {string} op - add or remove
|
||||
* @return {void}
|
||||
*/
|
||||
NodeUpdatePatch.prototype._processItem = function(item, path, op) {
|
||||
$log.info("NodeUpdatePatch._processItem: " + path + " " + op);
|
||||
if (isProperty(item)) {
|
||||
this.patch.push({op: op, path: path, value: item});
|
||||
} else if (isCollection(item)) {
|
||||
angular.forEach(item, function(partName, part) {
|
||||
this._processItem(part, path + "/" + partName, op);
|
||||
});
|
||||
} else {
|
||||
this._updateStatus(NodeUpdatePatch.status.UNKNOWN_TYPE);
|
||||
$log.error("Unable to process (" + op + ") item (" + path + "). " +
|
||||
" " + typeof item + " " + JSON.stringify(item));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add instructions to the patch for adding a specified item
|
||||
*
|
||||
* @param {object} item - item to be added
|
||||
* @param {string} path - Path to the item being removed
|
||||
* @return {void}
|
||||
*/
|
||||
NodeUpdatePatch.prototype._addItem = function(item, path) {
|
||||
this._processItem(item, path, "add");
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add instructions to the patch for removing a specified item
|
||||
*
|
||||
* @param {object} item - item to be removed
|
||||
* @param {string} path - Path to the item being removed
|
||||
* @return {void}
|
||||
*/
|
||||
NodeUpdatePatch.prototype._removeItem = function(item, path) {
|
||||
this._processItem(item, path, "remove");
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Determine the set of operations required to
|
||||
* transform a source version of an object into a target version,
|
||||
* and add them to a patch.
|
||||
*
|
||||
* @param {object} source - Source object
|
||||
* @param {object} target - Target object
|
||||
* @param {string} path - Pathname of the patched object
|
||||
* @return {void}
|
||||
*/
|
||||
NodeUpdatePatch.prototype.buildPatch = function(source, target, path) {
|
||||
$log.info("NodeUpdatePatch._buildPatch: " + path);
|
||||
var patcher = this;
|
||||
|
||||
if (isProperty(source) && isProperty(target)) {
|
||||
if (source !== target) {
|
||||
patcher.patch.push({op: "replace", path: path, value: target});
|
||||
}
|
||||
} else if (isCollection(source) && isCollection(target)) {
|
||||
angular.forEach(source, function(sourceItem, sourceItemName) {
|
||||
if (angular.isDefined(target[sourceItemName])) {
|
||||
patcher.buildPatch(sourceItem,
|
||||
target[sourceItemName],
|
||||
path + '/' + sourceItemName);
|
||||
} else {
|
||||
patcher._removeItem(sourceItem, path + '/' + sourceItemName);
|
||||
}
|
||||
});
|
||||
angular.forEach(target, function(targetItem, targetItemName) {
|
||||
if (angular.isUndefined(source[targetItemName])) {
|
||||
patcher._addItem(targetItem, path + '/' + targetItemName);
|
||||
}
|
||||
});
|
||||
} else if (isProperty(source) && isCollection(target) ||
|
||||
isCollection(source) && isProperty(target)) {
|
||||
patcher._removeItem(source, path);
|
||||
patcher._addItem(target, path);
|
||||
} else {
|
||||
patcher._updateStatus(NodeUpdatePatch.status.ERROR);
|
||||
$log.error("Unable to patch " + path + " " +
|
||||
"source = " + JSON.stringify(source) + ", " +
|
||||
"target = " + JSON.stringify(target));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the patch
|
||||
*
|
||||
* @return {object} An object with two properties:
|
||||
* patch: Array of patch instructions compatible with the Ironic
|
||||
* node update function
|
||||
* status: Code indicating whether patch creation was successful
|
||||
*
|
||||
*/
|
||||
NodeUpdatePatch.prototype.getPatch = function() {
|
||||
return {patch: angular.copy(this.patch), status: this.status};
|
||||
};
|
||||
|
||||
return service;
|
||||
}
|
||||
})();
|
@ -25,242 +25,37 @@
|
||||
|
||||
EnrollNodeController.$inject = [
|
||||
'$rootScope',
|
||||
'$controller',
|
||||
'$modalInstance',
|
||||
'horizon.app.core.openstack-service-api.ironic',
|
||||
'horizon.dashboard.admin.ironic.events',
|
||||
'horizon.app.core.openstack-service-api.glance',
|
||||
'horizon.dashboard.admin.ironic.enroll-node.service',
|
||||
'horizon.dashboard.admin.ironic.validHostNamePattern',
|
||||
'$log'
|
||||
];
|
||||
|
||||
function EnrollNodeController($rootScope,
|
||||
$controller,
|
||||
$modalInstance,
|
||||
ironic,
|
||||
ironicEvents,
|
||||
glance,
|
||||
enrollNodeService,
|
||||
validHostNamePattern,
|
||||
$log) {
|
||||
var ctrl = this;
|
||||
|
||||
ctrl.validHostNameRegex = new RegExp(validHostNamePattern);
|
||||
ctrl.drivers = null;
|
||||
ctrl.images = null;
|
||||
ctrl.loadingDriverProperties = false;
|
||||
// Object containing the set of properties associated with the currently
|
||||
// selected driver
|
||||
ctrl.driverProperties = null;
|
||||
ctrl.driverPropertyGroups = null;
|
||||
ctrl.moveNodeToManageableState = false;
|
||||
$controller('BaseNodeController',
|
||||
{ctrl: ctrl,
|
||||
$modalInstance: $modalInstance});
|
||||
|
||||
// Parameter object that defines the node to be enrolled
|
||||
ctrl.node = {
|
||||
name: null,
|
||||
driver: null,
|
||||
driver_info: {},
|
||||
properties: {},
|
||||
extra: {}
|
||||
};
|
||||
ctrl.modalTitle = gettext("Enroll Node");
|
||||
ctrl.submitButtonTitle = ctrl.modalTitle;
|
||||
|
||||
init();
|
||||
|
||||
function init() {
|
||||
loadDrivers();
|
||||
getImages();
|
||||
ctrl._loadDrivers();
|
||||
ctrl._getImages();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the list of currently active Ironic drivers
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function loadDrivers() {
|
||||
ironic.getDrivers().then(function(response) {
|
||||
ctrl.drivers = response.data.items;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the list of images from Glance
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function getImages() {
|
||||
glance.getImages().then(function(response) {
|
||||
ctrl.images = response.data.items;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Check whether a group contains required properties
|
||||
*
|
||||
* @param {DriverProperty[]} group - Property group
|
||||
* @return {boolean} Return true if the group contains required
|
||||
* properties, false otherwise
|
||||
*/
|
||||
function driverPropertyGroupHasRequired(group) {
|
||||
var hasRequired = false;
|
||||
for (var i = 0; i < group.length; i++) {
|
||||
if (group[i].required) {
|
||||
hasRequired = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hasRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Convert array of driver property groups to a string
|
||||
*
|
||||
* @param {array[]} groups - Array for driver property groups
|
||||
* @return {string} Output string
|
||||
*/
|
||||
function driverPropertyGroupsToString(groups) {
|
||||
var output = [];
|
||||
angular.forEach(groups, function(group) {
|
||||
var groupStr = [];
|
||||
angular.forEach(group, function(property) {
|
||||
groupStr.push(property.name);
|
||||
});
|
||||
groupStr = groupStr.join(", ");
|
||||
output.push(['[', groupStr, ']'].join(""));
|
||||
});
|
||||
output = output.join(", ");
|
||||
return ['[', output, ']'].join("");
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Comaprison function used to sort driver property groups
|
||||
*
|
||||
* @param {DriverProperty[]} group1 - First group
|
||||
* @param {DriverProperty[]} group2 - Second group
|
||||
* @return {integer} Return:
|
||||
* < 0 if group1 should precede group2 in an ascending ordering
|
||||
* > 0 if group2 should precede group1
|
||||
* 0 if group1 and group2 are considered equal from ordering perpsective
|
||||
*/
|
||||
function compareDriverPropertyGroups(group1, group2) {
|
||||
var group1HasRequired = driverPropertyGroupHasRequired(group1);
|
||||
var group2HasRequired = driverPropertyGroupHasRequired(group2);
|
||||
|
||||
if (group1HasRequired === group2HasRequired) {
|
||||
if (group1.length === group2.length) {
|
||||
return group1[0].name.localeCompare(group2[0].name);
|
||||
} else {
|
||||
return group1.length - group2.length;
|
||||
}
|
||||
} else {
|
||||
return group1HasRequired ? -1 : 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Order driver properties in the form using the following
|
||||
* rules:
|
||||
*
|
||||
* (1) Properties that are related to one another should occupy adjacent
|
||||
* locations in the form
|
||||
*
|
||||
* (2) Required properties with no dependents should be located at the
|
||||
* top of the form
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl._sortDriverProperties = function() {
|
||||
// Build dependency graph between driver properties
|
||||
var graph = new enrollNodeService.Graph();
|
||||
|
||||
// Create vertices
|
||||
angular.forEach(ctrl.driverProperties, function(property, name) {
|
||||
graph.addVertex(name, property);
|
||||
});
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
|
||||
// Create edges
|
||||
angular.forEach(ctrl.driverProperties,
|
||||
function(property, name) {
|
||||
var activators = property.getActivators();
|
||||
if (activators) {
|
||||
angular.forEach(activators,
|
||||
function(unused, activatorName) {
|
||||
graph.addEdge(name, activatorName);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
// Perform depth-first-search to find groups of related properties
|
||||
var groups = [];
|
||||
graph.dfs(
|
||||
function(vertexList, components) {
|
||||
// Sort properties so that those with the largest number of
|
||||
// immediate dependents are the top of the list
|
||||
vertexList.sort(function(vertex1, vertex2) {
|
||||
return vertex2.adjacents.length - vertex1.adjacents.length;
|
||||
});
|
||||
|
||||
// Build component and add to list
|
||||
var component = new Array(vertexList.length);
|
||||
angular.forEach(vertexList, function(vertex, index) {
|
||||
component[index] = vertex.data;
|
||||
});
|
||||
components.push(component);
|
||||
},
|
||||
groups);
|
||||
groups.sort(compareDriverPropertyGroups);
|
||||
|
||||
$log.debug("Found the following property groups: " +
|
||||
driverPropertyGroupsToString(groups));
|
||||
return groups;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the properties associated with a specified driver
|
||||
*
|
||||
* @param {string} driverName - Name of driver
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.loadDriverProperties = function(driverName) {
|
||||
ctrl.node.driver = driverName;
|
||||
ctrl.node.driver_info = {};
|
||||
|
||||
ctrl.loadingDriverProperties = true;
|
||||
ctrl.driverProperties = null;
|
||||
ctrl.driverPropertyGroups = null;
|
||||
|
||||
ironic.getDriverProperties(driverName).then(function(response) {
|
||||
ctrl.driverProperties = {};
|
||||
angular.forEach(response.data, function(desc, property) {
|
||||
ctrl.driverProperties[property] =
|
||||
new enrollNodeService.DriverProperty(property,
|
||||
desc,
|
||||
ctrl.driverProperties);
|
||||
});
|
||||
ctrl.driverPropertyGroups = ctrl._sortDriverProperties();
|
||||
ctrl.loadingDriverProperties = false;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Cancel the node enrollment process
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.cancel = function() {
|
||||
$modalInstance.dismiss('cancel');
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Enroll the defined node
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.enroll = function() {
|
||||
$log.debug(">> EnrollNodeController.enroll()");
|
||||
ctrl.submit = function() {
|
||||
$log.debug(">> EnrollNodeController.submit()");
|
||||
angular.forEach(ctrl.driverProperties, function(property, name) {
|
||||
$log.debug(name +
|
||||
", required = " + property.isRequired() +
|
||||
@ -289,61 +84,7 @@
|
||||
function() {
|
||||
// No additional error processing for now
|
||||
});
|
||||
$log.debug("<< EnrollNodeController.enroll()");
|
||||
};
|
||||
|
||||
/**
|
||||
* @desription Delete a node property
|
||||
*
|
||||
* @param {string} propertyName - Name of the property
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.deleteProperty = function(propertyName) {
|
||||
delete ctrl.node.properties[propertyName];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether the specified node property already exists
|
||||
*
|
||||
* @param {string} propertyName - Name of the property
|
||||
* @return {boolean} True if the property already exists,
|
||||
* otherwise false
|
||||
*/
|
||||
ctrl.checkPropertyUnique = function(propertyName) {
|
||||
return !(propertyName in ctrl.node.properties);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Delete a node metadata property
|
||||
*
|
||||
* @param {string} propertyName - Name of the property
|
||||
* @return {void}
|
||||
*/
|
||||
ctrl.deleteExtra = function(propertyName) {
|
||||
delete ctrl.node.extra[propertyName];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether the specified node metadata property
|
||||
* already exists
|
||||
*
|
||||
* @param {string} propertyName - Name of the metadata property
|
||||
* @return {boolean} True if the property already exists,
|
||||
* otherwise false
|
||||
*/
|
||||
ctrl.checkExtraUnique = function(propertyName) {
|
||||
return !(propertyName in ctrl.node.extra);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Check whether a specified driver property is
|
||||
* currently active
|
||||
*
|
||||
* @param {string} property - Driver property
|
||||
* @return {boolean} True if the property is active, false otherwise
|
||||
*/
|
||||
ctrl.isDriverPropertyActive = function(property) {
|
||||
return property.isActive();
|
||||
$log.debug("<< EnrollNodeController.submit()");
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
@ -16,35 +16,6 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
var REQUIRED = " " + gettext("Required") + ".";
|
||||
|
||||
var SELECT_OPTIONS_REGEX =
|
||||
new RegExp(
|
||||
gettext('(?:[Oo]ne of )(?!this)((?:(?:"[^"]+"|[^,\\. ]+)(?:, |\\.))+)'));
|
||||
|
||||
var DEFAULT_IS_REGEX =
|
||||
new RegExp(gettext('default (?:value )?is ([^"\\. ]+|"[^"]+")'));
|
||||
|
||||
var DEFAULTS_TO_REGEX =
|
||||
new RegExp(gettext('Defaults to ([^"\\. ]+|"[^"]+")'));
|
||||
|
||||
var DEFAULT_IN_PARENS_REGEX =
|
||||
new RegExp(gettext(' ([^" ]+|"[^"]+") \\(Default\\)'));
|
||||
|
||||
var DEFAULT_REGEX_LIST = [DEFAULT_IS_REGEX,
|
||||
DEFAULTS_TO_REGEX,
|
||||
DEFAULT_IN_PARENS_REGEX];
|
||||
var ONE_OF_REGEX =
|
||||
new RegExp(gettext('One of this, (.*) must be specified\\.'));
|
||||
|
||||
var NOT_INSIDE_MATCH = -1;
|
||||
|
||||
var VALID_PORT_REGEX = new RegExp('^\\d+$');
|
||||
|
||||
var VALID_IPV4_ADDRESS = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; // eslint-disable-line max-len
|
||||
|
||||
var VALID_IPV6_ADDRESS = "^\\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*$"; // eslint-disable-line max-len
|
||||
|
||||
angular
|
||||
.module('horizon.dashboard.admin.ironic')
|
||||
.factory('horizon.dashboard.admin.ironic.enroll-node.service',
|
||||
@ -52,634 +23,23 @@
|
||||
|
||||
enrollNodeService.$inject = [
|
||||
'$modal',
|
||||
'horizon.dashboard.admin.basePath',
|
||||
'$log',
|
||||
'horizon.dashboard.admin.ironic.validHostNamePattern',
|
||||
'horizon.dashboard.admin.ironic.validUuidPattern'
|
||||
'horizon.dashboard.admin.basePath'
|
||||
];
|
||||
|
||||
function enrollNodeService($modal,
|
||||
basePath,
|
||||
$log,
|
||||
validHostNamePattern,
|
||||
validUuidPattern) {
|
||||
function enrollNodeService($modal, basePath) {
|
||||
var service = {
|
||||
modal: modal,
|
||||
DriverProperty: DriverProperty,
|
||||
Graph: Graph
|
||||
modal: modal
|
||||
};
|
||||
|
||||
var VALID_ADDRESS_HOSTNAME_REGEX = new RegExp(VALID_IPV4_ADDRESS + "|" +
|
||||
VALID_IPV6_ADDRESS + "|" +
|
||||
validHostNamePattern);
|
||||
|
||||
var VALID_IMAGE_REGEX = new RegExp(validUuidPattern + "|" +
|
||||
"^(https?|file)://.+$");
|
||||
|
||||
function modal() {
|
||||
var options = {
|
||||
controller: 'EnrollNodeController as ctrl',
|
||||
backdrop: 'static',
|
||||
templateUrl: basePath + '/ironic/enroll-node/enroll-node.html'
|
||||
templateUrl: basePath + '/ironic/base-node/base-node.html'
|
||||
};
|
||||
return $modal.open(options);
|
||||
}
|
||||
|
||||
/**
|
||||
The DriverProperty class is used to represent an ironic driver
|
||||
property. It is currently used by the enroll-node form to
|
||||
support property display, value assignment and validation.
|
||||
|
||||
The following rules are used to extract information about a property
|
||||
from the description returned by the driver.
|
||||
|
||||
1. If the description ends with " Required." a value must be
|
||||
supplied for the property.
|
||||
|
||||
2. The following syntax is used to extract default values
|
||||
from property descriptions.
|
||||
|
||||
Default is <value>(<space>|.)
|
||||
default is “<value>”
|
||||
default value is <value>(<space>|.)
|
||||
default value is “<value>”
|
||||
Defaults to <value>(<space>|.)
|
||||
Defaults to “<value>”
|
||||
<value> (Default)
|
||||
|
||||
3. The following syntax is used to determine whether a property
|
||||
is considered active. In the example below if the user specifies
|
||||
a value for <property-name-1>, properties 2 to n will be tagged
|
||||
inactive, and hidden from view. All properties are considered
|
||||
to be required.
|
||||
|
||||
One of this, <property-name-1>, <property-name-2>, …, or
|
||||
<property-name-n> must be specified.
|
||||
|
||||
4. The following syntax is used to determine whether a property
|
||||
is restricted to a set of enumerated values. The property will
|
||||
be displayed as an HTML select element.
|
||||
|
||||
[Oo]ne of <value-1>, "<value-2>", …, <value-n>.
|
||||
|
||||
5. The following syntax is used to determine whether a property is
|
||||
active and required based on the value of another property.
|
||||
If the property is not active it will not be displayed.
|
||||
|
||||
Required|Used only if <property-name> is set to <value-1>
|
||||
(or "<value-2>")*.
|
||||
|
||||
Notes:
|
||||
1. The properties "deploy_kernel" and "deploy_ramdisk" are
|
||||
assumed to accept Glance image uuids as valid values.
|
||||
|
||||
2. Property names ending in _port are assumed to only accept
|
||||
postive integer values
|
||||
|
||||
3. Property names ending in _address are assumed to only accept
|
||||
valid IPv4 and IPv6 addresses; and hostnames
|
||||
*/
|
||||
|
||||
/**
|
||||
* @description Construct a new driver property
|
||||
*
|
||||
* @class DriverProperty
|
||||
* @param {string} name - Name of property
|
||||
* @param {string} desc - Description of property
|
||||
* @param {object} propertySet - Set of properties to which this one belongs
|
||||
*
|
||||
* @property {string} defaultValue - Default value of the property
|
||||
* @property {string[]} selectOptions - If the property is limited to a
|
||||
* set of enumerated values then selectOptions will be an array of those
|
||||
* values, otherwise null
|
||||
* @property {boolean} required - Boolean value indicating whether a value
|
||||
* must be supplied for this property if it is active
|
||||
* @property {PostfixExpr} isActiveExpr - Null if this property is always
|
||||
* active; otherwise, a boolean expression that when evaluated will
|
||||
* return whether this variable is active. A property is considered
|
||||
* active if its role is not eliminated by the values of other
|
||||
* properties in the property-set.
|
||||
* @property {string} inputValue - User assigned value for this property
|
||||
* @property {regexp} validValueRegex - Regular expression used to
|
||||
* determine whether an input value is valid.
|
||||
* @returns {object} Driver property
|
||||
*/
|
||||
function DriverProperty(name, desc, propertySet) {
|
||||
this.name = name;
|
||||
this.desc = desc;
|
||||
this.propertySet = propertySet;
|
||||
|
||||
// Determine whether this property should be presented as a selection
|
||||
this.selectOptions = this._analyzeSelectOptions();
|
||||
|
||||
this.required = null; // Initialize to unknown
|
||||
// Expression to be evaluated to determine whether property is active.
|
||||
// By default the property is considered active.
|
||||
this.isActiveExpr = null;
|
||||
var result = this._analyzeRequiredOnlyDependencies();
|
||||
if (result) {
|
||||
this.required = result[0];
|
||||
this.isActiveExpr = result[1];
|
||||
}
|
||||
if (!this.isActiveExpr) {
|
||||
result = this._analyzeOneOfDependencies();
|
||||
if (result) {
|
||||
this.required = result[0];
|
||||
this.isActiveExpr = result[1];
|
||||
}
|
||||
}
|
||||
if (this.required === null) {
|
||||
this.required = desc.endsWith(REQUIRED);
|
||||
}
|
||||
|
||||
this.defaultValue = this._getDefaultValue();
|
||||
this.inputValue = this.defaultValue;
|
||||
|
||||
// Infer that property is a boolean that can be represented as a
|
||||
// True/False selection
|
||||
if (this.selectOptions === null &&
|
||||
(this.defaultValue === "True" || this.defaultValue === "False")) {
|
||||
this.selectOptions = ["True", "False"];
|
||||
}
|
||||
|
||||
this.validValueRegex = _determineValidValueRegex(this.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Return a regular expression that can be used to
|
||||
* validate the value of a specified property
|
||||
*
|
||||
* @param {string} propertyName - Name of property
|
||||
* @return {regexp} Regular expression object or undefined
|
||||
*/
|
||||
function _determineValidValueRegex(propertyName) {
|
||||
var regex;
|
||||
if (propertyName.endsWith("_port")) {
|
||||
regex = VALID_PORT_REGEX;
|
||||
} else if (propertyName.endsWith("_address")) {
|
||||
regex = VALID_ADDRESS_HOSTNAME_REGEX;
|
||||
} else if (propertyName === "deploy_kernel") {
|
||||
regex = VALID_IMAGE_REGEX;
|
||||
} else if (propertyName === "deploy_ramdisk") {
|
||||
regex = VALID_IMAGE_REGEX;
|
||||
}
|
||||
|
||||
return regex;
|
||||
}
|
||||
|
||||
DriverProperty.prototype.isActive = function() {
|
||||
if (!this.isActiveExpr) {
|
||||
return true;
|
||||
}
|
||||
var ret = this.isActiveExpr.evaluate(this.propertySet);
|
||||
return ret[0] === PostfixExpr.status.OK &&
|
||||
typeof ret[1] === "boolean" ? ret[1] : true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get a regular expression object that can be used to
|
||||
* determine whether a value is valid for this property
|
||||
*
|
||||
* @return {regexp} Regular expression object or undefined
|
||||
*/
|
||||
DriverProperty.prototype.getValidValueRegex = function() {
|
||||
return this.validValueRegex;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Must a value be provided for this property
|
||||
*
|
||||
* @return {boolean} True if a value must be provided for this property
|
||||
*/
|
||||
DriverProperty.prototype.isRequired = function() {
|
||||
return this.required;
|
||||
};
|
||||
|
||||
DriverProperty.prototype._analyzeSelectOptions = function() {
|
||||
var match = this.desc.match(SELECT_OPTIONS_REGEX);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var matches = match[1].substring(0, match[1].length - 1).split(", ");
|
||||
var options = [];
|
||||
angular.forEach(matches, function(match) {
|
||||
options.push(trimQuotes(match));
|
||||
});
|
||||
return options;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the list of select options for this property
|
||||
*
|
||||
* @return {string[]} null if this property is not selectable; else,
|
||||
* an array of selectable options
|
||||
*/
|
||||
DriverProperty.prototype.getSelectOptions = function() {
|
||||
return this.selectOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Remove leading/trailing double-quotes from a string
|
||||
*
|
||||
* @param {string} str - String to be trimmed
|
||||
* @return {string} trim'd string
|
||||
*/
|
||||
function trimQuotes(str) {
|
||||
return str.charAt(0) === '"'
|
||||
? str.substring(1, str.length - 1) : str;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Get the default value of this property
|
||||
*
|
||||
* @return {string} Default value of this property
|
||||
*/
|
||||
DriverProperty.prototype._getDefaultValue = function() {
|
||||
var value;
|
||||
for (var i = 0; i < DEFAULT_REGEX_LIST.length; i++) {
|
||||
var match = this.desc.match(DEFAULT_REGEX_LIST[i]);
|
||||
if (match) {
|
||||
value = trimQuotes(match[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$log.debug("_getDefaultValue | " + this.desc + " | " + value);
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the input value of this property
|
||||
*
|
||||
* @return {string} the input value of this property
|
||||
*/
|
||||
DriverProperty.prototype.getInputValue = function() {
|
||||
return this.inputValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the default value of this property
|
||||
*
|
||||
* @return {string} the default value of this property
|
||||
*/
|
||||
DriverProperty.prototype.getDefaultValue = function() {
|
||||
return this.defaultValue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the description of this property
|
||||
*
|
||||
* @return {string} Description of this property
|
||||
*/
|
||||
DriverProperty.prototype.getDescription = function() {
|
||||
return this.desc;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Use the property description to build an expression
|
||||
* that will evaluate to a boolean result indicating whether the
|
||||
* property is active
|
||||
*
|
||||
* @return {array} null if this property is not dependent on any others;
|
||||
* otherwise,
|
||||
* [0] boolean indicating whether if active a value must be
|
||||
* supplied for this property.
|
||||
* [1] an expression that when evaluated will return a boolean
|
||||
* result indicating whether this property is active
|
||||
*/
|
||||
DriverProperty.prototype._analyzeRequiredOnlyDependencies = function() {
|
||||
var re = /(Required|Used) only if ([^ ]+) is set to /g;
|
||||
var match = re.exec(this.desc);
|
||||
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build logical expression to describe under what conditions this
|
||||
// property is active
|
||||
var expr = new PostfixExpr();
|
||||
var numAdds = 0;
|
||||
|
||||
var i = NOT_INSIDE_MATCH;
|
||||
var j = re.lastIndex;
|
||||
while (j < this.desc.length) {
|
||||
if (i === NOT_INSIDE_MATCH && this.desc.charAt(j) === ".") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.desc.charAt(j) === '"') {
|
||||
if (i === NOT_INSIDE_MATCH) {
|
||||
i = j + 1;
|
||||
} else {
|
||||
expr.addProperty(match[2]);
|
||||
expr.addValue(this.desc.substring(i, j));
|
||||
expr.addOperator(PostfixExpr.op.EQ);
|
||||
numAdds++;
|
||||
if (numAdds > 1) {
|
||||
expr.addOperator(PostfixExpr.op.OR);
|
||||
}
|
||||
i = NOT_INSIDE_MATCH;
|
||||
}
|
||||
}
|
||||
j++;
|
||||
}
|
||||
$log.debug("_analyzeRequiredOnlyDependencies | " +
|
||||
this.desc + " | " +
|
||||
match[2] + ", " +
|
||||
JSON.stringify(expr));
|
||||
return [match[1] === "Required", expr];
|
||||
};
|
||||
|
||||
DriverProperty.prototype._analyzeOneOfDependencies = function() {
|
||||
var match = this.desc.match(ONE_OF_REGEX);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Build logical expression to describe under what conditions this
|
||||
// property is active
|
||||
var expr = new PostfixExpr();
|
||||
|
||||
var parts = match[1].split(", or ");
|
||||
expr.addProperty(parts[1]);
|
||||
expr.addValue(undefined);
|
||||
expr.addOperator(PostfixExpr.op.EQ);
|
||||
|
||||
parts = parts[0].split(", ");
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
expr.addProperty(parts[i]);
|
||||
expr.addValue(undefined);
|
||||
expr.addOperator(PostfixExpr.op.EQ);
|
||||
expr.addOperator(PostfixExpr.op.AND);
|
||||
}
|
||||
$log.debug("_analyzeOneOfDependencies | " +
|
||||
this.desc + " | " +
|
||||
JSON.stringify(match) + ", " +
|
||||
JSON.stringify(expr));
|
||||
return [true, expr];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get the names of the driver-properties whose values
|
||||
* determine whether this property is active
|
||||
*
|
||||
* @return {object} Object the properties of which are names of
|
||||
* activating driver-properties or null
|
||||
*/
|
||||
DriverProperty.prototype.getActivators = function() {
|
||||
return this.isActiveExpr ? this.isActiveExpr.getProperties() : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* PostFixExpr is a class primarily developed to support the
|
||||
* evaluation of boolean expressions that determine whether a
|
||||
* particular property is active.
|
||||
*
|
||||
* The expression is stored as a postfix sequence of operands and
|
||||
* operators. Operands are currently limited to the literal values
|
||||
* and the values of properties in a specified set. Currently
|
||||
* supported operands are ==, or, and.
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
function PostfixExpr() {
|
||||
this.elem = [];
|
||||
}
|
||||
|
||||
PostfixExpr.op = {
|
||||
EQ: "==",
|
||||
AND: "and",
|
||||
OR: "or"
|
||||
};
|
||||
|
||||
PostfixExpr.UNDEFINED = undefined;
|
||||
|
||||
PostfixExpr.status = {
|
||||
OK: 0,
|
||||
ERROR: 1,
|
||||
BAD_ARG: 2,
|
||||
UNKNOWN_OP: 3,
|
||||
MALFORMED: 4
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add a property to the expression
|
||||
*
|
||||
* @param {string} propertyName - Property name
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
PostfixExpr.prototype.addProperty = function(propertyName) {
|
||||
this.elem.push({name: propertyName});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add a value to the expression
|
||||
*
|
||||
* @param {object} value - value
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
PostfixExpr.prototype.addValue = function(value) {
|
||||
this.elem.push({value: value});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add an operator to the expression
|
||||
*
|
||||
* @param {PostfixExpr.op} opId - operator
|
||||
*
|
||||
* @return {void}
|
||||
*/
|
||||
PostfixExpr.prototype.addOperator = function(opId) {
|
||||
this.elem.push({op: opId});
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Get a list of property names referenced by this
|
||||
* expression
|
||||
*
|
||||
* @return {object} An object each property of which corresponds to
|
||||
* a property in the expression
|
||||
*/
|
||||
PostfixExpr.prototype.getProperties = function() {
|
||||
var properties = {};
|
||||
angular.forEach(this.elem, function(elem) {
|
||||
if (angular.isDefined(elem.name)) {
|
||||
properties[elem.name] = true;
|
||||
}
|
||||
});
|
||||
return properties;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Evaluate a boolean binary operation
|
||||
*
|
||||
* @param {array} valStack - Stack of values to operate on
|
||||
* @param {string} opId - operator id
|
||||
*
|
||||
* @return {integer} Return code
|
||||
*/
|
||||
function _evaluateBoolBinaryOp(valStack, opId) {
|
||||
var retCode = PostfixExpr.status.OK;
|
||||
var val1 = valStack.pop();
|
||||
var val2 = valStack.pop();
|
||||
if (typeof val1 === "boolean" &&
|
||||
typeof val2 === "boolean") {
|
||||
switch (opId) {
|
||||
case PostfixExpr.op.AND:
|
||||
valStack.push(val1 && val2);
|
||||
break;
|
||||
case PostfixExpr.op.OR:
|
||||
valStack.push(val1 || val2);
|
||||
break;
|
||||
default:
|
||||
retCode = PostfixExpr.status.UNKNOWN_OP;
|
||||
}
|
||||
} else {
|
||||
retCode = PostfixExpr.status.BAD_ARG;
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Evaluate the experssion using property values from
|
||||
* a specified set
|
||||
*
|
||||
* @param {object} propertySet - Dictionary of DriverProperty instances
|
||||
*
|
||||
* @return {array} Return code and Value of the expression
|
||||
*/
|
||||
PostfixExpr.prototype.evaluate = function(propertySet) {
|
||||
var resultStack = [];
|
||||
for (var i = 0, len = this.elem.length; i < len; i++) {
|
||||
var elem = this.elem[i];
|
||||
if (elem.hasOwnProperty("name")) {
|
||||
resultStack.push(propertySet[elem.name].getInputValue());
|
||||
} else if (elem.hasOwnProperty("value")) {
|
||||
resultStack.push(elem.value);
|
||||
} else if (elem.hasOwnProperty("op")) {
|
||||
if (elem.op === PostfixExpr.op.EQ) {
|
||||
var val1 = resultStack.pop();
|
||||
var val2 = resultStack.pop();
|
||||
resultStack.push(val1 === val2);
|
||||
} else {
|
||||
var ret = _evaluateBoolBinaryOp(resultStack, elem.op);
|
||||
if (ret !== PostfixExpr.status.OK) {
|
||||
return [ret, PostfixExpr.UNDEFINED];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return [PostfixExpr.status.UNKNOWN_ELEMENT, PostfixExpr.UNDEFINED];
|
||||
}
|
||||
}
|
||||
return resultStack.length === 1
|
||||
? [PostfixExpr.status.OK, resultStack.pop()]
|
||||
: [PostfixExpr.status.MALFORMED, PostfixExpr.UNDEFINED];
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Class for representing and manipulating undirected
|
||||
* graphs
|
||||
*
|
||||
* @property {object} vertices - Associative array of vertex objects
|
||||
* indexed by property name
|
||||
* @return {object} Graph
|
||||
*/
|
||||
function Graph() {
|
||||
this.vertices = {};
|
||||
}
|
||||
|
||||
Graph.prototype.getVertex = function(vertexName) {
|
||||
var vertex = null;
|
||||
if (this.vertices.hasOwnProperty(vertexName)) {
|
||||
vertex = this.vertices[vertexName];
|
||||
}
|
||||
return vertex;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add a vertex to this graph
|
||||
*
|
||||
* @param {string} name - Vertex name
|
||||
* @param {object} data - Vertex data
|
||||
* @returns {object} - Newly created vertex
|
||||
*/
|
||||
Graph.prototype.addVertex = function(name, data) {
|
||||
var vertex = {name: name, data: data, adjacents: []};
|
||||
this.vertices[name] = vertex;
|
||||
return vertex;
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Add an undirected edge between two vertices
|
||||
*
|
||||
* @param {string} vertexName1 - Name of first vertex
|
||||
* @param {string} vertexName2 - Name of second vertex
|
||||
* @returns {void}
|
||||
*/
|
||||
Graph.prototype.addEdge = function(vertexName1, vertexName2) {
|
||||
this.vertices[vertexName1].adjacents.push(vertexName2);
|
||||
this.vertices[vertexName2].adjacents.push(vertexName1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Depth-first-search graph traversal utility function
|
||||
*
|
||||
* @param {object} vertex - Root vertex from which traveral will begin.
|
||||
* It is assumed that this vertex has not alreday been visited as part
|
||||
* of this traversal.
|
||||
* @param {object} visited - Associative array. Each named property
|
||||
* corresponds to a vertex with the same name, and has boolean value
|
||||
* indicating whether the vertex has been alreday visited.
|
||||
* @param {object[]} component - Array of vertices that define a strongly
|
||||
* connected component.
|
||||
* @returns {void}
|
||||
*/
|
||||
Graph.prototype._dfsTraverse = function(vertex, visited, component) {
|
||||
var graph = this;
|
||||
visited[vertex.name] = true;
|
||||
component.push(vertex);
|
||||
|
||||
/* eslint-disable no-unused-vars */
|
||||
angular.forEach(vertex.adjacents, function(vertexName) {
|
||||
if (!visited[vertexName]) {
|
||||
graph._dfsTraverse(graph.vertices[vertexName], visited, component);
|
||||
}
|
||||
});
|
||||
/* eslint-enable no-unused-vars */
|
||||
};
|
||||
|
||||
/**
|
||||
* @description Perform a depth-first-search on a specified graph to
|
||||
* find strongly connected components. A user provided function will
|
||||
* be called to process each component.
|
||||
*
|
||||
* @param {function} componentFunc - Function called on each strongly
|
||||
* connected component. Accepts aruments: array of vertex objects, and
|
||||
* user-provided extra data that can be used in processing the component.
|
||||
* @param {object} extra - Extra data that is passed into the component
|
||||
* processing function.
|
||||
* @returns {void}
|
||||
*/
|
||||
Graph.prototype.dfs = function(componentFunc, extra) {
|
||||
var graph = this;
|
||||
var visited = {};
|
||||
angular.forEach(
|
||||
graph.vertices,
|
||||
function(unused, name) {
|
||||
visited[name] = false;
|
||||
});
|
||||
|
||||
angular.forEach(this.vertices, function(vertex, vertexName) {
|
||||
if (!visited[vertexName]) {
|
||||
var component = [];
|
||||
graph._dfsTraverse(vertex, visited, component);
|
||||
componentFunc(component, extra);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return service;
|
||||
}
|
||||
})();
|
||||
|
@ -38,6 +38,7 @@
|
||||
return {
|
||||
ENROLL_NODE_SUCCESS:'horizon.dashboard.admin.ironic.ENROLL_NODE_SUCCESS',
|
||||
DELETE_NODE_SUCCESS:'horizon.dashboard.admin.ironic.DELETE_NODE_SUCCESS',
|
||||
EDIT_NODE_SUCCESS:'horizon.dashboard.admin.ironic.EDIT_NODE_SUCCESS',
|
||||
CREATE_PORT_SUCCESS:'horizon.dashboard.admin.ironic.CREATE_PORT_SUCCESS',
|
||||
DELETE_PORT_SUCCESS:'horizon.dashboard.admin.ironic.DELETE_PORT_SUCCESS'
|
||||
};
|
||||
|
@ -33,17 +33,17 @@
|
||||
active: 'active',
|
||||
manageable: 'manage'
|
||||
},
|
||||
adopt_failed: {
|
||||
'adopt failed': {
|
||||
manageable: 'manage',
|
||||
active: 'adopt'
|
||||
},
|
||||
inspect_failed: {
|
||||
'inspect failed': {
|
||||
manageable: 'manage'
|
||||
},
|
||||
clean_failed: {
|
||||
'clean failed': {
|
||||
manageable: 'manage'
|
||||
},
|
||||
deploy_failed: {
|
||||
'deploy failed': {
|
||||
active: 'active',
|
||||
manageable: 'deleted'
|
||||
},
|
||||
@ -85,7 +85,8 @@
|
||||
powerOnNode: powerOnNode,
|
||||
putNodeInMaintenanceMode: putNodeInMaintenanceMode,
|
||||
removeNodeFromMaintenanceMode: removeNodeFromMaintenanceMode,
|
||||
setNodeProvisionState: setNodeProvisionState
|
||||
setNodeProvisionState: setNodeProvisionState,
|
||||
updateNode: updateNode
|
||||
};
|
||||
|
||||
return service;
|
||||
@ -310,6 +311,32 @@
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Update the definition of a specified node.
|
||||
*
|
||||
* http://docs.openstack.org/developer/ironic/webapi/v1.html#
|
||||
* patch--v1-nodes-(node_ident)
|
||||
*
|
||||
* @param {string} uuid – UUID of a node.
|
||||
* @param {object[]} patch – Sequence of update operations
|
||||
* @return {promise} Promise
|
||||
*/
|
||||
function updateNode(uuid, patch) {
|
||||
var data = {
|
||||
patch: patch
|
||||
};
|
||||
return apiService.patch('/api/ironic/nodes/' + uuid, data)
|
||||
.success(function() {
|
||||
var msg = gettext(
|
||||
'Successfully updated node %s');
|
||||
toastService.add('success', interpolate(msg, [uuid], false));
|
||||
})
|
||||
.error(function(reason) {
|
||||
var msg = gettext('Unable to update node %s: %s');
|
||||
toastService.add('error', interpolate(msg, [uuid, reason], false));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve the list of Ironic drivers
|
||||
*
|
||||
|
@ -31,6 +31,7 @@
|
||||
'horizon.dashboard.admin.ironic.events',
|
||||
'horizon.dashboard.admin.ironic.actions',
|
||||
'horizon.dashboard.admin.basePath',
|
||||
'horizon.dashboard.admin.ironic.edit-node.service',
|
||||
'horizon.dashboard.admin.ironic.maintenance.service',
|
||||
'horizon.dashboard.admin.ironic.validUuidPattern'
|
||||
];
|
||||
@ -43,6 +44,7 @@
|
||||
ironicEvents,
|
||||
actions,
|
||||
basePath,
|
||||
editNodeService,
|
||||
maintenanceService,
|
||||
validUuidPattern) {
|
||||
var ctrl = this;
|
||||
@ -72,11 +74,18 @@
|
||||
ctrl.getVifPortId = getVifPortId;
|
||||
ctrl.putNodeInMaintenanceMode = putNodeInMaintenanceMode;
|
||||
ctrl.removeNodeFromMaintenanceMode = removeNodeFromMaintenanceMode;
|
||||
ctrl.editNode = editNode;
|
||||
ctrl.createPort = createPort;
|
||||
ctrl.deletePort = deletePort;
|
||||
ctrl.deletePorts = deletePorts;
|
||||
ctrl.refresh = refresh;
|
||||
|
||||
var editNodeHandler =
|
||||
$rootScope.$on(ironicEvents.EDIT_NODE_SUCCESS,
|
||||
function() {
|
||||
init();
|
||||
});
|
||||
|
||||
var createPortHandler =
|
||||
$rootScope.$on(ironicEvents.CREATE_PORT_SUCCESS,
|
||||
function() {
|
||||
@ -91,6 +100,7 @@
|
||||
});
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
editNodeHandler();
|
||||
createPortHandler();
|
||||
deletePortHandler();
|
||||
});
|
||||
@ -190,6 +200,10 @@
|
||||
maintenanceService.removeNodeFromMaintenanceMode(ctrl.node);
|
||||
}
|
||||
|
||||
function editNode() {
|
||||
editNodeService.modal(ctrl.node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name horizon.dashboard.admin.ironic.NodeDetailsController.createPort
|
||||
* @description Initiate creation of a newtwork port for the current
|
||||
|
@ -44,6 +44,10 @@
|
||||
targetState) === null">
|
||||
{$ ('Move to ' | translate) + targetState $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="ctrl.editNode">
|
||||
{$ 'Edit' | translate $}
|
||||
</action>
|
||||
</menu>
|
||||
</action-list>
|
||||
</div>
|
||||
|
@ -160,15 +160,6 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Capabilities -->
|
||||
<div class="col-md-6 status detail">
|
||||
<h4 translate>Capabilities</h4>
|
||||
<hr class="header_rule">
|
||||
<dl class="dl-horizontal">
|
||||
<dd>{$ ctrl.node.capabilities $}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<!-- Instance Info -->
|
||||
<div class="col-md-6 status detail">
|
||||
<h4 translate>Instance Info</h4>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<hr class="header_rule">
|
||||
<dl class="dl-horizontal">
|
||||
<dt translate>Name</dt>
|
||||
<dd>{$ ctrl.node.name $}</dd>
|
||||
<dd>{$ ctrl.node.name | noValue $}</dd>
|
||||
<dt translate>Maintenance</dt>
|
||||
<dd>{$ ctrl.node.maintenance | yesno $}</dd>
|
||||
<dt translate>Maintenance Reason</dt>
|
||||
@ -34,7 +34,7 @@
|
||||
</a>
|
||||
</dd>
|
||||
<dt translate>Power State</dt>
|
||||
<dd ng-class="{'running': ctrl.node.target_power_state}">{$ ctrl.node.power_state $}</dd>
|
||||
<dd ng-class="{'running': ctrl.node.target_power_state}">{$ ctrl.node.power_state | noValue $}</dd>
|
||||
<dt translate>Target Power State</dt>
|
||||
<dd>{$ ctrl.node.target_power_state | noValue $}</dd>
|
||||
<dt translate>Provision State</dt>
|
||||
|
@ -31,7 +31,8 @@
|
||||
'horizon.dashboard.admin.ironic.actions',
|
||||
'horizon.dashboard.admin.basePath',
|
||||
'horizon.dashboard.admin.ironic.maintenance.service',
|
||||
'horizon.dashboard.admin.ironic.enroll-node.service'
|
||||
'horizon.dashboard.admin.ironic.enroll-node.service',
|
||||
'horizon.dashboard.admin.ironic.edit-node.service'
|
||||
];
|
||||
|
||||
function IronicNodeListController($scope,
|
||||
@ -43,7 +44,8 @@
|
||||
actions,
|
||||
basePath,
|
||||
maintenanceService,
|
||||
enrollNodeService) {
|
||||
enrollNodeService,
|
||||
editNodeService) {
|
||||
var ctrl = this;
|
||||
|
||||
ctrl.nodes = [];
|
||||
@ -56,6 +58,7 @@
|
||||
ctrl.removeNodeFromMaintenanceMode = removeNodeFromMaintenanceMode;
|
||||
ctrl.removeNodesFromMaintenanceMode = removeNodesFromMaintenanceMode;
|
||||
ctrl.enrollNode = enrollNode;
|
||||
ctrl.editNode = editNode;
|
||||
ctrl.refresh = refresh;
|
||||
|
||||
/**
|
||||
@ -107,6 +110,11 @@
|
||||
init();
|
||||
});
|
||||
|
||||
var editNodeHandler = $rootScope.$on(ironicEvents.EDIT_NODE_SUCCESS,
|
||||
function() {
|
||||
init();
|
||||
});
|
||||
|
||||
var createPortHandler = $rootScope.$on(ironicEvents.CREATE_PORT_SUCCESS,
|
||||
function() {
|
||||
init();
|
||||
@ -120,6 +128,7 @@
|
||||
$scope.$on('destroy', function() {
|
||||
enrollNodeHandler();
|
||||
deleteNodeHandler();
|
||||
editNodeHandler();
|
||||
createPortHandler();
|
||||
deletePortHandler();
|
||||
});
|
||||
@ -183,6 +192,10 @@
|
||||
enrollNodeService.modal();
|
||||
}
|
||||
|
||||
function editNode(node) {
|
||||
editNodeService.modal(node);
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
init();
|
||||
}
|
||||
|
@ -185,6 +185,12 @@
|
||||
targetState) === null">
|
||||
{$ ('Move to ' | translate) + targetState $}
|
||||
</action>
|
||||
<action button-type="menu-item"
|
||||
callback="table.editNode"
|
||||
item="node">
|
||||
{$ 'Edit' | translate $}
|
||||
</action>
|
||||
</menu>
|
||||
</action-list>
|
||||
</td>
|
||||
</tr>
|
||||
|
Loading…
Reference in New Issue
Block a user