Renaming a datastore through vCO

1 minute read

I was in need of automatically renaming a generic datastore name in one of my host deployment workflows and found that the renameDatastore() method was deprecated (Thanks Jörg!) and that we are to use rename_Task().  The rename_Task() method is one that takes any manageable object.  Here is an exert from the API reference:

Rename_Task

Renames this managed entity.

Any % (percent) character used in this name parameter must be escaped, unless it is used to start an escape sequence. Clients may also escape any other characters in this name parameter.
See [name] http://pubs.vmware.com/vsphere-50/topic/com.vmware.wssdk.apiref.doc_50/vim.ManagedEntity.html#name

Required Privileges
When object is VirtualMachine - VirtualMachine.Config.Rename
When object is Datacenter - Datacenter.Rename
When object is Folder - Folder.Rename
When object is VirtualApp - VApp.Rename
When object is ResourcePool - Resource.RenamePool
When object is ClusterComputeResource - Host.Inventory.RenameCluster
When object is DistributedVirtualSwitch - DVSwitch.Modify
When object is DistributedVirtualPortgroup - DVPortgroup.Modify
When object is Datastore - Datastore.Rename
When object is Network - System.Read

So I implemented the following code into a new scriptable task within my workflow:

var hostDatastoreSystem = VcPlugin.toManagedObject( host, host.configManager.datastoreSystem );

// Rename datastore on host matching Datastore
for each (var datastore in hostDatastoreSystem.datastore) {
if(datastore.name == "Datastore"){
datastore.rename_Task("newDsName");
System.log("Changing datastore name to "+newDsName);
}

Another thing I realized was that the API explorer within vCO is not always as forthcoming with information so a word to the wise, always check the API reference (http://pubs.vmware.com/vsphere-50/topic/com.vmware.wssdk.apiref.doc_50/right-pane.html) for more detailed information.

Leave a Comment