im trying to write a control VMs on a HyperV Server using Python. I start with connecting to the server the HyperV server runs on:
connection = wmi.connect_server(server="servername", namespace=r"root\virtualization", user=r"username", password=r"password") wmiServerConnection = wmi.WMI(wmi=connection) This gives me a wmi object for this connection.
For stopping and starting a VM I can simply use:
#get the wmi object representing the VM vmSystem = wmiServerConnection.Msvm_ComputerSystem(ElementName="VmName") #send change request to vm vmSystem[0].RequestStateChange(3) But before starting a VM I want to apply a certain snapshot. The class Msvm_VirtualSystemManagementService provides a method - ApplyVirtualSystemSnapshot/ApplyVirtualSystemSnapshotEx - for this. It needs the SnapshotSettingData as a parameter and I thought I could get that one using the GetSummaryInformation method of the same class. MSDN says this method returns a Msvm_SummaryInformation class.
I call this function like this:
#get the wmi class object vmManagement = wmiServerConnection.Msvm_VirtualSystemManagementService() snapshotInfo = vmManagement[0].GetSummaryInformation([1,107]) This should give me the name and the snapshot information for all VMs on the HyperV server. But all I get is list of COM Objects.
When I try to give a certain VM as parameter gotten from
vmSettings = wmiServerConnection.Msvm_VirtualSystemSettingData(ElementName="VmName") like this
snapshotInfo = vmManagement[0].GetSummaryInformation([1,107], [vmSettings[0]]) it crashes.
My questions:
Why don't I get a WMI object?
The second parameter is obviously wrong. MSDN says it needs
CIM_VirtualSystemSettingData REF SettingData[]as parameter. Is the WMI object the wrong one? How do I get the correct parameter?How can I retrieve the information I need from the COM object?
Or am I totally on the wrong track?
Thanks, Stefanie