From 92a66dfddb61a5e2d8e7e1fcf2a9288c98a52dd2 Mon Sep 17 00:00:00 2001 From: Donal Lafferty Date: Thu, 31 Oct 2013 12:19:15 +0530 Subject: [PATCH] If a VM is already running, deploy virtual machine shouldn't fail and throw an exception. --- .../ServerResource/HypervResource/WmiCallsV2.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs index 4b44a231bdd..71c75d34b66 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs @@ -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);