Skip to content

Commit

Permalink
Merge pull request #25 from AsrOneSdk/multipleIPFixes
Browse files Browse the repository at this point in the history
Multiple IP per NIC - help files, PSObject, test and minor fixes
  • Loading branch information
subashchandra31 authored Apr 20, 2021
2 parents 64e8985 + 793a821 commit b725b2e
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,12 @@ function Test-VMNicConfig {
#Update VM Nic properties
$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
$nicId = $pe.NicDetailsList[0].NicId
$ipConfigName = $pe.NicDetailsList[0].IpConfigs[0].Name
$recNicName = getRecoveryNicName
$nicConfig = New-AzRecoveryServicesAsrVMNicConfig -NicId $nicId -ReplicationProtectedItem $pe -RecoveryNicName $recNicName -RecoveryNicResourceGroupName $recRgName -ReuseExistingNic

$ipConfig = New-AzRecoveryServicesAsrVMNicIPConfig -IpConfigName $ipConfigName -RecoverySubnetName ""
$ipConfigs = @($ipConfig)
$nicConfig = New-AzRecoveryServicesAsrVMNicConfig -NicId $nicId -ReplicationProtectedItem $pe -RecoveryVMNetworkId $RecoveryAzureNetworkId -RecoveryNicName $recNicName -RecoveryNicResourceGroupName $recRgName -ReuseExistingNic -IPConfig $ipConfigs

$updateDRjob = Set-AzRecoveryServicesAsrReplicationProtectedItem -InputObject $pe -ASRVMNicConfiguration $nicConfig
WaitForJobCompletion -JobId $updateDRjob.Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ public class ASRVMNicConfig
/// Gets or sets the IP configuration details for the recovery NIC.
/// </summary>
[DataMember]
public List<IPConfigInputDetails> IPConfigs { get; set; }
public List<PSIPConfigInputDetails> IPConfigs { get; set; }

/// <summary>
/// Gets or sets whether the recovery NIC has accelerated networking enabled.
Expand Down Expand Up @@ -2393,6 +2393,81 @@ public class ASRVMNicConfig
public bool EnableAcceleratedNetworkingOnTfo { get; set; }
}

/// <summary>
/// IP config details of a NIC.
/// </summary>
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
public class PSIPConfigInputDetails
{
/// <summary>
/// Gets or sets name of the IP config.
/// </summary>
[DataMember]
public string IPConfigName { get; set; }

/// <summary>
/// Gets or sets the value indicating if IP config is primary..
/// </summary>
[DataMember]
public bool IsPrimary { get; set; }

/// <summary>
/// Gets or sets the value indicating if IP config is selected for failover..
/// </summary>
[DataMember]
public bool IsSeletedForFailover { get; set; }

/// <summary>
/// Gets or sets recovery subnet name.
/// </summary>
[DataMember]
public string RecoverySubnetName { get; set; }

/// <summary>
/// Gets or sets recovery static IP address.
/// </summary>
[DataMember]
public string RecoveryStaticIPAddress { get; set; }

/// <summary>
/// Gets or sets the id of the recovery public IP address resource associated
/// with the IP config.
/// </summary>
[DataMember]
public string RecoveryPublicIPAddressId { get; set; }

/// <summary>
/// Gets or sets the recovery backend address pools for the IP config.
/// </summary>
[DataMember]
public IList<string> RecoveryLBBackendAddressPoolIds { get; set; }

/// <summary>
/// Gets or sets the subnet to be used by IP config during test failover.
/// </summary>
[DataMember]
public string TfoSubnetName { get; set; }

/// <summary>
/// Gets or sets tfo static IP address.
/// </summary>
[DataMember]
public string TfoStaticIPAddress { get; set; }

/// <summary>
/// Gets or sets the id of the public IP address resource associated with the
/// tfo IP config.
/// </summary>
[DataMember]
public string TfoPublicIPAddressId { get; set; }

/// <summary>
/// Gets or sets the tfo backend address pools for the IP config.
/// </summary>
[DataMember]
public IList<string> TfoLBBackendAddressPoolIds { get; set; }
}

/// <summary>
/// CS Accounts Details.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public class NewAzureRmAsrVmNicConfig : SiteRecoveryCmdletBase
Mandatory = false,
HelpMessage = "Specifies test failover/failover settings of NIC IP configs.")]
[ValidateNotNull]
public IPConfigInputDetails[] IPConfig { get; set; }
public PSIPConfigInputDetails[] IPConfig { get; set; }

#endregion Parameters

Expand Down Expand Up @@ -253,6 +253,29 @@ public override void ExecuteSiteRecoveryCmdlet()
vmNic.EnableAcceleratedNetworkingOnTfo ?? false;
}

List<PSIPConfigInputDetails> ipConfigList = null;
if (this.IPConfig == null || this.IPConfig.ToList().Count == 0)
{
ipConfigList = vmNic.IpConfigs?.Select(ip => ConvertToPSIPConfig(ip))?.ToList() ?? null;
}
else if (vmNic.IpConfigs != null)
{
ipConfigList = this.IPConfig.ToList();
// NIC IP config names in lowercase.
var inputIPConfigNames = this.IPConfig.Select(ip => ip.IPConfigName.ToLower());

foreach (IPConfigDetails ipConfig in vmNic.IpConfigs)
{
if (inputIPConfigNames.Contains(ipConfig.Name.ToLower()))
{
continue;
}

// Defaulting logic for IP configs whose input is not
ipConfigList.Add(ConvertToPSIPConfig(ipConfig));
}
}

nicConfig = new ASRVMNicConfig
{
NicId = this.NicId,
Expand All @@ -263,7 +286,7 @@ public override void ExecuteSiteRecoveryCmdlet()
RecoveryNetworkSecurityGroupId = this.RecoveryNetworkSecurityGroupId,
EnableAcceleratedNetworkingOnRecovery =
this.EnableAcceleratedNetworkingOnRecovery,
IPConfigs = this.IPConfig?.ToList(),
IPConfigs = ipConfigList,
TfoVMNetworkId = this.TfoVMNetworkId,
TfoNicName = this.TfoNicName,
TfoNicResourceGroupName = this.TfoNicResourceGroupName,
Expand Down Expand Up @@ -297,17 +320,19 @@ private bool ValidateAndPopulateIPConfigs(ASRVMNicDetails vmNic)
isRecoveryNetworkRequired = true;
}

var vmNicIPConfig = vmNic.IpConfigs.FirstOrDefault(
IPConfigDetails vmNicIPConfig = vmNic.IpConfigs.FirstOrDefault(
ip => ip.Name.Equals(
ipConfig.IpConfigName, StringComparison.OrdinalIgnoreCase));
ipConfig.IPConfigName, StringComparison.OrdinalIgnoreCase));

if (vmNicIPConfig == null)
{
this.WriteWarning(string.Format(Resources.IPConfigNotFoundInVMNic, ipConfig.IpConfigName, vmNic.NicId));
this.WriteWarning(
string.Format(Resources.IPConfigNotFoundInVMNic,
ipConfig.IPConfigName, vmNic.NicId));
return false;
}

ipConfig.IsPrimary = vmNicIPConfig.IsPrimary;
ipConfig.IsPrimary = (bool)vmNicIPConfig.IsPrimary;
if (string.IsNullOrEmpty(ipConfig.RecoverySubnetName))
{
ipConfig.RecoverySubnetName = vmNicIPConfig.RecoverySubnetName;
Expand Down Expand Up @@ -363,5 +388,23 @@ private bool ValidateAndPopulateIPConfigs(ASRVMNicDetails vmNic)

return true;
}

PSIPConfigInputDetails ConvertToPSIPConfig(IPConfigDetails ipConfig)
{
return new PSIPConfigInputDetails()
{
IPConfigName = ipConfig.Name,
IsPrimary = (bool)ipConfig.IsPrimary,
IsSeletedForFailover = (bool)ipConfig.IsSeletedForFailover,
RecoverySubnetName = ipConfig.RecoverySubnetName,
RecoveryStaticIPAddress = ipConfig.RecoveryStaticIPAddress,
RecoveryPublicIPAddressId = ipConfig.RecoveryPublicIPAddressId,
RecoveryLBBackendAddressPoolIds = ipConfig.RecoveryLBBackendAddressPoolIds,
TfoSubnetName = ipConfig.TfoSubnetName,
TfoStaticIPAddress = ipConfig.TfoStaticIPAddress,
TfoPublicIPAddressId = ipConfig.TfoPublicIPAddressId,
TfoLBBackendAddressPoolIds = ipConfig.TfoLBBackendAddressPoolIds
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery
/// </summary>
[Cmdlet("New", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrVMNicIPConfig", DefaultParameterSetName = ASRParameterSets.AzureToAzure, SupportsShouldProcess = true)]
[Alias("New-ASRVMNicIPConfig")]
[OutputType(typeof(IPConfigInputDetails))]
[OutputType(typeof(PSIPConfigInputDetails))]
public class NewAzureRmAsrVmNicIPConfig : SiteRecoveryCmdletBase
{
#region Parameters
Expand Down Expand Up @@ -126,7 +126,7 @@ public class NewAzureRmAsrVmNicIPConfig : SiteRecoveryCmdletBase
public override void ExecuteSiteRecoveryCmdlet()
{
base.ExecuteSiteRecoveryCmdlet();
IPConfigInputDetails ipConfig = null;
PSIPConfigInputDetails ipConfig = null;

if (string.IsNullOrEmpty(this.RecoverySubnetName) &&
!string.IsNullOrEmpty(this.RecoveryStaticIPAddress))
Expand All @@ -146,9 +146,9 @@ public override void ExecuteSiteRecoveryCmdlet()
{
case ASRParameterSets.AzureToAzure:

ipConfig = new IPConfigInputDetails
ipConfig = new PSIPConfigInputDetails
{
IpConfigName = this.IpConfigName,
IPConfigName = this.IpConfigName,
IsSeletedForFailover = this.IsSelectedForFailover,
RecoverySubnetName = this.RecoverySubnetName,
RecoveryStaticIPAddress = this.RecoveryStaticIPAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,21 @@ private List<VMNicInputDetails> getNicListToUpdate(IList<VMNicDetails> vmNicList
nic.EnableAcceleratedNetworkingOnRecovery;
vMNicInputDetails.RecoveryNetworkSecurityGroupId =
nic.RecoveryNetworkSecurityGroupId;
vMNicInputDetails.IpConfigs = nic.IPConfigs;
vMNicInputDetails.IpConfigs = nic.IPConfigs?.Select(ip =>
new IPConfigInputDetails()
{
IpConfigName = ip.IPConfigName,
IsPrimary = ip.IsPrimary,
IsSeletedForFailover = ip.IsSeletedForFailover,
RecoverySubnetName = ip.RecoverySubnetName,
RecoveryStaticIPAddress = ip.RecoveryStaticIPAddress,
RecoveryPublicIPAddressId = ip.RecoveryPublicIPAddressId,
RecoveryLBBackendAddressPoolIds = ip.RecoveryLBBackendAddressPoolIds,
TfoSubnetName = ip.TfoSubnetName,
TfoStaticIPAddress = ip.TfoStaticIPAddress,
TfoPublicIPAddressId = ip.TfoPublicIPAddressId,
TfoLBBackendAddressPoolIds = ip.TfoLBBackendAddressPoolIds
}).ToList() ?? null;
vMNicInputDetails.TfoNicName = nic.TfoNicName;
vMNicInputDetails.TfoNicResourceGroupName = nic.TfoNicResourceGroupName;
vMNicInputDetails.TfoReuseExistingNic = nic.TfoReuseExistingNic;
Expand All @@ -895,8 +909,13 @@ private List<VMNicInputDetails> getNicListToUpdate(IList<VMNicDetails> vmNicList
&& string.Compare(nDetails.NicId, this.UpdateNic, StringComparison.OrdinalIgnoreCase) == 0)
{
vMNicInputDetails.NicId = this.UpdateNic;

var dbIpConfig = nDetails.IpConfigs?[0];
var ipConfig = new IPConfigInputDetails()
{
IpConfigName = dbIpConfig?.Name,
IsPrimary = dbIpConfig?.IsPrimary ?? true,
IsSeletedForFailover = true,
RecoverySubnetName = this.RecoveryNicSubnetName,
RecoveryStaticIPAddress = this.RecoveryNicStaticIPAddress,
RecoveryPublicIPAddressId = this.RecoveryPublicIPAddressId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ CmdletsToExport = 'Get-AzRecoveryServicesBackupProperty',
'New-AzRecoveryServicesAsrStorageClassificationMapping',
'New-AzRecoveryServicesAsrvCenter',
'New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig',
'New-AzRecoveryServicesAsrVMNicConfig',
'New-AzRecoveryServicesAsrVMNicConfig',
'New-AzRecoveryServicesAsrVMNicIPConfig',
'Remove-AzRecoveryServicesAsrFabric',
'Remove-AzRecoveryServicesAsrNetworkMapping',
'Remove-AzRecoveryServicesAsrPolicy',
Expand Down
Loading

0 comments on commit b725b2e

Please sign in to comment.