vRO scriptable task to expand a datastore

A quick vRO time saver.  Here is the scriptable task to expand a datastore.  This is not extents it’s an expand.  In other words the lun has expanded and you want the datastore to use newly available space.   In the next article I will show how to create a vRA service to expand the datastore.

datastorename = "your-test-datastore-name";

//Get all datastores
var ds = System.getModule("com.vmware.library.vc.datastore").getAllDatastoresMatchingRegexp(datastorename);

//Locate a ESXi host that connects to the datastore (from ds into host)
esx = ds[0].host[0].key;

//Get VimHostDatastore system to be used to gather path and extent
dsSys = esx.configManager.datastoreSystem;

//Get the local path to vmfsSystem
vmfsPath = ds[0].host[0].mountInfo.path;

//Identify free space on the lun and put into VcVmfsDatastoreExpandSpec
extend = dsSys.queryVmfsDatastoreExpandOptions(ds[0]);

//As long as extend is not null
if ( extend != null)
 extend_spec = extend[0].spec;
 //expand the volume to max size on disk
 System.log("Expanding Datastore : " + datastorename);
 dsSys.expandVmfsDatastore(ds[0], extend_spec);

//Rescan is initiated by the expand for all nodes mounting so it does not need to be done manually

You can download it here: datastore_Expand

Let me know if you have any questions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.