VMware Cloud Community
ukmtk
Contributor
Contributor

Reset VM test box

Forgive me if this is a silly question. I'm a developer but a complete newbie to vSphere Power CLI.

I'll describe the scenario I have and what I am attempting to do. I have a number of VMs that are automated test boxes. They are reset by the VM server each night and then run a suite of automated tests. Currently I reboot them every 4 hours to rerun the tests (using "shutdown -r"). Unfortunately these reboots leave installed software remaining on the VMs.

Solution: what I would like to do is get the VM to request a reset of itself if the automated tests run successfully. I.e. if the tests fail the VM will not request a reset. At first I had hoped that with the CLI I might be able to do this with something along the lines of:

get-vm testbox | stop-vm | start-vm

I suspect that this might not actually work from the testbox itself? When I tried a stop-vm command in a shell (Windows PowerShell or vSpere Power CLI) it keeps asking for a Y/N confirmation (regardless of the "-confirm" switch)? Would this also happen in a script?

Is what I wish to do possible from the test VM box itself? And what software do I actually need to install on this machine? It would be a lot easier if there were some simple executable I could place on the VM itself that would allow it to perform simple commands (e.g. a "reset").

0 Kudos
8 Replies
LucD
Leadership
Leadership

Provided you have PowerShell and PowerCLI installed on those test boxes you should be able to trigger the restart from the test box itself.

Remember that you first will need to set up a connection to the vCenter or the ESX server with Coonect-ViServer.

The confirmation prompt can be overruled by the -Confirm parameter.

Connect-ViServer -Server <vCentername>
Get-VM <VM-name> | Stop-Vm -Confirm:$false | Start-Vm

For your question about an executable, there is a tool called PowerWF Studio that will allow you to build an EXE from the above lines of PowerShell code. The product is currently still in RC but GA is apparently just around the corner.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
ukmtk
Contributor
Contributor

Unfortunately on my VM the stop-vm stops the VM. But it seems to me like the start-vm never actually happens? I.e. the VM enters the powered off state but never restarts (powered on)?

Which would make sense if the piped object no longer exists? This seems to me to be an inherent problem if the reset is a non-atomic operation?

I.e. a VM is not actually able to request a reset itself if it has to perform a stop followed by a start!?

0 Kudos
LucD
Leadership
Leadership

The VirtualMachineImpl object also exists for a VM that is stopped.

Strange that the VM is not started. Tested it again and this works for me.

Are you on the latest PowerShell and PowerCLI release ?

Against which vCenter and ESX/ESXi versions are you using this ?

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
ae_jenkins
Enthusiast
Enthusiast

If you have the vmware tools installed, this should also work and get around the mysterious 'not starting" issue

Connect-ViServer -Server -Confirm:$false

0 Kudos
ukmtk
Contributor
Contributor

Unfortunately a restart in that form is equivalent to "shutdown -r" - i.e. a reboot with disks as they were.

This is what I was trying to get around.

0 Kudos
ukmtk
Contributor
Contributor

I certainly have the latest PowerCLI (VMware-Vim4PS-4.0.1-208462.exe).

It was running on PowerShell 1.0(WindowsXP-KB926139-v2-x86-ENU.exe) but I tried PowerShell 2.0 (WindowsXP-KB968930-x86-ENG.exe) and it had the same effect.

The VM server is VC 2.5 with ESXi 3.5.

The test script worked fine against a VM that was not hosting the script. I'm just having problems when testing it on the VM to be reset.

0 Kudos
LucD
Leadership
Leadership

Oops, I missed the part that you running the script on the VM that is being reset.

Then I understand why it doesn't get to the Start-VM cmdlet.

An alternative is to trigger the run from the VM that needs to be restarted but run the script itself on another box.

You could use the Invoke-VMScript cmdlet for that.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
ukmtk
Contributor
Contributor

OK - thanks for the helpful replies. It is much as I had expected.

0 Kudos