Skip to main content
  1. Posts/

Renaming a datastore through vCO

·242 words·2 mins· loading · loading · ·
Howto JavaScript Vco Vro

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:

{% highlight javascript %} 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); } {% endhighlight %}

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.

James Bowling
Author
James Bowling
Principal Cloud Engineer @ Global Oil/Gas Drilling Company

Related

vCO Webviews/Perspectives Default Values Issue
·165 words·1 min· loading · loading
Howto Vco Vro
vCO vApp Upgrade Issue
·214 words·2 mins· loading · loading
Blog Bug Howto Vco Vro
vCenter Orchestrator: Operation Automate - Part Five
·355 words·2 mins· loading · loading
Blog Howto Workflows Vco Vro