Creating an Instance Catalog item that allows users to add additional disks

If your looking for a way to allow users to add additional disks to an Instance Catalog Item in Morpheus this may help.

Requirements:
- An Option List that allows users to select the number of drives they want to add
- An Input for the number of drives selection
- An Input for each additional drive
- Catalog Item for the instance


Option Lists:

addDisks (Option List) - This will just be a manual dataset that will allow users in this case to select adding from 1 to 5 extra disks



Inputs:

addDisks (Input) - This will be the input as a select list linked back to the addDisks option list above.



addDisk1 (Input) - this is a number input to allow the user to set the size of the disk. We are also setting the visibility based on what is selected from the addDisks input.
config.customOptions.addDisks:(^1$|^2$|^3$|^4$|^5$) - This will display the field if any value 1 to 5 is selected for the addDisks drop down.


You will want to repeat the above for each additional disk you want to allow. Changing the visibility to only display for the number of disks selected.

addDisks2 = config.customOptions.addDisks:(^2$|^3$|^4$|^5$)
addDisks3 = config.customOptions.addDisks:(^3$|^4$|^5$)
addDisks4 = config.customOptions.addDisks:(^4$|^5$)
addDisks5 = config.customOptions.addDisks:(^5$)

Now we can move on to building our Catalog Item

Run through the customization wizard as you normally would adding the max number of disks that you want the user to be able to add. This should match the inputs you created in the above steps. This will create the config for these volumes in the spec for you.

In my example I will keep it simple and most values in the spec will be hard coded with the exception of the disks we want the users to be able to select.

You will want to add all the disk Inputs you created to the catalog item. In my case I have the number of disks selection and then 5 disk inputs.





In our spec we want to look for the volume blocks and add logic to the size and the storage type. In order to get Morpheus to not add a volume we want to set the storageType to something that does not exist in Morphues. In the example below I am setting the storageType to ‘none’ if my cusomtOption of addDisk1 does not have a value. If it does have a value it’s going to set the storageType to ‘1’. 1 is the value that was pulled for this disk type when running the wizard to initially create the spec. You will want to do the same to every additional drive in the spec you want to allow the add function.

{
“rootVolume”: false,
“name”: “data-1”,
“maxStorage”: 0,
“minStorage”: 0,
“datastoreId”: “auto”,
“controllerMountPoint”: “161:0:6:1”,
“size”: “<%= if(customOptions.addDisk1 == ‘’) {‘40’} else {customOptions.addDisk1} %>”,
“volumeCustomizable”: true,
“readonlyName”: false,
“storageType”: “<%= if(customOptions.addDisk1 == ‘’) {‘none’} else {‘1’} %>”,
“maxIOPS”: null
},


What this looks like for the user from the catalog.

When one disk is selected

When 5 disks are selected


Results:

Now when selecting 1 additional disk we can see below that the instance was provisioned with 1 additional disk with the size of 20 specified.


From the same catalog item when 5 disks are selected and we enter 20,30,40,50,60 for disks 1 through 5. We see that 5 disks were added with the values specified.