コード例 #1
0
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();
            ASRVMNicConfig nicConfig = null;

            if (string.IsNullOrEmpty(this.RecoveryVMNetworkId) &&
                !string.IsNullOrEmpty(this.RecoveryVMSubnetName))
            {
                this.WriteWarning(Resources.RecoveryNetworkInformationMissing);
                return;
            }

            if (string.IsNullOrEmpty(this.TfoVMNetworkId) &&
                !string.IsNullOrEmpty(this.TfoVMSubnetName))
            {
                this.WriteWarning(Resources.TfoNetworkInformationMissing);
                return;
            }

            if (string.IsNullOrEmpty(this.RecoveryVMSubnetName) &&
                !string.IsNullOrEmpty(this.RecoveryNicStaticIPAddress))
            {
                this.WriteWarning(Resources.RecoverySubnetInformationMissing);
                return;
            }

            if (string.IsNullOrEmpty(this.TfoVMSubnetName) &&
                !string.IsNullOrEmpty(this.TfoNicStaticIPAddress))
            {
                this.WriteWarning(Resources.TfoSubnetInformationMissing);
                return;
            }

            switch (this.ParameterSetName)
            {
            case ASRParameterSets.AzureToAzure:

                var providerSpecificDetails =
                    this.ReplicationProtectedItem.ProviderSpecificDetails;

                if (!(providerSpecificDetails is ASRAzureToAzureSpecificRPIDetails))
                {
                    this.WriteWarning(
                        Resources.UnsupportedReplicationProvidedForASRVMNicConfig);
                    return;
                }

                var vmNicDetailsList =
                    this.ReplicationProtectedItem.NicDetailsList ??
                    new List <ASRVMNicDetails>();

                var vmNic =
                    vmNicDetailsList.FirstOrDefault(
                        nic => nic.NicId.Equals(
                            this.NicId, StringComparison.OrdinalIgnoreCase));

                if (vmNic == null)
                {
                    this.WriteWarning(string.Format(Resources.NicNotFoundInVM, this.NicId));
                    return;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryVMNetworkId)))
                {
                    this.RecoveryVMNetworkId =
                        this.ReplicationProtectedItem.SelectedRecoveryAzureNetworkId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryVMSubnetName)))
                {
                    this.RecoveryVMSubnetName = vmNic.RecoveryVMSubnetName;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryNicStaticIPAddress)))
                {
                    this.RecoveryNicStaticIPAddress = vmNic.ReplicaNicStaticIPAddress;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryNetworkSecurityGroupId)))
                {
                    this.RecoveryNetworkSecurityGroupId = vmNic.RecoveryNetworkSecurityGroupId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() =>
                                                this.EnableAcceleratedNetworkingOnRecovery)))
                {
                    this.EnableAcceleratedNetworkingOnRecovery =
                        vmNic.EnableAcceleratedNetworkingOnRecovery ?? false;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryPublicIPAddressId)))
                {
                    this.RecoveryPublicIPAddressId = vmNic.RecoveryPublicIPAddressId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryLBBackendAddressPoolId)))
                {
                    this.RecoveryLBBackendAddressPoolId =
                        vmNic.RecoveryLBBackendAddressPoolId?.ToArray();
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoVMNetworkId)))
                {
                    this.TfoVMNetworkId =
                        this.ReplicationProtectedItem.SelectedTfoAzureNetworkId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoVMSubnetName)))
                {
                    this.TfoVMSubnetName = vmNic.TfoVMSubnetName;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoNicStaticIPAddress)))
                {
                    this.TfoNicStaticIPAddress =
                        vmNic.TfoIPConfigs?.FirstOrDefault()?.StaticIPAddress ?? string.Empty;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoNetworkSecurityGroupId)))
                {
                    this.TfoNetworkSecurityGroupId = vmNic.TfoNetworkSecurityGroupId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() =>
                                                this.EnableAcceleratedNetworkingOnTfo)))
                {
                    this.EnableAcceleratedNetworkingOnTfo =
                        vmNic.EnableAcceleratedNetworkingOnTfo ?? false;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoPublicIPAddressId)))
                {
                    this.TfoPublicIPAddressId =
                        vmNic.TfoIPConfigs?.FirstOrDefault()?.PublicIpAddressId ?? string.Empty;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoLBBackendAddressPoolId)))
                {
                    this.TfoLBBackendAddressPoolId =
                        vmNic.TfoIPConfigs?.FirstOrDefault()?.LBBackendAddressPoolIds?.ToArray();
                }

                nicConfig = new ASRVMNicConfig
                {
                    NicId = this.NicId,
                    RecoveryVMNetworkId                   = this.RecoveryVMNetworkId,
                    RecoveryVMSubnetName                  = this.RecoveryVMSubnetName,
                    RecoveryNetworkSecurityGroupId        = this.RecoveryNetworkSecurityGroupId,
                    EnableAcceleratedNetworkingOnRecovery =
                        this.EnableAcceleratedNetworkingOnRecovery,
                    RecoveryIPConfigs =
                        new List <IPConfig>
                    {
                        new IPConfig
                        {
                            StaticIPAddress         = this.RecoveryNicStaticIPAddress,
                            PublicIpAddressId       = this.RecoveryPublicIPAddressId,
                            LBBackendAddressPoolIds =
                                this.RecoveryLBBackendAddressPoolId?.ToList() ??
                                new List <string>()
                        }
                    },

                    TfoVMNetworkId                   = this.TfoVMNetworkId,
                    TfoVMSubnetName                  = this.TfoVMSubnetName,
                    TfoNetworkSecurityGroupId        = this.TfoNetworkSecurityGroupId,
                    EnableAcceleratedNetworkingOnTfo = this.EnableAcceleratedNetworkingOnTfo,
                    TfoIPConfigs =
                        new List <IPConfig>
                    {
                        new IPConfig
                        {
                            StaticIPAddress         = this.TfoNicStaticIPAddress,
                            PublicIpAddressId       = this.TfoPublicIPAddressId,
                            LBBackendAddressPoolIds =
                                this.TfoLBBackendAddressPoolId?.ToList() ??
                                new List <string>()
                        }
                    }
                };

                break;
            }

            this.WriteObject(nicConfig);
        }
コード例 #2
0
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();
            ASRVMNicConfig nicConfig = null;

            switch (this.ParameterSetName)
            {
            case ASRParameterSets.AzureToAzure:

                var providerSpecificDetails =
                    this.ReplicationProtectedItem.ProviderSpecificDetails;

                if (!(providerSpecificDetails is ASRAzureToAzureSpecificRPIDetails))
                {
                    this.WriteWarning(
                        Resources.UnsupportedReplicationProvidedForASRVMNicConfig);
                    return;
                }

                var vmNicDetailsList =
                    this.ReplicationProtectedItem.NicDetailsList ??
                    new List <ASRVMNicDetails>();

                var vmNic =
                    vmNicDetailsList.FirstOrDefault(
                        nic => nic.NicId.Equals(
                            this.NicId, StringComparison.OrdinalIgnoreCase));

                if (vmNic == null)
                {
                    this.WriteWarning(string.Format(Resources.NicNotFoundInVM, this.NicId));
                    return;
                }

                if (this.IPConfig != null)
                {
                    if (!ValidateAndPopulateIPConfigs(vmNic))
                    {
                        return;
                    }
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryVMNetworkId)))
                {
                    this.RecoveryVMNetworkId =
                        this.ReplicationProtectedItem.SelectedRecoveryAzureNetworkId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.RecoveryNetworkSecurityGroupId)))
                {
                    this.RecoveryNetworkSecurityGroupId = vmNic.RecoveryNetworkSecurityGroupId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() =>
                                                this.EnableAcceleratedNetworkingOnRecovery)))
                {
                    this.EnableAcceleratedNetworkingOnRecovery =
                        vmNic.EnableAcceleratedNetworkingOnRecovery ?? false;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoVMNetworkId)))
                {
                    this.TfoVMNetworkId =
                        this.ReplicationProtectedItem.SelectedTfoAzureNetworkId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() => this.TfoNetworkSecurityGroupId)))
                {
                    this.TfoNetworkSecurityGroupId = vmNic.TfoNetworkSecurityGroupId;
                }

                if (!this.MyInvocation.BoundParameters.ContainsKey(
                        Utilities.GetMemberName(() =>
                                                this.EnableAcceleratedNetworkingOnTfo)))
                {
                    this.EnableAcceleratedNetworkingOnTfo =
                        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,
                    RecoveryVMNetworkId                   = this.RecoveryVMNetworkId,
                    RecoveryNicName                       = this.RecoveryNicName,
                    RecoveryNicResourceGroupName          = this.RecoveryNicResourceGroupName,
                    ReuseExistingNic                      = this.ReuseExistingNic,
                    RecoveryNetworkSecurityGroupId        = this.RecoveryNetworkSecurityGroupId,
                    EnableAcceleratedNetworkingOnRecovery =
                        this.EnableAcceleratedNetworkingOnRecovery,
                    IPConfigs                        = ipConfigList,
                    TfoVMNetworkId                   = this.TfoVMNetworkId,
                    TfoNicName                       = this.TfoNicName,
                    TfoNicResourceGroupName          = this.TfoNicResourceGroupName,
                    TfoReuseExistingNic              = this.TfoReuseExistingNic,
                    TfoNetworkSecurityGroupId        = this.TfoNetworkSecurityGroupId,
                    EnableAcceleratedNetworkingOnTfo = this.EnableAcceleratedNetworkingOnTfo
                };

                break;
            }

            this.WriteObject(nicConfig);
        }