vCenter Orchestrator – Add NFS Datastore

Was surprised this wasn’t here by default, but alas, out of the box vCO does not ship with a workflow to manage an NFS datastore.

Thanks to the VMware communities for a bit of scripting, I was able to put one together. First we’ll break out the components, then show you how it runs. Finally you’ll be able to pull it down.

Inputs:

So first we need to tell vCO where to find the NFS datastore as well as what host we are adding it to:
image

If you can’t read the above, no worries, I can’t either, so I’ve also got this handy table:

NameTypeDescription
HostVC:HostSystemHost to connect datastore to
DatastoreNamestringName for Datastore
remoteHoststringHostname or IP for NFS server
remotePathstringPath to Exports

Schema:

Now that we have our inputs, let’s build out the actual flow-charty bits for the workflow:
image

Yeah, pretty much that simple. Start, scripting block, stop.

Scripting!

Now for the awesomesauce that makes this work:

var datastore_mgr = Host.configManager.datastoreSystem;
 
var new_spec = new VcHostNasVolumeSpec();
new_spec.accessMode=VcHostMountMode._readWrite;
new_spec.localPath=DatastoreName;
new_spec.remoteHost=remoteHost;
new_spec.remotePath=remotePath;
new_spec.type=”nfs”;

try {
    var newDatastore=datastore_mgr.createNasDatastore(new_spec);
}

catch (ex) {
    System.log ( ex + ” creating datastore ” + remoteHost + “:” + remotePath + ” on ” + Host.name + ” as datastore ” + DatastoreName );
}

Note: Parts of this script were borrowed from the VMware communities here. Also found this here.

Running:

image

Results:

image

image

Summary

So, the workflow itself is kinda useful for a single host, it becomes more powerful when you embed it within another workflow to do say all hosts in a cluster. However, that’s an activity for the reader.

Download

The workflow can be downloaded from here!

More Info

We’ve talked about vCO extensively in the past… you can find some additional info here.