dsccommunity / HyperVDsc

This module contains DSC resources for deployment and configuration of Microsoft Hyper-V.
MIT License
114 stars 65 forks source link

VMNetworkAdapter: Multiple DNS IP adresses does not work (parameter type need to be changed) #190

Closed benjFR69 closed 2 years ago

benjFR69 commented 3 years ago

Hello, thanks for this code as it is very uncommon to have something functional for hyperv...

Details of the scenario you tried and the problem that is occurring

When you try to provide a table in the networkingsetting object it does not work as parameter of function is String and not Tab String (MSFT_xVMNetworkAdapter.psm1#L648 )

Verbose logs showing the problem

"module_version": "3.17.0.0", "msg": "Failed to invoke DSC Set method: Incorrect function. ", "reboot_required": false, "verbose_set": [ "Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = ResourceSet,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.", "An LCM method call arrived from computer HOST with user sid S-1-5-21-203002872-2615672331-1556995904-17199.", "[LY-C3-HOST3]: LCM: [ Start Set ] [[xVMNetworkAdapter]DirectResourceAccess]", "[LY-C3-HOST3]: [[xVMNetworkAdapter]DirectResourceAccess] Getting VM Network Adapter information.", "[LY-C3-HOST3]: [[xVMNetworkAdapter]DirectResourceAccess] Adding VM Network Adapter.", "[LY-C3-HOST3]: LCM: [ End Set ] [[xVMNetworkAdapter]DirectResourceAccess] in 1.7500 seconds.", "Operation 'Invoke CimMethod' complete.", "Time taken for configuration job to complete is 1.906 seconds"

Suggested solution to the issue

Change parameter type to "String[]"

The DSC configuration that is used to reproduce the issue (as detailed as possible)

"item": { "NetworkSetting": { "DefaultGateway": "172.99.0.1", "DnsServer": "@("172.99.3.22", "172.993.2")", "IpAddress": "172.99.3.16", "Subnet": "255.255.0.0" }, "name": "default", "switchname": "test", "vlanid": "15" },

We also tried multiple setting : "DnsServer": ["172.99.3.22", "172.99.3.2"], "DnsServer": ("172.99.3.22", "172.99.3.2"), "DnsServer": "172.99.3.22, 172.99.3.2",



#### The operating system the target node is running
Not related to operating system

#### Version and build of PowerShell the target node is running
<!--
    To help with this information, please run this command:
    $PSVersionTable
-->
[HOST]: PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.3866
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.3866
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

#### Version of the DSC module that was used
ansible.windows.win_dsc 
This plugin is part of the ansible.windows collection (version 1.7.2).

Thanks for your help and fix !
johlju commented 2 years ago

This row get the object to set:

https://github.com/dsccommunity/HyperVDsc/blob/0de4197b16a21f5f317a87f99b54e29f4dff220f/source/DSCResources/DSC_VMNetworkAdapter/DSC_VMNetworkAdapter.psm1#L655

and here we set the DNS Server value:

https://github.com/dsccommunity/HyperVDsc/blob/0de4197b16a21f5f317a87f99b54e29f4dff220f/source/DSCResources/DSC_VMNetworkAdapter/DSC_VMNetworkAdapter.psm1#L680

The problem is that the schema is not an array:

https://github.com/dsccommunity/HyperVDsc/blob/0de4197b16a21f5f317a87f99b54e29f4dff220f/source/DSCResources/DSC_VMNetworkAdapter/DSC_VMNetworkAdapter.schema.mof#L8

because the property we set expects an array:

https://docs.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-guestnetworkadapterconfiguration#properties

Happy to review a PR that changes the schema to an array and enforces that array.