VMware Cloud Community
kalex
Enthusiast
Enthusiast

setting multiple swapfile datastores on a host question

hello,

I'm trying to automate -vmswapdatastore location on my cluster and so far I managed to add single datastore that can be used. Problem is i can't figure out how to add multiple datastores that are allocated to swapfile datstores on my cluster.

here is my code:

connect-viserver vcenter

foreach ($vmhost in get-cluster "clustername" | get-vmhost)

{ Get-vmhost $vmhost | set-vmhost -vmswapfiledatastore "VS01" }

this works perfectly but I can't add more of them and if i try to add another one it just replaces the current one with new one. so how would i go about adding vs02 and vs03 to the datstores?

What is the trick to doing this?

thanks

Alex

0 Kudos
6 Replies
LucD
Leadership
Leadership

Afaik you can only define a single datastore to store virtual machine swapfiles.

If you look at the localSwapDatastore property in the HostConfigInfo object that seems to also refer to a single datastore.

And in the vSphere Client there is no option to select more than one datastore.


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

0 Kudos
kalex
Enthusiast
Enthusiast

that makes sense. what is the trick to sorting out hosts during get-vmhost command? for example i have 16 hosts in a cluster:

host1

host2

host3

host4

host16

if i want to assign swap data store in groups of four. so for example host1-host4 will get vs01 datastore, host5-host8 will get vs02 and so on. what do i need to do to get this accomplished?

thanks again for help btw

0 Kudos
LucD
Leadership
Leadership

Try something like this

foreach($i in 1..3){
	Get-VMHost -Name ((($i -1)*4+1)..($i*4) | %{"host" + $_}) | Set-VMHost -VMSwapfileDatastore ("vs0" + $i)
}

For testing add perhaps first the -WhatIf parameter on the Set-VMHost cmdlet.


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

0 Kudos
kalex
Enthusiast
Enthusiast

Thanks for the tip. let me play around with it

0 Kudos
AnatolyVilchins

rather than { Get-vmhost $vmhost | set-vmhost -vmswapfiledatastore "VS01" },
could you not use different data store names, to make it easier to script?

eg:
{ Get-vmhost $vmhost | set-vmhost -vmswapfiledatastore "VS-$vmhost" }



saves you having to bother counting how many machines are running, or which ones is using what datastore.



I'm probably completely off the mark and missed the point, but...





http://serverfault.com/questions/98220/setting-multiple-swapfile-datastores-on-a-host-question

Starwind Software Developer

www.starwindsoftware.com

Kind Regards, Anatoly Vilchinsky
0 Kudos
kalex
Enthusiast
Enthusiast

Anatoly - what you suggested will not work for me. we have 16 hosts in a cluster and we allocate 4 data stores for swap file location. so vs1, vs2, vs3, vs4. since each host can only have 1 location we need to break it up into 4 hosts. so hosts 1-4 will get vs1 data store, 5-8 will get vs2, 9-12 will get vs3, and 13-16 will get vs4.

So I believe i need to use Luc's suggestion of how to separate hosts into groups of 4 and assign swap location. of course I'm open to other suggestions as well

thanks

Alex

0 Kudos