From 270470f858cd7806199d3d22388d6975e63ab45a Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Wed, 18 Dec 2019 13:06:11 -0500 Subject: [PATCH 1/6] Update Nic Object Logic --- .../Public/Export-ZertoVmNicSetting.ps1 | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) 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 { From 05783a1f37a531d0f55367c5c8a53f847f5bdd0c Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 19 Dec 2019 18:49:13 -0500 Subject: [PATCH 2/6] Update Import Logic --- .../Public/Import-ZertoVmNicSetting.ps1 | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 index 0a59888..104e325 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" + $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" From 003396998c41ae3ac95bcd24de690ad2c333b12b Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 20 Dec 2019 21:09:12 -0500 Subject: [PATCH 3/6] Eliminate Blank Output --- ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 index 104e325..bd9a51d 100644 --- a/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 +++ b/ZertoApiWrapper/Public/Import-ZertoVmNicSetting.ps1 @@ -51,7 +51,7 @@ function Import-ZertoVmNicSetting { foreach ($nic in $VmNicSettings.nics) { if ($nic.NicIdentifier -eq $vm.NicIdentifier) { $NicUri = "{0}/nics/{1}" -f $uri, $nic.NicIdentifier - Invoke-ZertoRestRequest -uri $NicUri -Method "DELETE" + 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 From 6c92dff447a0c36c49197a587c68235561eebe94 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Fri, 20 Dec 2019 22:56:04 -0500 Subject: [PATCH 4/6] Update Description with new logic --- docs/Import-ZertoVmNicSetting.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/Import-ZertoVmNicSetting.md b/docs/Import-ZertoVmNicSetting.md index f16815a..b09da42 100644 --- a/docs/Import-ZertoVmNicSetting.md +++ b/docs/Import-ZertoVmNicSetting.md @@ -19,7 +19,13 @@ Import-ZertoVmNicSetting [-InputFile] [-WhatIf] [-Confirm] [ Date: Fri, 20 Dec 2019 22:56:20 -0500 Subject: [PATCH 5/6] Update Online Help Link --- docs/Import-ZertoVmNicSetting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Import-ZertoVmNicSetting.md b/docs/Import-ZertoVmNicSetting.md index b09da42..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 --- From 4c98b7513438a958ffa26c83dcd7d42aaf048da7 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 22 Dec 2019 10:48:07 -0500 Subject: [PATCH 6/6] Update RELEASENOTES.md --- RELEASENOTES.md | 2 ++ 1 file changed, 2 insertions(+) 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.