Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple IP per NIC - help files, PSObject, test and minor fixes #25

Merged
merged 3 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
subashchandra31 marked this conversation as resolved.
Show resolved Hide resolved

$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; }
subashchandra31 marked this conversation as resolved.
Show resolved Hide resolved

#endregion Parameters

Expand Down Expand Up @@ -253,6 +253,28 @@ 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;
subashchandra31 marked this conversation as resolved.
Show resolved Hide resolved
}
else if (vmNic.IpConfigs != null)
{
ipConfigList = this.IPConfig.ToList();
var inputIPConfigNames = this.IPConfig.Select(ip => ip.IPConfigName).ToList();
subashchandra31 marked this conversation as resolved.
Show resolved Hide resolved

foreach (IPConfigDetails ipConfig in vmNic.IpConfigs)
{
if (inputIPConfigNames.Contains(ipConfig.Name))
subashchandra31 marked this conversation as resolved.
Show resolved Hide resolved
{
continue;
}

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

nicConfig = new ASRVMNicConfig
{
NicId = this.NicId,
Expand All @@ -263,7 +285,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 +319,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 +387,23 @@ private bool ValidateAndPopulateIPConfigs(ASRVMNicDetails vmNic)

return true;
}

PSIPConfigInputDetails ConvertToPSIPConfig(IPConfigDetails ipConfig)
subashchandra31 marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -875,7 +875,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 @@ -901,8 +915,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