Create template without keypair and fix REST data

This patch allows cluster template creation without keypair,
and check keypair requirements in cluster creation.
Also, fix REST data structure.

Change-Id: I99cdd63be833a24946ee56783e0b6619992af4bc
Closes-Bug: #1645754
This commit is contained in:
Shu Muto 2016-12-07 11:32:45 +09:00
parent 63accc7987
commit 2e21d08d68
14 changed files with 63 additions and 33 deletions

View File

@ -75,6 +75,9 @@
.setProperty('coe', {
label: gettext('COE')
})
.setProperty('keypair_id', {
label: gettext('Keypair')
})
.setProperty('network_driver', {
label: gettext('Network Driver')
})
@ -95,6 +98,11 @@
id: 'coe',
priority: 1
})
.append({
id: 'keypair_id',
priority: 1,
filters: ['noValue']
})
.append({
id: 'network_driver',
priority: 2

View File

@ -54,22 +54,20 @@
}
function onGetImages(response) {
angular.forEach(response.items, function(item) {
angular.forEach(response.data.items, function(item) {
ctrl.images.push({id: item.name, name: item.name});
});
}
function onGetFlavors(response) {
angular.forEach(response.items, function(item) {
angular.forEach(response.data.items, function(item) {
ctrl.nflavors.push({id: item.name, name: item.name});
});
angular.forEach(response.items, function(item) {
ctrl.mflavors.push({id: item.name, name: item.name});
});
}
function onGetKeypairs(response) {
angular.forEach(response.items, function(item) {
angular.forEach(response.data.items, function(item) {
ctrl.keypairs.push({id: item.keypair.name, name: item.keypair.name});
});
}

View File

@ -29,9 +29,9 @@
nova = $injector.get('horizon.app.core.openstack-service-api.nova');
deferred = $q.defer();
deferred.resolve({items:{1:{name:1},2:{name:2}}});
deferred.resolve({data:{items:{1:{name:1},2:{name:2}}}});
KeyDeferred = $q.defer();
KeyDeferred.resolve({items:{1:{keypair:{name:1}},2:{keypair:{name:2}}}});
KeyDeferred.resolve({data:{items:{1:{keypair:{name:1}},2:{keypair:{name:2}}}}});
spyOn(glance, 'getImages').and.returnValue(deferred.promise);
spyOn(nova, 'getFlavors').and.returnValue(deferred.promise);

View File

@ -14,12 +14,9 @@
</div>
<div class="col-xs-6">
<div class="form-group">
<label class="control-label" for="cluster-template-keypair-id">
<translate>Keypair</translate>
<span class="hz-icon-required fa fa-asterisk"></span>
</label>
<label class="control-label" for="cluster-template-keypair-id" translate>Keypair</label>
<select name="cluster-template-keypair-id" type="text" class="form-control" id="cluster-template-keypair-id"
ng-model="model.newClusterTemplateSpec.keypair_id" ng-required="true"
ng-model="model.newClusterTemplateSpec.keypair_id"
ng-options="keypair.id as keypair.name for keypair in ctrl.keypairs">
</select>
</div>

View File

@ -39,7 +39,7 @@
}
function onGetImages(images) {
angular.forEach(images.items, function(image) {
angular.forEach(images.data.items, function(image) {
if (image.name === ctrl.cluster_template.image_id) {
ctrl.image_uuid = image.id;
}

View File

@ -26,7 +26,7 @@
beforeEach(inject(function($controller, $q, $injector) {
glance = $injector.get('horizon.app.core.openstack-service-api.glance');
deferred = $q.defer();
deferred.resolve({data: {image_id: 1},items:{1:{name:1,id:1},2:{name:2,id:2}}});
deferred.resolve({data: {image_id: 1, items: {1: {name: 1, id: 1},2: {name: 2, id: 2}}}});
spyOn(glance, 'getImages').and.returnValue(deferred.promise);
ctrl = $controller('ClusterTemplateOverviewController',
{

View File

@ -24,8 +24,9 @@
<dl class="dl-horizontal">
<dt translate>Image ID</dt>
<dd><a href="project/images/{$ ctrl.image_uuid $}/" target="_self">{$ ctrl.cluster_template.image_id $}</a></dd>
<dt translate>Keypair ID</dt>
<dd><a href="project/access_and_security/keypairs/{$ ctrl.cluster_template.keypair_id $}/" target="_self">{$ ctrl.cluster_template.keypair_id $}</a></dd>
<dt translate>Keypair</dt>
<dd ng-if="ctrl.cluster_template.keypair_id!==null"><a href="project/access_and_security/keypairs/{$ ctrl.cluster_template.keypair_id $}/" target="_self">{$ ctrl.cluster_template.keypair_id $}</a></dd>
<dd ng-if="ctrl.cluster_template.keypair_id===null">-</dd>
<dt translate>Flavor ID</dt>
<dd>{$ ctrl.cluster_template.flavor_id $}</dd>
<dt translate>Master Flavor ID</dt>

View File

@ -28,6 +28,7 @@
function ClusterModel(magnum) {
var model = {
newClusterSpec: {},
templateKeypair: null,
// API methods
init: init,

View File

@ -49,21 +49,22 @@
registry_enabled: "",
tls_disabled: "",
apiserver_port: "",
keypair: ""
keypair_id: ""
};
$scope.changeClusterTemplate = function() {
angular.forEach(ctrl.cluster_templates, function(model) {
if ($scope.model.newClusterSpec.cluster_template_id === model.id) {
$scope.cluster_template_detail.name = model.name;
$scope.cluster_template_detail.id = model.id;
$scope.cluster_template_detail.coe = model.coe;
$scope.cluster_template_detail.image_id = model.image_id;
$scope.cluster_template_detail.public = model.public;
$scope.cluster_template_detail.registry_enabled = model.registry_enabled;
$scope.cluster_template_detail.tls_disabled = model.tls_disabled;
$scope.cluster_template_detail.apiserver_port = model.apiserver_port;
$scope.cluster_template_detail.keypair = model.keypair;
angular.forEach(ctrl.cluster_templates, function(template) {
if ($scope.model.newClusterSpec.cluster_template_id === template.id) {
$scope.cluster_template_detail.name = template.name;
$scope.cluster_template_detail.id = template.id;
$scope.cluster_template_detail.coe = template.coe;
$scope.cluster_template_detail.image_id = template.image_id;
$scope.cluster_template_detail.public = template.public;
$scope.cluster_template_detail.registry_enabled = template.registry_enabled;
$scope.cluster_template_detail.tls_disabled = template.tls_disabled;
$scope.cluster_template_detail.apiserver_port = template.apiserver_port;
$scope.cluster_template_detail.keypair = template.keypair_id;
$scope.model.templateKeypair = template.keypair_id;
}
});
};

View File

@ -35,6 +35,8 @@
<dd>{$ cluster_template_detail.coe $}</dd>
<dt translate>Image ID</dt>
<dd>{$ cluster_template_detail.image_id $}</dd>
<dt translate>Keypair</dt>
<dd>{$ cluster_template_detail.keypair|noValue $}</dd>
<dt translate>Public</dt>
<dd>{$ cluster_template_detail.public $}</dd>
<dt translate>Registry Enabled</dt>
@ -42,7 +44,7 @@
<dt translate>TLS Disabled</dt>
<dd>{$ cluster_template_detail.tls_disabled $}</dd>
<dt translate>API Server Port</dt>
<dd>{$ cluster_template_detail.apiserver_port $}</dd>
<dd>{$ cluster_template_detail.apiserver_port|noValue $}</dd>
</dl>
</div>
</div>

View File

@ -50,6 +50,17 @@
ctrl.keypairs.push({id: item.keypair.name, name: item.keypair.name});
});
}
}
function getKeypair() {
return $scope.model.templateKeypair;
}
function toggleKeypairRequirement(newValue) {
ctrl.templateKeypair = newValue;
}
var keypairWatcher = $scope.$watch(getKeypair, toggleKeypairRequirement, true);
$scope.$on('$destroy', function() {
keypairWatcher();
});
}
})();

View File

@ -1 +1,9 @@
<p translate>Specify conditions for cluster creation.</p>
<dl>
<dt>Keypair</dt>
<dd>
When the selected cluster template contains keypair, user can either provide a new keypair
for the cluster or inherit one from the cluster template. When the selected cluster template
has no keypair attached, user has to provide a keypair for the cluster.
</dd>
</dl>

View File

@ -14,9 +14,12 @@
placeholder="{$ 'The timeout for cluster creation in minutes. Set to 0 for no timeout. The default is no timeout.'|translate $}">
</div>
<div class="form-group">
<label class="control-label" for="cluster-keypair" translate>Keypair</label>
<label class="control-label" for="cluster-keypair">
<translate>Keypair</translate>
<span class="hz-icon-required fa fa-asterisk" ng-if="ctrl.templateKeypair === null"></span>
</label>
<select name="cluster-keypair" type="text" class="form-control" id="cluster-keypair"
ng-model="model.newClusterSpec.keypair" ng-required="false"
ng-model="model.newClusterSpec.keypair" ng-required="ctrl.templateKeypair === null"
ng-options="keypair.id as keypair.name for keypair in ctrl.keypairs">
</select>
</div>

View File

@ -39,7 +39,7 @@
}
function onGetClusterTemplate(clusterTemplate) {
ctrl.cluster_template = clusterTemplate;
ctrl.cluster_template = clusterTemplate.data;
}
}
})();