Configuration phase to modify requested instance volume information before deployment

Hello,

This is a quick post to share an example configuration phase script that will enforce that the root volume goes to 50GB and then the VM deploys with two additional volumes, regardless of what a user inputs during instance provision. This was for a niche customer use-case, but I thought it might be useful for the community as another example of using the configuration phase.

Script:

import json

configspec = morpheus['spec']
volume1 = None
for volume in configspec['volumes']:
    if volume["rootVolume"] == True:
        volume1 = volume
        break #we have the root volume

#change size of root volume
volume1["size"] = 50 #50GB

#create some custom volumes to overide user selected volume settings
volume2 = {}
volume2["size"] = 10
volume2["storageType"] = volume1["storageType"] #get same storage type as first (root) volume
volume2["id"] = -1 #no id yet as its new
volume2["datastoreId"] = volume1["datastoreId"] 
volume2["rootVolume"] = False
volume2["name"] = "volume2"

volume3 = {}
volume3["size"] = 20
volume3["storageType"] = volume1["storageType"] #get same storage type as first (root) volume
volume3["id"] = -1 #no id yet as its new
volume3["datastoreId"] = volume1["datastoreId"]
volume3["rootVolume"] = False
volume3["name"] = "volume3"

configspec["volumes"] = [volume1, volume2, volume3] #override the existing volumes data
configspec["volumesDisplay"] = configspec["volumes"] #copy over in other place in spec

newspec = {}
newspec['spec'] = configspec
print(json.dumps(newspec)) #return spec so Morpheus uses new spec

Cheers,

Chris

4 Likes