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
     });
 }
        // validates IP configs and populate values not provided in input from DB NIC entiry.
        // returns false in case of validation error.
        private bool ValidateAndPopulateIPConfigs(ASRVMNicDetails vmNic)
        {
            bool isTfoNetworkRequired      = false;
            bool isRecoveryNetworkRequired = false;

            foreach (var ipConfig in this.IPConfig)
            {
                if (!string.IsNullOrEmpty(ipConfig.TfoSubnetName))
                {
                    isTfoNetworkRequired = true;
                }

                if (!string.IsNullOrEmpty(ipConfig.RecoverySubnetName))
                {
                    isRecoveryNetworkRequired = true;
                }

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

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

                ipConfig.IsPrimary = (bool)vmNicIPConfig.IsPrimary;
                if (string.IsNullOrEmpty(ipConfig.RecoverySubnetName))
                {
                    ipConfig.RecoverySubnetName = vmNicIPConfig.RecoverySubnetName;
                }

                if (ipConfig.RecoveryStaticIPAddress == null)
                {
                    ipConfig.RecoveryStaticIPAddress = vmNicIPConfig.RecoveryStaticIPAddress;
                }

                if (ipConfig.RecoveryPublicIPAddressId == null)
                {
                    ipConfig.RecoveryPublicIPAddressId = vmNicIPConfig.RecoveryPublicIPAddressId;
                }

                if (ipConfig.RecoveryLBBackendAddressPoolIds == null)
                {
                    ipConfig.RecoveryLBBackendAddressPoolIds = vmNicIPConfig.RecoveryLBBackendAddressPoolIds;
                }

                if (string.IsNullOrEmpty(ipConfig.TfoSubnetName))
                {
                    ipConfig.TfoSubnetName = vmNicIPConfig.TfoSubnetName;
                }

                if (ipConfig.TfoStaticIPAddress == null)
                {
                    ipConfig.TfoStaticIPAddress = vmNicIPConfig.TfoStaticIPAddress;
                }

                if (ipConfig.TfoPublicIPAddressId == null)
                {
                    ipConfig.TfoPublicIPAddressId = vmNicIPConfig.TfoPublicIPAddressId;
                }

                if (ipConfig.TfoLBBackendAddressPoolIds == null)
                {
                    ipConfig.TfoLBBackendAddressPoolIds = vmNicIPConfig.TfoLBBackendAddressPoolIds;
                }
            }

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

            if (isRecoveryNetworkRequired && string.IsNullOrEmpty(this.RecoveryVMNetworkId))
            {
                this.WriteWarning(Resources.TfoNetworkInformationMissing);
                return(false);;
            }

            return(true);
        }