VMware Cloud Community
pabloramos
Enthusiast
Enthusiast
Jump to solution

convert string to Vc:Datastore

I have 2 scripts that go out and retrieve all available datastores for a given cluster. I then place the datastore name, Provisionedspace and vmcount values into an array. I parse the array and come up with the datastore name that meets my constraints and spits out the ds name into a string variable I call bestDatastore. I want to pass this string variable bestDatastore to the sub-workflow that clones the vm. I am linking the string variable bestDatastore to the VC:Datastore input on the clone windows vm workflow. The workflow complains with a Warning error that the inputs are not the same and I get the error when I run: [2014-11-04 15:27:16.865] [I] Workflow:LM Get Best Datastore / getBestvmDatastore (item1) : ch.dunes.model.type.ConvertorException: Unable to convert object, 'my_datastore' plugin unexcepted exception : Bad type syntax 'string' How can I take the string value of a datastore and place it in a VC:Datastore type?

Reply
0 Kudos
1 Solution

Accepted Solutions
AlexAllenExpedi
Enthusiast
Enthusiast
Jump to solution

Store the Datastore object in the array, not just the name.

If you need to use the name just pull the datastore object from the array then call objDatastore.name.
When you are ready you can just pass the Datastore object to whatever workflow or additional function you need to do.

There are multiple INEFFICIENT ways to go from str to any managed object. You either have to filter or do a match.

Here is 1 general way.  This can be applied to search for VMs, Neworks, Etc.  anything that returns the Managed Object Reference as an Array.

Using a for loop to go from Strng  to VC:Datastore.

var strMyDatastore = "[DatastoreName]";

for(VcDatastoreIndex in Cluster.Datastore){

     if(strMyDatastore == Cluster.Datastore[VcDatastoreIndex].name){

         //Found you datastore by name do something with it.

     break;

     }

}

You can also run a for loop and match again VC:Datacenter object, Datacenter.sdkConnection.getAllDatastores, etc. etc.
You can filter for it using Attribute Filter and XPATH.
So many different ways.  All this can be avoided if you just keep the Object as an Object and not convert down to a string.

Hope this helps.
~Alex Allen C.

View solution in original post

Reply
0 Kudos
2 Replies
AlexAllenExpedi
Enthusiast
Enthusiast
Jump to solution

Store the Datastore object in the array, not just the name.

If you need to use the name just pull the datastore object from the array then call objDatastore.name.
When you are ready you can just pass the Datastore object to whatever workflow or additional function you need to do.

There are multiple INEFFICIENT ways to go from str to any managed object. You either have to filter or do a match.

Here is 1 general way.  This can be applied to search for VMs, Neworks, Etc.  anything that returns the Managed Object Reference as an Array.

Using a for loop to go from Strng  to VC:Datastore.

var strMyDatastore = "[DatastoreName]";

for(VcDatastoreIndex in Cluster.Datastore){

     if(strMyDatastore == Cluster.Datastore[VcDatastoreIndex].name){

         //Found you datastore by name do something with it.

     break;

     }

}

You can also run a for loop and match again VC:Datacenter object, Datacenter.sdkConnection.getAllDatastores, etc. etc.
You can filter for it using Attribute Filter and XPATH.
So many different ways.  All this can be avoided if you just keep the Object as an Object and not convert down to a string.

Hope this helps.
~Alex Allen C.

Reply
0 Kudos
pabloramos
Enthusiast
Enthusiast
Jump to solution

that worked, thanks Alex.

Reply
0 Kudos