コード例 #1
0
        private PSVirtualNetworkGatewayNatRule CreateVpnGatewayNatRule()
        {
            PSVirtualNetworkGatewayNatRule gatewayNatRule = new PSVirtualNetworkGatewayNatRule
            {
                Name = this.Name,
                Mode = this.Mode,
                VirtualNetworkGatewayNatRulePropertiesType = this.Type,
                InternalMappings  = new List <PSVpnNatRuleMapping>(),
                ExternalMappings  = new List <PSVpnNatRuleMapping>(),
                IpConfigurationId = this.IpConfigurationId,
            };

            if (this.InternalMapping != null)
            {
                foreach (string internalMappingSubnet in this.InternalMapping)
                {
                    var internalMapping = new PSVpnNatRuleMapping();
                    internalMapping.AddressSpace = internalMappingSubnet;
                    gatewayNatRule.InternalMappings.Add(internalMapping);
                }
            }

            if (this.ExternalMapping != null)
            {
                foreach (string externalMappingSubnet in this.ExternalMapping)
                {
                    var externalMapping = new PSVpnNatRuleMapping();
                    externalMapping.AddressSpace = externalMappingSubnet;
                    gatewayNatRule.ExternalMappings.Add(externalMapping);
                }
            }

            return(gatewayNatRule);
        }
コード例 #2
0
        private PSVirtualNetworkGatewayNatRule CreateVpnGatewayNatRule()
        {
            PSVirtualNetworkGatewayNatRule gatewayNatRule = new PSVirtualNetworkGatewayNatRule
            {
                Name = this.Name,
                Mode = this.Mode,
                VirtualNetworkGatewayNatRulePropertiesType = this.Type,
                InternalMappings  = new List <PSVpnNatRuleMapping>(),
                ExternalMappings  = new List <PSVpnNatRuleMapping>(),
                IpConfigurationId = this.IpConfigurationId,
            };

            if (this.InternalMapping != null)
            {
                foreach (string internalMappingSubnet in this.InternalMapping)
                {
                    var internalMapping = new PSVpnNatRuleMapping();
                    internalMapping.AddressSpace = internalMappingSubnet;
                    gatewayNatRule.InternalMappings.Add(internalMapping);
                }
            }

            if (this.ExternalMapping != null)
            {
                foreach (string externalMappingSubnet in this.ExternalMapping)
                {
                    var externalMapping = new PSVpnNatRuleMapping();
                    externalMapping.AddressSpace = externalMappingSubnet;
                    gatewayNatRule.ExternalMappings.Add(externalMapping);
                }
            }

            if (this.InternalPortRange != null)
            {
                if (gatewayNatRule.InternalMappings.Count < this.InternalPortRange.Count())
                {
                    throw new PSArgumentException(string.Format(Properties.Resources.VpnNatRuleUnmatchedPortRange, nameof(InternalPortRange), nameof(InternalMapping)));
                }

                for (int i = 0; i < this.InternalPortRange.Count(); i++)
                {
                    gatewayNatRule.InternalMappings[i].PortRange = this.InternalPortRange[i];
                }
            }

            if (this.ExternalPortRange != null)
            {
                if (gatewayNatRule.ExternalMappings.Count < this.ExternalPortRange.Count())
                {
                    throw new PSArgumentException(string.Format(Properties.Resources.VpnNatRuleUnmatchedPortRange, nameof(ExternalPortRange), nameof(ExternalMapping)));
                }

                for (int i = 0; i < this.ExternalPortRange.Count(); i++)
                {
                    gatewayNatRule.ExternalMappings[i].PortRange = this.ExternalPortRange[i];
                }
            }

            return(gatewayNatRule);
        }
コード例 #3
0
        public PSVirtualNetworkGatewayNatRule CreateOrUpdateVirtualNetworkGatewayNatRule(string resourceGroupName, string virtualNetworkGatewayName, string NatRuleName, PSVirtualNetworkGatewayNatRule virtualNetworkGatewayNatRule)
        {
            var gatewayNatRuleModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualNetworkGatewayNatRule>(virtualNetworkGatewayNatRule);

            var gatewayNatRuleCreatedOrUpdated = this.NatRuleClient.CreateOrUpdate(resourceGroupName, virtualNetworkGatewayName, NatRuleName, gatewayNatRuleModel);
            PSVirtualNetworkGatewayNatRule gatewayNatRuleToReturn = this.ToPsVirtualNetworkGatewayNatRule(gatewayNatRuleCreatedOrUpdated);

            return(gatewayNatRuleToReturn);
        }
コード例 #4
0
        public override void Execute()
        {
            base.Execute();

            if (ParameterSetName.Equals(VirtualNetworkGatewayParameterSets.ByVirtualNetworkGatewayNatRuleObject, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceId = this.InputObject.Id;
            }

            if (!string.IsNullOrWhiteSpace(this.ResourceId))
            {
                var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName  = parsedResourceId.ResourceGroupName;
                this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                this.Name = parsedResourceId.ResourceName;
            }

            if (string.IsNullOrWhiteSpace(this.ResourceGroupName) || string.IsNullOrWhiteSpace(this.ParentResourceName) || string.IsNullOrWhiteSpace(this.Name))
            {
                throw new PSArgumentException(Properties.Resources.VirtualNetworkGatewayNatRuleNotFound);
            }

            //// Get the virtualNetworkgateway object - this will throw not found if the object is not found
            PSVirtualNetworkGateway parentGateway = this.GetVirtualNetworkGateway(this.ResourceGroupName, this.ParentResourceName);

            if (parentGateway == null ||
                parentGateway.NatRules == null ||
                !parentGateway.NatRules.Any(natRule => natRule.Name.Equals(this.Name, StringComparison.OrdinalIgnoreCase)))
            {
                throw new PSArgumentException(Properties.Resources.VirtualNetworkGatewayNatRuleNotFound);
            }

            PSVirtualNetworkGatewayNatRule natRuleToUpdate = null;

            natRuleToUpdate = this.GetVirtualNetworkGatewayNatRule(this.ResourceGroupName, this.ParentResourceName, this.Name);

            if (natRuleToUpdate == null)
            {
                throw new PSArgumentException(Properties.Resources.VirtualNetworkGatewayNatRuleNotFound);
            }


            if (this.IpConfigurationId != null)
            {
                natRuleToUpdate.IpConfigurationId = IpConfigurationId;
            }

            if (this.InternalMapping != null)
            {
                natRuleToUpdate.InternalMappings.Clear();

                foreach (string internalMappingSubnet in this.InternalMapping)
                {
                    var internalMapping = new PSVpnNatRuleMapping();
                    internalMapping.AddressSpace = internalMappingSubnet;
                    natRuleToUpdate.InternalMappings.Add(internalMapping);
                }
            }

            if (this.ExternalMapping != null)
            {
                natRuleToUpdate.ExternalMappings.Clear();

                foreach (string externalMappingSubnet in this.ExternalMapping)
                {
                    var externalMapping = new PSVpnNatRuleMapping();
                    externalMapping.AddressSpace = externalMappingSubnet;
                    natRuleToUpdate.ExternalMappings.Add(externalMapping);
                }
            }

            ConfirmAction(
                Properties.Resources.SettingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.UpdatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateVirtualNetworkGatewayNatRule(this.ResourceGroupName, this.ParentResourceName, this.Name, natRuleToUpdate));
            });
        }