fix bug in launching host templates

This commit is contained in:
Westly Wright 2018-01-05 15:56:08 -07:00
parent 9d30f56a8e
commit 5cb408da65
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
1 changed files with 45 additions and 39 deletions

View File

@ -9,7 +9,7 @@ import Util from 'ui/utils/util';
import NewOrEdit from 'shared/mixins/new-or-edit'; import NewOrEdit from 'shared/mixins/new-or-edit';
import ManageLabels from 'shared/mixins/manage-labels'; import ManageLabels from 'shared/mixins/manage-labels';
import { addAction } from 'ui/utils/add-view-action'; import { addAction } from 'ui/utils/add-view-action';
import { get } from '@ember/object'; import { get, set, setProperties } from '@ember/object';
export default Mixin.create(NewOrEdit, ManageLabels, { export default Mixin.create(NewOrEdit, ManageLabels, {
intl: service(), intl: service(),
@ -47,7 +47,7 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
}, },
passConfigBack(cb) { passConfigBack(cb) {
this.sendAction('completed', this.get('model')); this.sendAction('completed', get(this, 'model'));
cb(true); cb(true);
}, },
@ -57,20 +57,24 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
out[row.key] = row.value; out[row.key] = row.value;
}); });
this.set('labelResource.labels', out); set(this, 'labelResource.labels', out);
} }
}, },
init() { init() {
this._super(...arguments); this._super(...arguments);
this.set('error', null); setProperties(this, {
this.set('editing', false); error: null,
editing: false
});
if (this.get('clonedModel')) { if (get(this, 'clonedModel')) {
this.set('model', this.get('clonedModel')); setProperties(this, {
this.set('prefix', ''); model: get(this, 'clonedModel'),
} else if (typeof this.get('bootstrap') === 'function') { prefix: '',
});
} else if (typeof get(this, 'bootstrap') === 'function') {
this.bootstrap(); this.bootstrap();
} }
@ -78,12 +82,12 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
let locationA = ['region']; let locationA = ['region'];
let locationB = ['zone','availabilityZone','location','datacenter']; let locationB = ['zone','availabilityZone','location','datacenter'];
let size = ['instanceType','offering','flavor','size']; let size = ['instanceType','offering','flavor','size'];
this.set('displayLocation', computed( set(this, 'displayLocation', computed(
this.driver+'.{'+locationA.join(',')+'}', this.driver+'.{'+locationA.join(',')+'}',
this.driver+'.{'+locationB.join(',')+'}', this.driver+'.{'+locationB.join(',')+'}',
function() { function() {
let out = ''; let out = '';
let config = this.get(this.get('driver')); let config = get(this, get(this, 'driver'));
for ( let i = 0 ; i < locationA.length ; i++ ) { for ( let i = 0 ; i < locationA.length ; i++ ) {
let key = locationA[i]; let key = locationA[i];
let val = get(config, key); let val = get(config, key);
@ -105,8 +109,8 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
return out; return out;
})); }));
this.set('displaySize', computed(this.driver+'.{'+size.join(',')+'}', function() { set(this, 'displaySize', computed(this.driver+'.{'+size.join(',')+'}', function() {
let config = this.get(this.get('driver')); let config = get(this, get(this, 'driver'));
for ( let i = 0 ; i < size.length ; i++ ) { for ( let i = 0 ; i < size.length ; i++ ) {
let key = size[i]; let key = size[i];
let val = get(config, key); let val = get(config, key);
@ -120,7 +124,7 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
}, },
driverSaveAction: computed('inModal', function() { driverSaveAction: computed('inModal', function() {
if (this.get('inModal')) { if (get(this, 'inModal')) {
return 'passConfigBack'; return 'passConfigBack';
} else { } else {
return 'save'; return 'save';
@ -128,8 +132,8 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
}), }),
nameParts: function() { nameParts: function() {
let input = this.get('prefix')||''; let input = get(this, 'prefix')||'';
let count = this.get('count'); let count = get(this, 'count');
let match = input.match(/^(.*?)([0-9]+)$/); let match = input.match(/^(.*?)([0-9]+)$/);
if ( count <= 1 ) if ( count <= 1 )
@ -166,7 +170,7 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
}.property('prefix','count'), }.property('prefix','count'),
nameCountLabel: function() { nameCountLabel: function() {
let parts = this.get('nameParts'); let parts = get(this, 'nameParts');
if ( typeof parts.name !== 'undefined' || !parts.prefix ) if ( typeof parts.name !== 'undefined' || !parts.prefix )
{ {
// qty=1 or no input yet, nothing to see here... // qty=1 or no input yet, nothing to see here...
@ -175,16 +179,16 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
let first = parts.prefix + Util.strPad(parts.start, parts.minLength, '0'); let first = parts.prefix + Util.strPad(parts.start, parts.minLength, '0');
let last = parts.prefix + Util.strPad(parts.end, parts.minLength, '0'); let last = parts.prefix + Util.strPad(parts.end, parts.minLength, '0');
return this.get('intl').tHtml('driver.multiHostNames',{first: first, last: last}); return get(this, 'intl').tHtml('driver.multiHostNames',{first: first, last: last});
}.property('nameParts','intl.locale'), }.property('nameParts','intl.locale'),
nameDidChange: function() { nameDidChange: function() {
this.set('primaryResource.name', this.get('prefix')); set(this, 'primaryResource.name', get(this, 'prefix'));
}.observes('prefix'), }.observes('prefix'),
defaultDescription: function() { defaultDescription: function() {
let loc = this.get('displayLocation'); let loc = get(this, 'displayLocation');
let size = this.get('displaySize'); let size = get(this, 'displaySize');
if ( loc && size ) { if ( loc && size ) {
return loc + ' / ' + size; return loc + ' / ' + size;
} else { } else {
@ -193,14 +197,12 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
}.property('displayLocation','displaySize'), }.property('displayLocation','displaySize'),
willSave() { willSave() {
this.set('primaryResource.clusterId', this.get('cluster.id')); set(this, 'primaryResource.clusterId', get(this, 'cluster.id'));
if ( this.get('primaryResource.type').toLowerCase() === 'machinetemplate') { if ( get(this, 'primaryResource.type').toLowerCase() === 'machinetemplate') {
if ( !this.get('primaryResource.description') ) { if ( !get(this, 'primaryResource.description') ) {
this.set('primaryResource.description', this.get('defaultDescription')); set(this, 'primaryResource.description', get(this, 'defaultDescription'));
} }
} else {
this.set('multiTemplate', this.get('primaryResource').clone());
} }
return this._super(); return this._super();
@ -209,35 +211,39 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
validate() { validate() {
let errors = []; let errors = [];
if ( !this.get('nameParts.prefix') && !this.get('nameParts.name') ) { if ( !get(this, 'nameParts.prefix') && !get(this, 'nameParts.name') ) {
errors.push('Name is required'); errors.push('Name is required');
} }
this.set('errors', errors); set(this, 'errors', errors);
return errors.length === 0; return errors.length === 0;
}, },
doSave() { doSave() {
if ( this.get('primaryResource.type').toLowerCase() === 'machinetemplate' ) { if ( get(this, 'primaryResource.type').toLowerCase() === 'machinetemplate' ) {
return this._super(...arguments); return this._super(...arguments);
} else { } else {
return resolve(this.get('primaryResource')); return resolve(get(this, 'primaryResource'));
} }
}, },
didSave() { didSave() {
let count = this.get('count'); let count = get(this, 'count');
let parts = this.get('nameParts'); let parts = get(this, 'nameParts');
let delay = this.get('createDelayMs'); let delay = get(this, 'createDelayMs');
let tpl; let tpl;
if ( this.get('primaryResource.type').toLowerCase() === 'machinetemplate') { if ( get(this, 'primaryResource.type').toLowerCase() === 'machinetemplate') {
tpl = this.get('globalStore').createRecord({ tpl = get(this, 'globalStore').createRecord({
type: 'machine', type: 'machine',
driver: this.get('model.driver'), driver: get(this, 'model.driver'),
machineTemplateId: this.get('model.id'), machineTemplateId: get(this, 'model.id'),
clusterId: this.get('cluster.id'), clusterId: get(this, 'cluster.id'),
}); });
} else {
// The model was the first one, add subsequent numbers
tpl = get(this, 'primaryResource').clone();
} }
return addHosts(); return addHosts();