mirror of https://github.com/rancher/ui.git
94 lines
2.4 KiB
JavaScript
94 lines
2.4 KiB
JavaScript
import Component from '@ember/component';
|
|
import layout from './template';
|
|
import StorageClassProvisioner from 'shared/mixins/storage-class-provisioner';
|
|
import { get, setProperties, computed, observer } from '@ember/object';
|
|
|
|
export const VOLUME_TYPES = [
|
|
'gp2',
|
|
'io1',
|
|
'st1',
|
|
'sc1',
|
|
];
|
|
|
|
export default Component.extend(StorageClassProvisioner, {
|
|
layout,
|
|
volumeTypes: VOLUME_TYPES,
|
|
|
|
volumeType: null,
|
|
zones: null,
|
|
zoneAutomatic: null,
|
|
iopsPerGB: null,
|
|
encrypted: true,
|
|
kmsKeyId: null,
|
|
kmsAutomatic: null,
|
|
|
|
didReceiveAttrs() {
|
|
const changes = {};
|
|
|
|
changes['volumeType'] = get(this, 'parameters.type')||'gp2';
|
|
changes['iopsPerGB'] = get(this, 'parameters.iopsPerGB')||'';
|
|
|
|
const zone = get(this, 'parameters.zone');
|
|
const zones = get(this, 'parameters.zones');
|
|
if ( zones && zones.length ) {
|
|
changes['zoneAutomatic'] = false;
|
|
changes['zones'] = zones;
|
|
} else if ( zone ) {
|
|
changes['zoneAutomatic'] = false;
|
|
changes['zones'] = 'zone';
|
|
} else {
|
|
changes['zoneAutomatic'] = true;
|
|
changes['zones'] = '';
|
|
}
|
|
|
|
changes['encrypted'] = get(this, 'parameters.encrypted') === "true";
|
|
|
|
const key = get(this, 'parameters.kmsKeyId');
|
|
if ( key ) {
|
|
changes['kmsKeyId'] = key;
|
|
changes['kmsAutomatic'] = false;
|
|
} else {
|
|
changes['kmsAutomatic'] = true;
|
|
}
|
|
|
|
setProperties(this, changes);
|
|
},
|
|
|
|
sendUpdate: observer('volumeType','zones','zoneAutomatic','iopsPerGB','encrypted','kmsKeyId','kmsAutomatic', function() {
|
|
const type = get(this, 'volumeType');
|
|
const out = {
|
|
type: type,
|
|
};
|
|
|
|
const zoneAutomatic = get(this, 'zoneAutomatic');
|
|
if ( !zoneAutomatic ) {
|
|
const zones = (get(this, 'zones')||'').trim();
|
|
if ( zones ) {
|
|
out['zones'] = zones;
|
|
}
|
|
}
|
|
|
|
if ( get(this, 'supportsIops') ) {
|
|
out['opsePerGB'] = (get(this,'iopsPerGB')||'')+'';
|
|
}
|
|
|
|
const encrypted = get(this, 'encrypted');
|
|
const kmsKeyId = get(this, 'kmsKeyId');
|
|
const kmsAutomatic = get(this, 'kmsAutomatic');
|
|
if ( encrypted ) {
|
|
out['encrypted'] = 'true';
|
|
if ( !kmsAutomatic && kmsKeyId ) {
|
|
out['kmsKeyId'] = kmsKeyId;
|
|
}
|
|
} else {
|
|
out['encrypted'] = 'false';
|
|
}
|
|
|
|
this.sendAction('changed', out);
|
|
}),
|
|
|
|
supportsIops: computed('volumeType', function() {
|
|
return !!get(this, 'volumeType').match(/^io\d+$/);
|
|
})
|
|
});
|