Beispiel #1
0
        public override void Execute()
        {
            base.Execute();

            var inboundNatRule = new PSInboundNatRule();

            inboundNatRule.Name         = this.Name;
            inboundNatRule.Protocol     = this.Protocol;
            inboundNatRule.FrontendPort = this.FrontendPort;
            inboundNatRule.BackendPort  = this.BackendPort;
            if (this.IdleTimeoutInMinutes > 0)
            {
                inboundNatRule.IdleTimeoutInMinutes = this.IdleTimeoutInMinutes;
            }
            inboundNatRule.EnableFloatingIP = this.EnableFloatingIP.IsPresent;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                inboundNatRule.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            inboundNatRule.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInBoundNatRuleName,
                    this.Name);

            WriteObject(inboundNatRule);
        }
        public override void Execute()
        {
            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.FrontendIpConfiguration != null)
                {
                    this.FrontendIpConfigurationId = this.FrontendIpConfiguration.Id;
                }

                if (this.BackendAddressPool != null)
                {
                    this.BackendAddressPoolId = this.BackendAddressPool.Id;
                }
            }
            var vInboundNatRules = new PSInboundNatRule();

            vInboundNatRules.Protocol             = this.Protocol;
            vInboundNatRules.FrontendPort         = this.FrontendPort;
            vInboundNatRules.BackendPort          = this.BackendPort;
            vInboundNatRules.IdleTimeoutInMinutes = this.MyInvocation.BoundParameters.ContainsKey("IdleTimeoutInMinutes") ? this.IdleTimeoutInMinutes : 4;
            vInboundNatRules.EnableFloatingIP     = this.EnableFloatingIP;
            vInboundNatRules.EnableTcpReset       = this.EnableTcpReset;
            vInboundNatRules.Name = this.Name;
            vInboundNatRules.FrontendPortRangeStart = this.FrontendPortRangeStart;
            vInboundNatRules.FrontendPortRangeEnd   = this.FrontendPortRangeEnd;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                // FrontendIPConfiguration
                if (vInboundNatRules.FrontendIPConfiguration == null)
                {
                    vInboundNatRules.FrontendIPConfiguration = new PSResourceId();
                }
                vInboundNatRules.FrontendIPConfiguration.Id = this.FrontendIpConfigurationId;
            }

            if (!string.IsNullOrEmpty(this.BackendAddressPoolId))
            {
                // BackendAddressPool
                if (vInboundNatRules.BackendAddressPool == null)
                {
                    vInboundNatRules.BackendAddressPool = new PSResourceId();
                }
                vInboundNatRules.BackendAddressPool.Id = this.BackendAddressPoolId;
            }

            var generatedId = string.Format(
                "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
                this.NetworkClient.NetworkManagementClient.SubscriptionId,
                Microsoft.Azure.Commands.Network.Properties.Resources.ResourceGroupNotSet,
                Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerNameNotSet,
                "InboundNatRules",
                this.Name);

            vInboundNatRules.Id = generatedId;

            WriteObject(vInboundNatRules, true);
        }
        public override void Execute()
        {
            var vInboundNatRulesIndex = this.LoadBalancer.InboundNatRules.IndexOf(
                this.LoadBalancer.InboundNatRules.SingleOrDefault(
                    resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)));

            if (vInboundNatRulesIndex == -1)
            {
                throw new ArgumentException("InboundNatRules with the specified name does not exist");
            }

            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.FrontendIpConfiguration != null)
                {
                    this.FrontendIpConfigurationId = this.FrontendIpConfiguration.Id;
                }

                if (this.BackendAddressPool != null)
                {
                    this.BackendAddressPoolId = this.BackendAddressPool.Id;
                }
            }
            var vInboundNatRules = new PSInboundNatRule();

            vInboundNatRules.Protocol             = this.Protocol;
            vInboundNatRules.FrontendPort         = this.FrontendPort;
            vInboundNatRules.BackendPort          = this.BackendPort;
            vInboundNatRules.IdleTimeoutInMinutes = this.MyInvocation.BoundParameters.ContainsKey("IdleTimeoutInMinutes") ? this.IdleTimeoutInMinutes : 4;
            vInboundNatRules.EnableFloatingIP     = this.EnableFloatingIP;
            vInboundNatRules.EnableTcpReset       = this.EnableTcpReset;
            vInboundNatRules.Name = this.Name;
            vInboundNatRules.FrontendPortRangeStart = this.FrontendPortRangeStart;
            vInboundNatRules.FrontendPortRangeEnd   = this.FrontendPortRangeEnd;
            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                // FrontendIPConfiguration
                if (vInboundNatRules.FrontendIPConfiguration == null)
                {
                    vInboundNatRules.FrontendIPConfiguration = new PSResourceId();
                }
                vInboundNatRules.FrontendIPConfiguration.Id = this.FrontendIpConfigurationId;
            }

            if (!string.IsNullOrEmpty(this.BackendAddressPoolId))
            {
                // BackendAddressPool
                if (vInboundNatRules.BackendAddressPool == null)
                {
                    vInboundNatRules.BackendAddressPool = new PSResourceId();
                }
                vInboundNatRules.BackendAddressPool.Id = this.BackendAddressPoolId;
            }

            this.LoadBalancer.InboundNatRules[vInboundNatRulesIndex] = vInboundNatRules;
            WriteObject(this.LoadBalancer, true);
        }
        public override void Execute()
        {
            var existingInboundNatRule = this.LoadBalancer.InboundNatRules.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingInboundNatRule != null)
            {
                throw new ArgumentException("InboundNatRule with the specified name already exists");
            }

            // InboundNatRules
            if (this.LoadBalancer.InboundNatRules == null)
            {
                this.LoadBalancer.InboundNatRules = new List <PSInboundNatRule>();
            }

            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.FrontendIpConfiguration != null)
                {
                    this.FrontendIpConfigurationId = this.FrontendIpConfiguration.Id;
                }
            }

            var vInboundNatRules = new PSInboundNatRule();

            vInboundNatRules.Protocol             = this.Protocol;
            vInboundNatRules.FrontendPort         = this.FrontendPort;
            vInboundNatRules.BackendPort          = this.BackendPort;
            vInboundNatRules.IdleTimeoutInMinutes = this.MyInvocation.BoundParameters.ContainsKey("IdleTimeoutInMinutes") ? this.IdleTimeoutInMinutes : 4;
            vInboundNatRules.EnableFloatingIP     = this.EnableFloatingIP;
            vInboundNatRules.EnableTcpReset       = this.EnableTcpReset;
            vInboundNatRules.Name = this.Name;
            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                // FrontendIPConfiguration
                if (vInboundNatRules.FrontendIPConfiguration == null)
                {
                    vInboundNatRules.FrontendIPConfiguration = new PSResourceId();
                }
                vInboundNatRules.FrontendIPConfiguration.Id = this.FrontendIpConfigurationId;
            }
            var generatedId = string.Format(
                "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Network/loadBalancers/{2}/{3}/{4}",
                this.NetworkClient.NetworkManagementClient.SubscriptionId,
                this.LoadBalancer.ResourceGroupName,
                this.LoadBalancer.Name,
                "InboundNatRules",
                this.Name);

            vInboundNatRules.Id = generatedId;

            this.LoadBalancer.InboundNatRules.Add(vInboundNatRules);
            WriteObject(this.LoadBalancer, true);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var existingInboundNatRule = this.LoadBalancer.InboundNatRules.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

            if (existingInboundNatRule != null)
            {
                throw new ArgumentException("InboundNatRule with the specified name already exists");
            }

            var inboundNatRule = new PSInboundNatRule();

            inboundNatRule.Name         = this.Name;
            inboundNatRule.Protocol     = this.Protocol;
            inboundNatRule.FrontendPort = this.FrontendPort;
            inboundNatRule.BackendPort  = this.BackendPort;
            if (this.IdleTimeoutInMinutes > 0)
            {
                inboundNatRule.IdleTimeoutInMinutes = this.IdleTimeoutInMinutes;
            }
            inboundNatRule.EnableFloatingIP = this.EnableFloatingIP.IsPresent;

            if (!string.IsNullOrEmpty(this.FrontendIpConfigurationId))
            {
                inboundNatRule.FrontendIPConfiguration = new PSResourceId()
                {
                    Id = this.FrontendIpConfigurationId
                };
            }

            inboundNatRule.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerInBoundNatRuleName,
                    this.Name);

            this.LoadBalancer.InboundNatRules.Add(inboundNatRule);

            WriteObject(this.LoadBalancer);
        }