diff --git a/packages/manager/modules/bm-server-components/src/general-information/inputs/inputs.class.js b/packages/manager/modules/bm-server-components/src/general-information/inputs/inputs.class.js deleted file mode 100644 index 4c105ff3381e..000000000000 --- a/packages/manager/modules/bm-server-components/src/general-information/inputs/inputs.class.js +++ /dev/null @@ -1,32 +0,0 @@ -export default class Inputs { - constructor(resource) { - Object.assign(this, resource); - } - - answersHash2userMetadata(answersHash) { - const userMetadata = []; - Object.values(this).forEach((input) => { - if (input.type !== 'keyValue' && answersHash[input.name]) { - userMetadata.push({ - key: input.name.toString(), - value: answersHash[input.name].toString(), - }); - } else if ( - input.type === 'keyValue' && - answersHash[input.name].length > 0 - ) { - answersHash[input.name].forEach((keyValueItem, keyValueIndex) => { - userMetadata.push({ - key: `${input.name + keyValueIndex}Key`, - value: keyValueItem.key.toString(), - }); - userMetadata.push({ - key: `${input.name + keyValueIndex}Value`, - value: keyValueItem.value.toString(), - }); - }); - } - }); - return userMetadata; - } -} diff --git a/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.constants.js b/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.constants.js index 141afcdf43c3..4c2d029741b6 100644 --- a/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.constants.js +++ b/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.constants.js @@ -1,17 +1,6 @@ export const MOUNT_POINTS = 'defghijklmnopqrstuvwxyza'; export const MAX_MOUNT_POINTS = 24; -export const TEMPLATE_OS_HARDWARE_RAID_ENUM = { - raid0: 'raid0', - raid1: 'raid1', - raid5: 'raid5', - raid6: 'raid6', - raid7: 'raid7', - raid10: 'raid10', - raid50: 'raid50', - raid60: 'raid60', -}; - export const TEMPLATE_OS_SOFTWARE_RAID_LIST = { 1: ['0'], 2: ['0', '1'], @@ -25,6 +14,5 @@ export const TEMPLATE_OS_SOFTWARE_RAID_LIST = { export default { MOUNT_POINTS, MAX_MOUNT_POINTS, - TEMPLATE_OS_HARDWARE_RAID_ENUM, TEMPLATE_OS_SOFTWARE_RAID_LIST, }; diff --git a/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.controller.js b/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.controller.js index 7bdd60a223f2..57a7cdcc9842 100644 --- a/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.controller.js +++ b/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.controller.js @@ -4,12 +4,10 @@ import forEachRight from 'lodash/forEachRight'; import range from 'lodash/range'; import set from 'lodash/set'; import some from 'lodash/some'; -import Inputs from '../../inputs/inputs.class'; import { INPUTS_RULES } from '../../inputs/constants'; import { MOUNT_POINTS, MAX_MOUNT_POINTS, - TEMPLATE_OS_HARDWARE_RAID_ENUM, TEMPLATE_OS_SOFTWARE_RAID_LIST, } from './server-installation-ovh.constants'; @@ -94,6 +92,8 @@ export default class ServerInstallationOvhCtrl { warningRaid6: '6', warningRaid7: '7', warningRaid10: '10', + warningRaid50: '50', + warningRaid60: '60', warningNone: 'none', warningSwap: 'swap', warningReiserfs: 'reiserfs', @@ -149,6 +149,8 @@ export default class ServerInstallationOvhCtrl { // STEP2 SELECT selectPartitionScheme: null, // select hight priority partition scheme partitionSchemeModels: null, // detail of partitionScheme selected + storage: [], + customizations: {}, nbDiskUse: null, // if nbPhysicalDisk > 2 user can select nb disk to use // dirtyPartition: true if variable partition size // has been customized(change to false in loadPartition()) @@ -1696,38 +1698,38 @@ export default class ServerInstallationOvhCtrl { } if (nbOfDisk >= 8) { this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid60, + this.$scope.constants.warningRaid60, ); } if (nbOfDisk >= 7) { this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid7, + this.$scope.constants.warningRaid7, ); } if (nbOfDisk >= 6) { this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid50, + this.$scope.constants.warningRaid50, ); } if (nbOfDisk >= 4) { this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid6, + this.$scope.constants.warningRaid6, ); this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid10, + this.$scope.constants.warningRaid10, ); } if (nbOfDisk >= 3) { this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid5, + this.$scope.constants.warningRaid5, ); } if (nbOfDisk >= 2) { this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid1, + this.$scope.constants.warningRaid1, ); this.$scope.informations.hardwareRaid.availableRaids.push( - TEMPLATE_OS_HARDWARE_RAID_ENUM.raid0, + this.$scope.constants.warningRaid0, ); } } @@ -1743,31 +1745,31 @@ export default class ServerInstallationOvhCtrl { this.$scope.installation.hardwareRaid.disks = null; switch (this.$scope.installation.hardwareRaid.raid) { - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid60: + case this.$scope.constants.warningRaid60: minDisks = 8; minDisksPerArray = 4; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid50: + case this.$scope.constants.warningRaid50: minDisks = 6; minDisksPerArray = 3; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid10: + case this.$scope.constants.warningRaid10: minDisksPerArray = 2; minDisks = 4; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid7: + case this.$scope.constants.warningRaid7: minDisks = 7; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid6: + case this.$scope.constants.warningRaid6: minDisks = 4; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid5: + case this.$scope.constants.warningRaid5: minDisks = 3; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid1: + case this.$scope.constants.warningRaid1: minDisks = 2; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid0: + case this.$scope.constants.warningRaid0: minDisks = 2; break; default: @@ -1793,17 +1795,17 @@ export default class ServerInstallationOvhCtrl { this.$scope.installation.hardwareRaid.arrays = null; switch (this.$scope.installation.hardwareRaid.raid) { - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid60: + case this.$scope.constants.warningRaid60: maxNumberArray = this.$scope.installation.hardwareRaid.disks / 4; minNumberArray = 2; isMultipleArrays = true; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid50: + case this.$scope.constants.warningRaid50: maxNumberArray = this.$scope.installation.hardwareRaid.disks / 3; minNumberArray = 2; isMultipleArrays = true; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid10: + case this.$scope.constants.warningRaid10: maxNumberArray = this.$scope.installation.hardwareRaid.disks / 2; minNumberArray = 2; isMultipleArrays = true; @@ -1845,31 +1847,31 @@ export default class ServerInstallationOvhCtrl { this.$scope.installation.hardwareRaid.totalSpace = this.$scope.installation.hardwareRaid.disks * diskSize; switch (this.$scope.installation.hardwareRaid.raid) { - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid60: + case this.$scope.constants.warningRaid60: this.$scope.installation.hardwareRaid.availableSpace = (nbOfDisks - 2 * grappe) * diskSize; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid50: + case this.$scope.constants.warningRaid50: this.$scope.installation.hardwareRaid.availableSpace = (nbOfDisks - grappe) * diskSize; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid10: + case this.$scope.constants.warningRaid10: this.$scope.installation.hardwareRaid.availableSpace = grappe * diskSize; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid7: + case this.$scope.constants.warningRaid7: this.$scope.installation.hardwareRaid.availableSpace = (nbOfDisks - 3) * diskSize; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid6: + case this.$scope.constants.warningRaid6: this.$scope.installation.hardwareRaid.availableSpace = (nbOfDisks - 2) * diskSize; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid5: + case this.$scope.constants.warningRaid5: this.$scope.installation.hardwareRaid.availableSpace = (nbOfDisks - 1) * diskSize; break; - case TEMPLATE_OS_HARDWARE_RAID_ENUM.raid1: + case this.$scope.constants.warningRaid1: this.$scope.installation.hardwareRaid.availableSpace = diskSize; break; default: @@ -2016,26 +2018,11 @@ export default class ServerInstallationOvhCtrl { startInstall() { this.$scope.loader.loading = true; - const inputs = new Inputs(this.$scope.installation.inputs); - // console.log('startInstall'); - // console.log(this.$scope.installation.partitionSchemeModels); this.Server.startInstallation( this.$stateParams.productId, this.$scope.informations.gabaritName, - this.$scope.installation.selectPartitionScheme, - { - customHostname: this.$scope.installation.options.customHostname, - softRaidDevices: - this.$scope.informations.nbDisk > 2 && - this.$scope.installation.nbDiskUse > 1 - ? this.$scope.installation.nbDiskUse - : null, - noRaid: - this.$scope.installation.nbDiskUse === 1 && - !this.$scope.informations.raidController, - diskGroupId: this.$scope.installation.diskGroup.diskGroupId || null, - }, - inputs.answersHash2userMetadata(this.$scope.installation.input), + this.$scope.installation.storage, + this.$scope.installation.customizations, ).then( (task) => { set(task, 'id', task.taskId); @@ -2058,30 +2045,109 @@ export default class ServerInstallationOvhCtrl { ); } - // setHardwareRaid( - // schemeNameFilterList = [this.$scope.installation.selectPartitionScheme], - // ) { - // const disks = this.prepareDiskList(); - // // console.log('setHardwareRaid'); + getCustomizations() { + const customizations = {}; + Object.values(this.$scope.installation.inputs).forEach((input) => { + if ( + input.type !== 'keyValue' && + this.$scope.installation.input[input.name] + ) { + customizations[input.name.toString()] = this.$scope.installation.input[ + input.name + ].toString(); + } else if ( + input.type === 'keyValue' && + this.$scope.installation.input[input.name].length > 0 + ) { + customizations[input.name.toString()] = {}; + this.$scope.installation.input[input.name].forEach((keyValueItem) => { + customizations[input.name.toString()][ + keyValueItem.key.toString() + ] = keyValueItem.value.toString(); + }); + } + }); + this.$scope.installation.customizations = customizations; + } + + getStoragePartitioningLayout() { + this.$scope.installation.partitionSchemeModels.sort( + (a, b) => a.order - b.order, + ); + const layout = []; + angular.forEach( + this.$scope.installation.partitionSchemeModels, + (partition) => { + const newPartition = { + fileSystem: partition.fileSystem, + mountPoint: partition.mountPoint, + size: partition.partitionSize, + raidLevel: Number(partition.raid), // jbd: to be improved + extras: {}, + }; + if ( + partition.volumeName && + this.$scope.installation.selectDistribution.lvmReady && + partition.fileSystem !== this.$scope.constants.warningZFS && + partition.fileSystem !== this.$scope.constants.warningSwap + ) { + newPartition.extras = { + lv: { + name: partition.volumeName, + }, + }; + } + if ( + partition.volumeName && + partition.fileSystem === this.$scope.constants.warningZFS + ) { + newPartition.extras = { + zp: { + name: partition.volumeName, + }, + }; + } + layout.push(newPartition); + }, + ); + return layout; + } - // schemeNameFilterList.forEach((schemeNameFilter) => { - // console.log(this.$stateParams.productId); - // console.log(this.$scope.informations.gabaritName); - // console.log(schemeNameFilter); - // console.log(disks); - // console.log(this.$scope.installation.hardwareRaid.raid); - // console.log('----'); - // console.log(this.$scope.installation.hardwareRaid); - // }); - // } + setStorage() { + const storage = { + diskGroupId: this.$scope.installation.diskGroup.diskGroupId || null, + hardwareRaid: [], + partitioning: { + disks: + this.$scope.informations.nbDisk > 2 && + this.$scope.installation.nbDiskUse > 1 + ? this.$scope.installation.nbDiskUse + : 0, + layout: [], + }, + }; + if (this.$scope.installation.hardwareRaid.raid) { + const disks = this.prepareDiskList(); + storage.hardwareRaid.push({ + arrays: this.$scope.installation.hardwareRaid.arrays, + disks: disks.length, + raidLevel: Number(this.$scope.installation.hardwareRaid.raid), // jbd: to be improved + }); + } + if (this.$scope.installation.customInstall) { + storage.partitioning.layout = this.getStoragePartitioningLayout(); + } else { + storage.partitioning.schemeName = this.$scope.installation.selectPartitionScheme; + } + this.$scope.installation.storage.push(storage); + } install() { this.trackClick( `dedicated::dedicated::${this.serverType}::system-install::public-catalog::install`, ); - // if (this.$scope.installation.hardwareRaid.raid) { - // this.setHardwareRaid(); - // } + this.getCustomizations(); + this.setStorage(); this.startInstall(); } diff --git a/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.html b/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.html index 1b740ab962d8..7e1f45445130 100644 --- a/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.html +++ b/packages/manager/modules/bm-server-components/src/general-information/installation/ovh/server-installation-ovh.html @@ -259,7 +259,7 @@ id="hardwareRaidRaidMode" name="hardwareRaidRaidMode" data-ng-if="installation.hardwareRaid.controller" - data-ng-options="raid as raid for raid in informations.hardwareRaid.availableRaids | orderBy:'toString()'" + data-ng-options="raid as 'raid' + raid for raid in informations.hardwareRaid.availableRaids | orderBy:'toString()'" data-ng-model="installation.hardwareRaid.raid" > diff --git a/packages/manager/modules/bm-server-components/src/server/server.service.js b/packages/manager/modules/bm-server-components/src/server/server.service.js index 9b9dd5d9fbb2..9aee89b11b0d 100644 --- a/packages/manager/modules/bm-server-components/src/server/server.service.js +++ b/packages/manager/modules/bm-server-components/src/server/server.service.js @@ -854,21 +854,19 @@ export default class Server { startInstallation( serviceName, - templateName, - partitionSchemeName, - details, - userMetadata = {}, + operatingSystem, + storage = {}, + customizations = {}, ) { - return this.OvhHttp.post('/dedicated/server/{serviceName}/install/startt', { + return this.OvhHttp.post('/dedicated/server/{serviceName}/reinstall', { rootPath: 'apiv6', urlParams: { serviceName, }, data: { - userMetadata, - details, - partitionSchemeName, - templateName, + operatingSystem, + storage, + customizations, }, }); }