diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 36bc38e..4d97ada 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -3,3 +3,5 @@ ### Zerto Virtual Manager * Addressed a reported [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/60) in the `Get-ZertoRecoveryReport` function where the `-VpgIdentifier` parameter was not working. This parameter is not accepted by the API as a valid filter and is ignored. This parameter has been removed from the function. +* Addressed a reported [issue](https://github.com/ZertoPublic/ZertoApiWrapper/issues/60) where the `Export-ZertoVpgNicSetting` function would not properly execute when run against a VM with no NICs attached. +* In reviewing the `Export-ZertoVpgNicSetting`, a review of the `Import-ZertoVpgNicSetting` was completed and it was determined to update the import logic based on various test cases. Along with this, it is now possible to reset the NIC settings to the default state with the `Import-ZertoVpgNicSetting` command. Please review the [Import-ZertoVpgNicSetting help](https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Import-ZertoVmNicSetting.md) to review the updated options and import logic. diff --git a/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 index bef7b42..110b125 100644 --- a/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 +++ b/ZertoApiWrapper/Public/Export-ZertoVmNicSetting.ps1 @@ -45,33 +45,37 @@ function Export-ZertoVmNicSetting { $null = Remove-ZertoVpgSettingsIdentifier -vpgSettingsIdentifier $settingsId $networkMap = Get-Map -InputObject $networks -key "NetworkIdentifier" -value "VirtualizationNetworkName" foreach ($vm in $vmSettings) { - $nicInfo = [PSCustomObject]@{ - VPGName = $group.VPGName - VMName = $vmMap[$($vm.vmIdentifier)] - NicIdentifier = $vm.nics.NicIdentifier - LiveNetwork = $networkMap[$vm.nics.failover.Hypervisor.NetworkIdentifier] - LiveShouldReplaceMac = $vm.nics.failover.Hypervisor.ShouldReplaceMacAddress - LiveIsDHCP = $vm.Nics.failover.Hypervisor.IpConfig.IsDhcp - LiveIpAddress = $vm.nics.failover.Hypervisor.IpConfig.StaticIp - LiveIpSubnetMask = $vm.nics.failover.Hypervisor.IpConfig.SubnetMask - LiveIpDefaultGateway = $vm.nics.failover.Hypervisor.IpConfig.Gateway - LivePrimaryDns = $vm.nics.failover.Hypervisor.IpConfig.PrimaryDns - LiveSecondayDns = $vm.nics.failover.Hypervisor.IpConfig.SecondaryDns - LiveDnsSuffix = $vm.nics.failover.Hypervisor.DnsSuffix - TestNetwork = $networkMap[$vm.nics.failoverTest.Hypervisor.NetworkIdentifier] - TestShouldReplaceMac = $vm.nics.failoverTest.Hypervisor.ShouldReplaceMacAddress - TestIsDHCP = $vm.Nics.failoverTest.Hypervisor.IpConfig.IsDhcp - TestIpAddress = $vm.nics.failoverTest.Hypervisor.IpConfig.StaticIp - TestIpSubnetMask = $vm.nics.failoverTest.Hypervisor.IpConfig.SubnetMask - TestIpDefaultGateway = $vm.nics.failoverTest.Hypervisor.IpConfig.Gateway - TestPrimaryDns = $vm.nics.failoverTest.Hypervisor.IpConfig.PrimaryDns - TestSecondayDns = $vm.nics.failoverTest.Hypervisor.IpConfig.SecondaryDns - TestDnsSuffix = $vm.nics.failoverTest.Hypervisor.DnsSuffix + if ($vm.nics.count -gt 0) { + foreach ($nic in $vm.nics) { + $nicInfo = [PSCustomObject]@{ + VPGName = $group.VPGName + VMName = $vmMap[$vm.vmIdentifier] + NicIdentifier = $nic.NicIdentifier + LiveNetwork = $networkMap[$nic.failover.Hypervisor.NetworkIdentifier] + LiveShouldReplaceMac = $nic.failover.Hypervisor.ShouldReplaceMacAddress + LiveIsDHCP = $nic.failover.Hypervisor.IpConfig.IsDhcp + LiveIpAddress = $nic.failover.Hypervisor.IpConfig.StaticIp + LiveIpSubnetMask = $nic.failover.Hypervisor.IpConfig.SubnetMask + LiveIpDefaultGateway = $nic.failover.Hypervisor.IpConfig.Gateway + LivePrimaryDns = $nic.failover.Hypervisor.IpConfig.PrimaryDns + LiveSecondayDns = $nic.failover.Hypervisor.IpConfig.SecondaryDns + LiveDnsSuffix = $nic.failover.Hypervisor.DnsSuffix + TestNetwork = $networkMap[$nic.failoverTest.Hypervisor.NetworkIdentifier] + TestShouldReplaceMac = $nic.failoverTest.Hypervisor.ShouldReplaceMacAddress + TestIsDHCP = $nic.failoverTest.Hypervisor.IpConfig.IsDhcp + TestIpAddress = $nic.failoverTest.Hypervisor.IpConfig.StaticIp + TestIpSubnetMask = $nic.failoverTest.Hypervisor.IpConfig.SubnetMask + TestIpDefaultGateway = $nic.failoverTest.Hypervisor.IpConfig.Gateway + TestPrimaryDns = $nic.failoverTest.Hypervisor.IpConfig.PrimaryDns + TestSecondayDns = $nic.failoverTest.Hypervisor.IpConfig.SecondaryDns + TestDnsSuffix = $nic.failoverTest.Hypervisor.DnsSuffix + } + $nicInfo + } } - $nicInfo } } - $nicSettings | Export-Csv -Path $OutputFile + $nicSettings | Export-Csv -Path $OutputFile -NoTypeInformation } end { diff --git a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 index 0a59888..bd9a51d 100644 --- a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 +++ b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 @@ -44,15 +44,28 @@ function Import-ZertoVmNicSetting { [string]::IsNullOrWhiteSpace($Vm.LiveShouldReplaceMac) -or [string]::IsNullOrWhiteSpace($Vm.TestNetwork) -or [string]::IsNullOrWhiteSpace($Vm.TestShouldReplaceMac)) { - Write-Error "$($Vm.VMName) does not contain all the required data. Please check the CSV entry for this item and try again." -ErrorAction Continue + Write-Error "$($Vm.VMName) does not contain all the required data. Please check the CSV entry for this item and try again. You are required to provide the VPGName, VMName, NicIdentifier, LiveNetwork, and ShouldReplaceMacAddress for each Nic." -ErrorAction Continue } else { $uri = "vpgSettings/{0}/vms/{1}" -f $vpgSettingsId, $vmMap[$vm.VMName] $VmNicSettings = Get-ZertoVpgSetting -vpgSettingsIdentifier $vpgSettingsId -vmIdentifier $vmMap[$vm.VMName] foreach ($nic in $VmNicSettings.nics) { if ($nic.NicIdentifier -eq $vm.NicIdentifier) { - $nic.failover.Hypervisor.NetworkIdentifier = $NetworkMap[$vm.LiveNetwork] - $nic.failover.Hypervisor.ShouldReplaceMacAddress = $vm.LiveShouldReplaceMac - if ($null -eq $nic.failover.Hypervisor.IpConfig -and ($null -ne $vm.LiveIsDHCP -or $null -ne $vm.LiveIpAddress)) { + $NicUri = "{0}/nics/{1}" -f $uri, $nic.NicIdentifier + Invoke-ZertoRestRequest -uri $NicUri -Method "DELETE" > $null + $nicSettings = Invoke-ZertoRestRequest -uri $NicUri -Method "GET" + $nicSettings.failover.Hypervisor.NetworkIdentifier = $NetworkMap[$vm.LiveNetwork] + $nicSettings.failover.Hypervisor.ShouldReplaceMacAddress = $vm.LiveShouldReplaceMac + if ($vm.LiveIsDHCP -imatch "true") { + $IpConfig = [PSCustomObject]@{ + IsDhcp = $vm.LiveIsDHCP + PrimaryDns = $vm.LivePrimaryDns + SecondaryDns = $vm.LiveSecondayDns + } + $nicSettings.failover.Hypervisor.IpConfig = $IpConfig + $nicSettings.failover.Hypervisor.DnsSuffix = $vm.LiveDnsSuffix + } elseif (($vm.LiveIsDHCP -imatch "false" -or + [string]::IsNullOrWhiteSpace($vm.LiveIsDHCP)) -and + -not [string]::IsNullOrWhiteSpace($vm.LiveIpAddress)) { $IpConfig = [PSCustomObject]@{ IsDhcp = $vm.LiveIsDHCP StaticIp = $vm.LiveIpAddress @@ -61,21 +74,22 @@ function Import-ZertoVmNicSetting { PrimaryDns = $vm.LivePrimaryDns SecondaryDns = $vm.LiveSecondayDns } - $nic.failover.Hypervisor.IpConfig = $IpConfig - } elseif ($null -eq $nic.failover.Hypervisor.IpConfig -and $null -eq $vm.LiveIsDHCP -and $null -eq $vm.LiveIpAddress) { - $nic.failover.Hypervisor.IpConfig = $null - } else { - $nic.failover.Hypervisor.IpConfig.IsDhcp = $vm.LiveIsDHCP - $nic.failover.Hypervisor.IpConfig.StaticIp = $vm.LiveIpAddress - $nic.failover.Hypervisor.IpConfig.SubnetMask = $vm.LiveIpSubnetMask - $nic.failover.Hypervisor.IpConfig.Gateway = $vm.LiveIpDefaultGateway - $nic.failover.Hypervisor.IpConfig.PrimaryDns = $vm.LivePrimaryDns - $nic.failover.Hypervisor.IpConfig.SecondaryDns = $vm.LiveSecondayDns + $nicSettings.failover.Hypervisor.IpConfig = $IpConfig + $nicSettings.failover.Hypervisor.DnsSuffix = $vm.LiveDnsSuffix } - $nic.failover.Hypervisor.DnsSuffix = $vm.LiveDnsSuffix - $nic.failoverTest.Hypervisor.NetworkIdentifier = $NetworkMap[$vm.TestNetwork] - $nic.failoverTest.Hypervisor.ShouldReplaceMacAddress = $vm.TestShouldReplaceMac - if ($null -eq $nic.failoverTest.Hypervisor.IpConfig -and ($null -ne $vm.TestIsDHCP -or $null -ne $vm.TestIpAddress)) { + $nicSettings.failoverTest.Hypervisor.NetworkIdentifier = $NetworkMap[$vm.TestNetwork] + $nicSettings.failoverTest.Hypervisor.ShouldReplaceMacAddress = $vm.TestShouldReplaceMac + if ($vm.TestIsDHCP -imatch "true" ) { + $IpConfig = [PsCustomObject]@{ + IsDhcp = $vm.TestIsDHCP + PrimaryDns = $vm.TestPrimaryDns + SecondaryDns = $vm.TestSecondayDns + } + $nicSettings.failoverTest.Hypervisor.IpConfig = $IpConfig + $nicSettings.failoverTest.Hypervisor.DnsSuffix = $vm.TestDnsSuffix + } elseif (($vm.TestIsDHCP -imatch "false" -or + [string]::IsNullOrWhiteSpace($vm.TestIsDHCP)) -and + -not [string]::IsNullOrWhiteSpace($vm.TestIpAddress)) { $IpConfig = [PsCustomObject]@{ IsDhcp = $vm.TestIsDHCP StaticIp = $vm.TestIpAddress @@ -84,24 +98,15 @@ function Import-ZertoVmNicSetting { PrimaryDns = $vm.TestPrimaryDns SecondaryDns = $vm.TestSecondayDns } - $nic.failoverTest.Hypervisor.IpConfig = $IpConfig - } elseif ($null -eq $nic.failoverTest.Hypervisor.IpConfig -and $null -eq $vm.TestIsDHCP -and $null -eq $vm.TestIpAddress) { - $nic.failoverTest.Hypervisor.IpConfig = $null - } else { - $nic.failoverTest.Hypervisor.IpConfig.IsDhcp = $vm.TestIsDHCP - $nic.failoverTest.Hypervisor.IpConfig.StaticIp = $vm.TestIpAddress - $nic.failoverTest.Hypervisor.IpConfig.SubnetMask = $vm.TestIpSubnetMask - $nic.failoverTest.Hypervisor.IpConfig.Gateway = $vm.TestIpDefaultGateway - $nic.failoverTest.Hypervisor.IpConfig.PrimaryDns = $vm.TestPrimaryDns - $nic.failoverTest.Hypervisor.IpConfig.SecondaryDns = $vm.TestSecondayDns + $nicSettings.failoverTest.Hypervisor.IpConfig = $IpConfig + $nicSettings.failoverTest.Hypervisor.DnsSuffix = $vm.TestDnsSuffix + } + Write-Verbose "Putting Updated Config for VM: $($vm.name), NIC: $($nic.nicidentifier) in VPG: $Vpg" + if ($PSCmdlet.ShouldProcess($vm.NicIdentifier, "Updating Nic")) { + Invoke-ZertoRestRequest -uri $NicUri -Method "PUT" -Body ($nicSettings | ConvertTo-Json -Depth 10) > $null } - $nic.failoverTest.Hypervisor.DnsSuffix = $vm.TestDnsSuffix } } - Write-Verbose "Putting Updated Config for VM: $($vm.vmname) in Vpg: $Vpg" - if ($PSCmdlet.ShouldProcess($vm.NicIdentifier, "Updating Nic")) { - Invoke-ZertoRestRequest -uri $uri -Method "PUT" -Body ($VmNicSettings | ConvertTo-Json -Depth 10) > $null - } } } Write-Verbose "Saving updated configuration for VPG: $Vpg" diff --git a/docs/Import-ZertoVmNicSetting.md b/docs/Import-ZertoVmNicSetting.md index f16815a..d65b8fc 100644 --- a/docs/Import-ZertoVmNicSetting.md +++ b/docs/Import-ZertoVmNicSetting.md @@ -1,7 +1,7 @@ --- external help file: ZertoApiWrapper-help.xml Module Name: ZertoApiWrapper -online version: https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Get-ZertoZsspSession.md +online version: https://github.com/ZertoPublic/ZertoApiWrapper/blob/master/docs/Import-ZertoVmNicSetting.md schema: 2.0.0 --- @@ -19,7 +19,13 @@ Import-ZertoVmNicSetting [-InputFile] [-WhatIf] [-Confirm] [