Page 1 of 1

LaunchVMProcess emergencystop API clarification?

PostPosted: 13. May 2013, 10:18
by rousseauhk
If I run

Code: Select all   Expand viewCollapse view
machine.LaunchVMProcess(null, "emergencystop", null);


I sometimes get an error:

"The machine [blah] is not locked by a session"

However if I try to establish a lock before i call it:
Code: Select all   Expand viewCollapse view
machine.LockMachine(session, LockType.LockType_VM);


I often get the contrary error (something like) "Session locked by another user".

What is the correct usage of the emergencystop command? From the documentation it reads like it shouldnt need a lock, because the whole purpose is to terminate a machine that is in use/locked by another user. Am I missing something?

thx
Steve

Re: LaunchVMProcess emergencystop API clarification?

PostPosted: 13. May 2013, 16:32
by noteirak
I am not sure how it should behave - never used that specific of it.
I'll give it a try later tonight and see what happens. Or a dev comes by and answers your question directly :)

Re: LaunchVMProcess emergencystop API clarification?

PostPosted: 13. May 2013, 21:26
by noteirak
I won't have the time tonight, but I was wondering : is there any particular reason you're using that specific method instead of using the regular powerDown()?

Re: LaunchVMProcess emergencystop API clarification?

PostPosted: 14. May 2013, 12:02
by rousseauhk
I run a cleanup process under a separate account that deletes old VMs. Since the VM could still have a lock open by another user, this seemed the most fool-proof way. The current method seems to work, but sometime generates those exceptions in the locking code (and if I dont lock, it sometimes generates exceptions in the emergencystop code).

thx
Steve

Re: LaunchVMProcess emergencystop API clarification?

PostPosted: 14. May 2013, 13:58
by noteirak
Just to make it clear, if you use the "emergencystop", does the VM ALWAYS stop, and sometimes you get an exception?
If that's the case, then I believe it would only be part of the API race with session and object destruction. I had a chat about this with Klaus in the dev mailing list but about powerOff().
Basically, if the VM always stops, and you sometimes get an exception aswell, then it's working as expected and your code has to deal with it.

Re: LaunchVMProcess emergencystop API clarification?

PostPosted: 14. May 2013, 17:20
by rousseauhk
While LaunchVMProess doesnt always seem to work by itself, the following code does (or at least I havent yet found a case where it fails)..

Code: Select all   Expand viewCollapse view
; psuedo-code
try
{
lockMachine();
}
catch (Exception) { //ignore}

try
{
LanchVMProcess("EmergencyStop"};
}
catch (Exception) { //ignore}

try
{
unlockMachine();
}
catch (Exception) { //ignore }


Basically this seems to covers two cases:

1) LaunchVMProcess either requires a lock in which case try{lockMachine()} always seems to work. Or
2) LaunchVMProcess doesnt require a lock, in which case try{lockMachine()} fails, but LaunchVMProcess still works OK.

thx
Steve

Re: LaunchVMProcess emergencystop API clarification?

PostPosted: 14. May 2013, 20:55
by noteirak
For the unlock(), you do require to be ready to catch exception yes, that's by design - see my discussion about it with Klaus, one of the devs.
So I would assume your code is in track with what would be expected but if you want a final confirmation, I would take this to the dev mailing list.

Side note : be sure that you don't simply catch Exception but check if the exception error message/code fits your specific issue, and rethrow it if it doesn't.