win_setup: Added connection name to interfaces (#37327)

pull/38363/head
Jordan Borean 7 years ago committed by GitHub
parent ad94d03ba1
commit fd4d264253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -44,9 +44,9 @@ Function Get-MachineSid {
$cim_instances = @{}
Function Get-LazyCimInstance([string]$instance_name) {
Function Get-LazyCimInstance([string]$instance_name, [string]$namespace="Root\CIMV2") {
if(-not $cim_instances.ContainsKey($instance_name)) {
$cim_instances[$instance_name] = $(Get-CimInstance $instance_name)
$cim_instances[$instance_name] = $(Get-CimInstance -Namespace $namespace -ClassName $instance_name)
}
return $cim_instances[$instance_name]
@ -229,15 +229,26 @@ if($gather_subset.Contains('facter')) {
if($gather_subset.Contains('interfaces')) {
$netcfg = Get-LazyCimInstance Win32_NetworkAdapterConfiguration
$ActiveNetcfg = @()
$ActiveNetcfg += $netcfg | where {$_.ipaddress -ne $null}
$namespaces = Get-LazyCimInstance __Namespace -namespace root
if ($namespaces | Where-Object { $_.Name -eq "StandardCimv" }) {
$net_adapters = Get-LazyCimInstance MSFT_NetAdapter -namespace Root\StandardCimv2
$guid_key = "InterfaceGUID"
$name_key = "Name"
} else {
$net_adapters = Get-LazyCimInstance Win32_NetworkAdapter
$guid_key = "GUID"
$name_key = "NetConnectionID"
}
$formattednetcfg = @()
foreach ($adapter in $ActiveNetcfg)
{
$thisadapter = @{
default_gateway = $null
connection_name = $null
dns_domain = $adapter.dnsdomain
interface_index = $adapter.InterfaceIndex
interface_name = $adapter.description
@ -248,6 +259,10 @@ if($gather_subset.Contains('interfaces')) {
{
$thisadapter.default_gateway = $adapter.DefaultIPGateway[0].ToString()
}
$net_adapter = $net_adapters | Where-Object { $_.$guid_key -eq $adapter.SettingID }
if ($net_adapter) {
$thisadapter.connection_name = $net_adapter.$name_key
}
$formattednetcfg += $thisadapter
}

@ -45,6 +45,7 @@
- setup_result.ansible_facts.ansible_interfaces
- setup_result.ansible_facts.ansible_interfaces[0]
- setup_result.ansible_facts.ansible_interfaces[0].interface_name
- setup_result.ansible_facts.ansible_interfaces[0].connection_name
- setup_result.ansible_facts.ansible_interfaces[0].interface_index
- setup_result.ansible_facts.ansible_architecture
- setup_result.ansible_facts.ansible_os_name
@ -114,6 +115,7 @@
- setup_result.ansible_facts.ansible_interfaces
- setup_result.ansible_facts.ansible_interfaces[0]
- setup_result.ansible_facts.ansible_interfaces[0].interface_name
- setup_result.ansible_facts.ansible_interfaces[0].connection_name
- setup_result.ansible_facts.ansible_interfaces[0].interface_index
- setup_result.ansible_facts.keys() | union(['ansible_interfaces','gather_subset','module_setup']) | length == 3

Loading…
Cancel
Save