lepob
Contributor
Contributor

Setting sched.swap.dir on-the-fly.

Hello All,

Can the vm's swap file location sched.swap.dir be set on-the-fly with PowerCLI? I've found a very useful script that allows me to change the location of snapshots (see below), but this sets the working directory which affects both snapshots and swap files, and I'd like to keep my swap files where they are - with the vm.

I'd like to do this, albeit on-the-fly and not by editing the vmx file and unregistering and re-registering the vm.

http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=100292...

The useful script I mentioned.

http://www.peetersonline.nl/index.php/vmware/set-vmware-snapshot-location-with-powershell/

The important bit from the script:

     # Create object containing new properties
     $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
     $vmConfigSpec.Files = New-Object VMware.Vim.VirtualMachineFileInfo
     $vmConfigSpec.Files.SnapshotDirectory = $Location
     # Reconfigure VM using new properties
     $vmView.ReconfigVM($vmConfigSpec)

Any help greatly appreciated.

LepoB.
Tags (2)
0 Kudos
7 Replies
LucD
Leadership
Leadership

You can do this with the Set-VM cmdlet and the VMSwapFilePolicy parameter.

Get-VM MYVM | Set-VM -VMSwapFilePolicy WithVM


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

lepob
Contributor
Contributor

Hi LucD,

I too thought that would work, but I tested it and it didn't. The VI client correctly reflected the change under options - swapfile location - Always store with the virtual machine, but when I vmotioned the vm the swap file remained in the "snapshot" workingdir datastore.

I can only deduce the workingdir setting overrides the VMSwapFilePolicy. Any thoughts?

LepoB

0 Kudos
LucD
Leadership
Leadership

Did you poweroff/poweron the guest after you changed the swap setting and before you did the vMotion ?

I assume the swapfile was in the Snapshotfolder before you changed the setting ?


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

lepob
Contributor
Contributor

No I did not power on/off the vm as I am trying to achieve this this on-the-fly.

Yes, the swap file was already in the snapshot folder before I made the change.

I was hoping there would be an object that could be set, similar to the snapshot one in my original post, that would take effect immediately and without needing any downtime for the vm.

0 Kudos
LucD
Leadership
Leadership

You can make the change with the SDK method as well.

Like this

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec 
$spec
.SwapPlacement = "hostLocal"
Get-VM
| %{     $vm.Extensiondata.ReconfigVM($vmConfigSpec) }

If you look at the swapPlacement property in the VirtualMachineConfigSpec object, it says explicitely that the setting will take effect after a vMigration. So it should work, give it a try.

Possible values for the property are in the VirtualMachineConfigInfoSwapPlacementType enumeration


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

0 Kudos
lepob
Contributor
Contributor

hmmm, unfortunately it didn't work. I managed to successfully set SwapPlacement to "vmDirectory", but after a vmotion the swap file remained in the snapshot directory.

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Files = New-Object VMware.Vim.VirtualMachineFileInfo

$vmConfigSpec.Files.SnapshotDirectory = $Location

$vmConfigSpec.SwapPlacement = "vmDirectory"

$vmView.ReconfigVM($vmConfigSpec)

After a vmotion the swap file did not move to the vm directory.

[vSphere PowerCLI] C:\> $vmview.config.swapplacement
vmDirectory

[vSphere PowerCLI] C:\> $vmview.layout.swapfile
[dhvdct_vmfs_iscsi_001] vm-snapshots/luu048t-35b2a7c1.vswp


[vSphere PowerCLI] C:\> $vmview.config.files


VmPathName        : [dhvdct_vmfs_iscsi_001] luu048t/luu048t.vmx
SnapshotDirectory : [dhvdct_vmfs_iscsi_001] vm-snapshots/
SuspendDirectory  : [dhvdct_vmfs_iscsi_001] luu048t/
LogDirectory      : [dhvdct_vmfs_iscsi_001] luu048t/

Am I missing something?

0 Kudos
lepob
Contributor
Contributor

I tried it again and the same result. Setting the working directory appears to render the swap placement setting irrelevant. With both settings configured using the lines below, after a vmotion the swap file is placed in the workingdir and not with the vm.

I know if I edit the vmx file I can achieve this seperation by adding workingdir and sched.swap.dir, but this requires downtime. As of now I've been unable to do the same with SDK.

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.Files = New-Object VMware.Vim.VirtualMachineFileInfo

$vmConfigSpec.Files.SnapshotDirectory = $Location

$vmConfigSpec.SwapPlacement = "vmDirectory"

 

$vmView.ReconfigVM($vmConfigSpec)

0 Kudos