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

I’m Happy to say that with the new form builder in Morpheus 6.1 you no longer need to use this process to create dynamic disks in a catalog item. Please take a look at the new Forms feature for reference.

https://docs.morpheusdata.com/en/latest/library/options/forms.html





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.

2 Likes

To further improve this solution the ‘size’ and ‘storageType’ values on the catalog config can be replaced with the config shown below:

This fixes two problems:

  1. When selecting the number of disks, the total instance cost is not being calculated on the order page if the number of additional disks selected is less than 5. This is fixed by setting the storageType value to ‘0’ from ‘none’.

  2. If a user selects 5 additional disks for example on the catalog order page, and then change it to 3 the total price is not re-calculated.

#Disk1

"size": "<%= if (customOptions.addDisks <'1'){'0'} else { if(customOptions.addDisk1 == '') {'40'} else {customOptions.addDisk2}} %>",
"storageType": "<%= if (customOptions.addDisks <'1'){'0'} else { if(customOptions.addDisk1 == '') {'0'} else {'1'}} %>",


#Disk2

"size": "<%= if (customOptions.addDisks <'2'){'0'} else { if(customOptions.addDisk2 == '') {'40'} else {customOptions.addDisk2}} %>",
"storageType": "<%= if (customOptions.addDisks <'2'){'0'} else { if(customOptions.addDisk2 == '') {'0'} else {'1'}} %>",



#Disk3 

"size": "<%= if (customOptions.addDisks <'3'){'0'} else { if(customOptions.addDisk3 == '') {'40'} else {customOptions.addDisk3}} %>",
"storageType": "<%= if (customOptions.addDisks <'3'){'0'} else { if(customOptions.addDisk3 == '') {'0'} else {'1'}} %>",


#Disk4

"size": "<%= if (customOptions.addDisks <'4'){'0'} else { if(customOptions.addDisk4 == '') {'40'} else {customOptions.addDisk4}} %>",
"storageType": "<%= if (customOptions.addDisks <'4'){'0'} else { if(customOptions.addDisk4 == '') {'0'} else {'1'}} %>",


#Disk5

"size": "<%= if (customOptions.addDisks <'5'){'0'} else { if(customOptions.addDisk5 == '') {'40'} else {customOptions.addDisk5}} %>",
"storageType": "<%= if (customOptions.addDisks <'5'){'0'} else { if(customOptions.addDisk5 == '') {'0'} else {'1'}} %>",

Thanks @wabbas, I had discovered a couple of these issues but forgot I had created this post. Thanks for adding it here and making it better!

Hi @rboyd : I am doing the same for AWS but whenever I add the storage type, it goes in “validation error : input string null”. I have created option lists for adding 5 disks and also added the storage type. For storage type, I have a manual dataset. Is there any other way to add the Storage type as a custom option ?
catalog


Hi @ranujain, Not sure what version of Morpheus you are running but I did some quick testing in 5.5.3 and I find that I can pass the storage type without issue using a manual option list like the one you have above. This allowed me to select the size and type and provisioned to those values without issue.

What didn’t work was setting the storage type to an invalid type to get it to not add the storage in AWS. So if I had 5 disks in my spec and only wanted to provision 3 using the info above it would not work in AWS. For me in my limited testing I would get back an Unsupported volume type. There are other ways to accomplish this like using a script in the configuration phase that edits the payload. You can see some examples of this at Edit Instance Configuration Before Deployment.

@rboyd : The same thing is happening with me. If I have 5 custom options for 5 drives then I will have to add 5 drives, it will not work with less than 5. Is there a way to resolve this within the service catalogs parameters or will we have to use any other way (automation tasks) ?
Morpheus version : 5.4.11

As per my understanding, we can also not use custom options for Mount points , is that correct ?

@ranujain - Correct based on my testing you cant use the original post with AWS to configure mutli disk in that way. To accomplish this you could do it in a few different ways.

Have an automation task that makes the needed api call to add the disks. You should be able to use the resize api call. The documentation for that is located here. https://apidocs.morpheusdata.com/reference/resizeinstance

You could use the reference I provided in the previous post to edit the config phase payload. You can reference this post on how to use this better. Edit Instance Configuration Before Deployment

For the mount points you could still use custom options for mount points but you would pass these to an automation task that would run against the OS resource to make the needed configuration at the OS level.