VMware Cloud Community
matt5stow
Contributor
Contributor

Schedule task for compute / storage vMotion - CLI

I am trying to find a script so I can create scheduled tasks via CLI so I can migrate multiple VMs as once to new hosts and storage. 

Scheduling one server at a time via the vCenter GUI works but would like to create multiple scheduled as we have hundreds of servers to migrate. 

I have seen post about scheduling snapshots via CLI but not migrations. 

Please help!

Labels (4)
0 Kudos
22 Replies
LucD
Leadership
Leadership

Which vSphere version is that?
I can see the Datastoreclusters when I do a Migrate Storage only.

For the scheduled task, this process of selecting a DatastoreCluster for a migration is in fact two calls.

The first call is to the RecommendDatastores method.
This returns a Datastore from the DatastoreCluster, as recommended by SDRS.

The second call is to the RelocateVM method, specifying the Datastore returned by the previous method.

Unfortunately calling two methods with a Scheduled Task is not available via the API.

But you could pick one Datastore from the DatastoreCLuster at random, then SDRS would if activated, make sure the files end up on the correct Datastore in the DatastoreCLuster.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
teddo1
Contributor
Contributor

It's a long shot but you are the best Luc so hoping for some help! 🙂

I'm searching for a script that will vmotion (compute only) a specific list of 5 vms from whatever host they currently reside on to any other host in the same cluster, and I want it to repeat hourly. So somehow the logic would have to get the current host of each vm and exclude it as a target for that vm, but any other host can be a target.  It would be best if the target hosts got randomized (not all vms end up on the same host).  There are 10 hosts in the cluster. Is it possible?  Nothing in vCenter scheduled tasks seems to fit the bill.

0 Kudos
LucD
Leadership
Leadership

For that kind of logic, you would need a script.
Unfortunately, the vCenter Scheduled Tasks don't really allow such scripts.
Unless you would opt for something as described in Use-Case: Execute PowerCLI Scripts as vSphere Alarm Actions using Script Runtime Service

An easier, at least IMHO, solution would be to use an external scheduler, like for example the Windows Task Scheduler or a cron table on a Linux box.

The 1st question you should answer is where and how you want to run the script.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos