pnrk
pnrk

Reputation: 1

WMI methods for Hyper-V network management is failing on Windows 2012

I have been trying to use WMI classes (using C++) to manage Virtual Switches in Hyperv like Creation,Deletion, Attach a Virtual Network to a VM etc. I was able to do everything perfectly on Windows 2008 R2. But none of them are working fine on Windows 2012.

For example when I create an externalnetwork I call a method called CreateSwitchPort on the object of the class Msvm_VirtualSwitchManagementService. It's working on 2k8R2 but fails with out parameter return value as 32768 which means failure. Can anyone point out why does the method return an error? How to debug the issue? Are there any permissions I should be giving. Any help in the regard is highly appreciated.

--Ramakrishna.

Upvotes: 0

Views: 1283

Answers (1)

Donal Lafferty
Donal Lafferty

Reputation: 5986

Hyper-V 2012 supports the previous WMI API, and I have successfully used it. Hyper-V 2012 introduces a v2 API, but this is irrelevant to you.

CreateSwitchPort is a very straightforward call. Here is an example in Python that is quite readable. The Python call returns a tuple that the [out] parameters are added to.

    #Create a port on the vswitch.
    (new_port, ret_val) = switch_svc.CreateSwitchPort(
                                        Name=str(uuid.uuid4()),
                                        FriendlyName=vm_name,
                                        ScopeOfResidence="",
                                        VirtualSwitch=extswitch.path_())

Check that the VirtualSwitch parameter is valid. I use a WMI query shown below to get this object. It fails if the VirtualSwitch is not connected to an external NIC. Is your query successful?

        return self._conn.Msvm_ExternalEthernetPort(IsBound='TRUE')[0]\
        .associators(wmi_result_class='Msvm_SwitchLANEndpoint')[0]\
        .associators(wmi_result_class='Msvm_SwitchPort')[0]\
        .associators(wmi_result_class='Msvm_VirtualSwitch')[0]

Next, look to see if the name Name parameter needs to be unique. If you use a static name, the call might fail because of a naming conflict.

If none of this helps, then start inspecting the Hyper-V WMI objects in realtime. You can use Python and the WMI bindings for Python by Tim Golden.

Upvotes: 0

Related Questions