PRB - Hyper-V/WMI locks VM after it is created
prb - hyper-v/wmi locks vm after created.
please help,
first off, have forwarded issue forum, think not correct forum post such issue. it's link here:
http://social.technet.microsoft.com/forums/en-us/winserverhyperv/thread/aa5a5fd0-95ec-419d-86f4-6bd2e6fdf802/
i'm using basic sample create vm. following code creates vm on remote hyper-v server. after completes, vm locked, , can not deleted, unless reboot done on hyper-v server. please understand, not want "delet vm" solution. saying, hyper-v manager can not delete vm create through code, because somethign locks it. lock on xml file appears, inside hyper-v storage directy, typically such: c:\programdata\microsoft\windows\hyper-v\virtual machines\~~~~.xml. lock stays until reboot hyper-v machine.
again issue not delete vm, ensure lock on vm (and files) released properly.
what causing this? there extreme measure can taken programmtically 100% remove lock? is, remote machine invoking wmi tell hyper-v release vm?
the machines used remote machine windows server 2008 r1 (x86), hyper-v machine being windows server 2008 r2 (x64).
connectionoptions connectionoptions_temp = new connectionoptions();
connectionoptions_temp.username = "god"; // has access anythign , everything..
connectionoptions_temp.authority = "ntlmdomain:myhypervserver";
connectionoptions_temp.password = "~~secret~~";
managementscope managementscope_temp = new managementscope
(
"\\\\myhypervserver\\root\\virtualization",
connectionoptions_temp
);
string
csret;
managementobject managementobject_globalsettingdata = null;
managementbaseobject managementbaseobject_inparams = null;
managementobject managementobject_vsms = null;
managementobjectcollection managementobjectcollection_dmi = null;
managementobject managementobject_defaultmemory = null;
managementbaseobject_outparams = null;
try
{
managementobject_vsms = getserviceobject
(
managementscope_param, "msvm_virtualsystemmanagementservice"
);
managementbaseobject_inparams = (managementbaseobject)
(
managementobject_vsms.getmethodparameters
(
"definevirtualsystem"
)
);
managementbaseobject_inparams["resourcesettingdata"] = null;
managementbaseobject_inparams["sourcesetting"] = null;
string csinstancesettingdata;
csret = getvirtualsystemglobalsettingdatainstance
(
managementscope_param, out managementobject_globalsettingdata
);
if (getattribute(csret, "ret") != "ok")
{
return csret;
}
managementobject_globalsettingdata["elementname"] = "my vm";
csinstancesettingdata = managementobject_globalsettingdata.gettext(textformat.cimdtd20);
managementbaseobject_inparams["systemsettingdata"] = csinstancesettingdata;
managementbaseobject_outparams = (managementbaseobject)
(
managementobject_vsms.invokemethod
(
"definevirtualsystem", managementbaseobject_inparams, null
)
);
}
catch (exception e)
{
return "ret=err";
}
finally
{
if (!isnull(managementobject_globalsettingdata))
{
try { managementobject_globalsettingdata.dispose(); } catch(exception) { }
managementobject_globalsettingdata = null;
}
if (!isnull(managementbaseobject_inparams))
{
try { managementbaseobject_inparams.dispose(); } catch(exception) { }
managementbaseobject_inparams = null;
}
if (!isnull(managementobjectcollection_dmi))
{
try { managementobjectcollection_dmi.dispose(); } catch(exception) { }
managementobjectcollection_dmi = null;
}
if (!isnull(managementobject_vsms))
{
try { managementobject_vsms.dispose(); } catch(exception) { }
managementobject_vsms = null;
}
}
managementobject managementobject_job = null;
try
{
string csjobpath = csstr(managementbaseobject_outparams["job"]);
managementobject_job = new managementobject
(
managementscope_temp, new managementpath(csjobpath), null
);
while
(
(uint16) managementobject_job["jobstate"] == jobstate.starting
||
(uint16) managementobject_job["jobstate"] == jobstate.running
)
{
if (uitimeout > 0)
{
return "timeout";
}
system.threading.thread.sleep(100);
managementobject_job.get();
}
uijobstate = (uint16) managementobject_job["jobstate"];
if (uijobstate != jobstate.completed)
{
uint16 uijoberrorcode = (uint16) managementobject_job["errorcode"];
string cserrordescription = csstr(managementobject_job["errordescription"]);
return "error";
}
}
catch (exception e)
{
return "exception";
}
finally
{
if (!isnull(managementobject_job))
{
try { managementobject_job.dispose(); } catch(exception) {}
managementobject_job = null;
}
}
return "ret=ok";
at point, program ends. hyper-v manager shows vm created. attempts delete vm hyper-v manager returns error:
"my vm" failed delete configuration: general access denied" (0x80070005) (virtual machine id ~~~~~~~~)
// -----------------------------------------------------
public static managementobjectcollection getserviceobjectcollection
(
managementscope managementscope_param, string csservicename
)
{
managementpath managementpath_wmi = null;
managementclass managementclass_service = null;
managementobjectcollection managementobjectcollection_services = null;
try
{
managementpath_wmi = new managementpath(csservicename);
managementclass_service = new managementclass(managementscope_param, managementpath_wmi, null);
managementobjectcollection_services = managementclass_service.getinstances();
return managementobjectcollection_services;
}
catch (exception e)
{
if (isblank(e.message))
{
}
}
finally
{
if (!isnull(managementclass_service))
{
try { managementclass_service.dispose(); } catch(exception) {}
managementclass_service = null;
}
}
return null;
}
public static string getvirtualsystemglobalsettingdatainstance
(
managementscope managementscope_param,
out managementobject managementobject_globalsettingdata
)
{
managementpath managementpath_settingpath = null;
managementclass managementclass_globalsettingclass = null;
managementobject_globalsettingdata = null;
try
{
managementpath_settingpath = new managementpath
(
"msvm_virtualsystemglobalsettingdata"
);
managementclass_globalsettingclass = new managementclass
(
managementscope_param, managementpath_settingpath, null
);
managementobject_globalsettingdata = managementclass_globalsettingclass.createinstance();
}
catch (exception e)
{
return "ret=err";
}
finally
{
if (!isnull(managementclass_globalsettingclass))
{
try { managementclass_globalsettingclass.dispose(); } catch(exception) { }
managementclass_globalsettingclass = null;
}
}
return "ret=ok";
}
by default, when vm created new (user) security guid created - has same guid vm.
it security guid should own vm.
in regards rebooting host - have tried restarting vsms service? (virtual system management service).
i find hard follow code , understand workflow there many details missing.
can please describe your workflow of actions that performing , in order?
i want make sure not performing action system performing , causing contnetion of sort (i uncovered 1 person doing once similar error yours).
brian ehlert (hopefully have found useful)
Windows Server > Hyper-V
Comments
Post a Comment