If a VM is already running, deploy virtual machine shouldn't fail and throw an exception.

This commit is contained in:
Donal Lafferty 2013-10-31 12:19:15 +05:30 committed by Devdeep Singh
parent cce0a27e2b
commit 92a66dfddb
1 changed files with 9 additions and 2 deletions

View File

@ -235,10 +235,17 @@ namespace HypervResource
logger.InfoFormat("Deleting existing VM with name {0}, before we go on to create a VM with the same name", vmName);
DestroyVm(vmName);
}
else if (vmWmiObj.EnabledState == EnabledState.Enabled)
{
string infoMsg = string.Format("Create VM discovered there exists a VM with name {0}, state {1}",
vmName,
EnabledState.ToString(vmWmiObj.EnabledState));
logger.Info(infoMsg);
return vmWmiObj;
}
else
{
// TODO: revise exception type
errMsg = string.Format("Create VM failing, because there exists a VM with name {0}, state {1}",
errMsg = string.Format("Create VM failing, because there exists a VM with name {0}, state {1}",
vmName,
EnabledState.ToString(vmWmiObj.EnabledState));
var ex = new WmiException(errMsg);