Esempio n. 1
0
        public override void Execute()
        {
            base.Execute();

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

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

            var frontendIpConfig = new PSFrontendIPConfiguration();

            frontendIpConfig.Name  = this.Name;
            frontendIpConfig.Zones = this.Zone;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIpConfig.Subnet    = new PSSubnet();
                frontendIpConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    frontendIpConfig.PrivateIpAddress          = this.PrivateIpAddress;
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Static;
                }
                else
                {
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                frontendIpConfig.PublicIpAddress    = new PSPublicIpAddress();
                frontendIpConfig.PublicIpAddress.Id = this.PublicIpAddressId;
            }

            frontendIpConfig.Id =
                ChildResourceHelper.GetResourceId(
                    this.NetworkClient.NetworkManagementClient.SubscriptionId,
                    this.LoadBalancer.ResourceGroupName,
                    this.LoadBalancer.Name,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerFrontendIpConfigName,
                    this.Name);

            this.LoadBalancer.FrontendIpConfigurations.Add(frontendIpConfig);

            WriteObject(this.LoadBalancer);
        }
Esempio n. 2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            // Get the subnetId and publicIpAddressId from the object if specified
            if (string.Equals(ParameterSetName, "object"))
            {
                this.SubnetId = this.Subnet.Id;

                if (PublicIpAddress != null)
                {
                    this.PublicIpAddressId = this.PublicIpAddress.Id;
                }
            }

            var frontendIpConfig = new PSFrontendIPConfiguration();

            frontendIpConfig.Name = this.Name;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIpConfig.Subnet    = new PSResourceId();
                frontendIpConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    frontendIpConfig.PrivateIpAddress          = this.PrivateIpAddress;
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IpAllocationMethod.Static;
                }
                else
                {
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IpAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                frontendIpConfig.PublicIpAddress    = new PSResourceId();
                frontendIpConfig.PublicIpAddress.Id = this.PublicIpAddressId;
            }

            frontendIpConfig.Id =
                ChildResourceHelper.GetResourceNotSetId(
                    this.NetworkClient.NetworkResourceProviderClient.Credentials.SubscriptionId,
                    Microsoft.Azure.Commands.Network.Properties.Resources.LoadBalancerFrontendIpConfigName,
                    this.Name);

            WriteObject(frontendIpConfig);
        }
        public override void Execute()
        {
            base.Execute();

            var frontendIpConfig = new PSFrontendIPConfiguration();

            frontendIpConfig.Name  = this.Name;
            frontendIpConfig.Zones = this.Zone;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIpConfig.Subnet    = new PSSubnet();
                frontendIpConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    frontendIpConfig.PrivateIpAddress          = this.PrivateIpAddress;
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Static;
                }
                else
                {
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IPAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                frontendIpConfig.PublicIpAddress    = new PSPublicIpAddress();
                frontendIpConfig.PublicIpAddress.Id = this.PublicIpAddressId;
            }

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

            WriteObject(frontendIpConfig);
        }
Esempio n. 4
0
        public override void Execute()
        {
            var existingFrontendIpConfiguration = this.LoadBalancer.FrontendIpConfigurations.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

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

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

            if (string.Equals(ParameterSetName, "SetByResourceSubnet"))
            {
                if (this.Subnet != null)
                {
                    this.SubnetId = this.Subnet.Id;
                }
            }

            if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddress"))
            {
                if (this.PublicIpAddress != null)
                {
                    this.PublicIpAddressId = this.PublicIpAddress.Id;
                }
            }

            var vFrontendIpConfigurations = new PSFrontendIPConfiguration();

            vFrontendIpConfigurations.PrivateIpAddress = this.PrivateIpAddress;
            if (!string.IsNullOrEmpty(vFrontendIpConfigurations.PrivateIpAddress))
            {
                vFrontendIpConfigurations.PrivateIpAllocationMethod = "Static";
            }
            else
            {
                vFrontendIpConfigurations.PrivateIpAllocationMethod = "Dynamic";
            }

            vFrontendIpConfigurations.Name  = this.Name;
            vFrontendIpConfigurations.Zones = this.Zone?.ToList();
            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                // Subnet
                if (vFrontendIpConfigurations.Subnet == null)
                {
                    vFrontendIpConfigurations.Subnet = new PSSubnet();
                }
                vFrontendIpConfigurations.Subnet.Id = this.SubnetId;
            }
            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                // PublicIpAddress
                if (vFrontendIpConfigurations.PublicIpAddress == null)
                {
                    vFrontendIpConfigurations.PublicIpAddress = new PSPublicIpAddress();
                }
                vFrontendIpConfigurations.PublicIpAddress.Id = this.PublicIpAddressId;
            }
            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,
                "FrontendIpConfigurations",
                this.Name);

            vFrontendIpConfigurations.Id = generatedId;

            this.LoadBalancer.FrontendIpConfigurations.Add(vFrontendIpConfigurations);
            WriteObject(this.LoadBalancer, true);
        }
Esempio n. 5
0
        public override void Execute()
        {
            var vFrontendIPConfigurationsIndex = this.LoadBalancer.FrontendIpConfigurations.IndexOf(
                this.LoadBalancer.FrontendIpConfigurations.SingleOrDefault(
                    resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase)));

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

            if (string.Equals(ParameterSetName, "SetByResourceSubnet"))
            {
                if (this.Subnet != null)
                {
                    this.SubnetId = this.Subnet.Id;
                }
            }

            if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddress"))
            {
                if (this.PublicIpAddress != null)
                {
                    this.PublicIpAddressId = this.PublicIpAddress.Id;
                }
            }

            if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddressPrefix"))
            {
                if (this.PublicIpAddressPrefix != null)
                {
                    this.PublicIpAddressPrefixId = this.PublicIpAddressPrefix.Id;
                }
            }

            var vFrontendIpConfigurations = new PSFrontendIPConfiguration();

            vFrontendIpConfigurations.PrivateIpAddress        = this.PrivateIpAddress;
            vFrontendIpConfigurations.PrivateIpAddressVersion = this.PrivateIpAddressVersion;
            if (!string.IsNullOrEmpty(vFrontendIpConfigurations.PrivateIpAddress))
            {
                vFrontendIpConfigurations.PrivateIpAllocationMethod = "Static";
            }
            else
            {
                vFrontendIpConfigurations.PrivateIpAllocationMethod = "Dynamic";
            }

            vFrontendIpConfigurations.Name  = this.Name;
            vFrontendIpConfigurations.Zones = this.Zone?.ToList();
            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                // Subnet
                if (vFrontendIpConfigurations.Subnet == null)
                {
                    vFrontendIpConfigurations.Subnet = new PSSubnet();
                }
                vFrontendIpConfigurations.Subnet.Id = this.SubnetId;
            }

            if (!string.IsNullOrEmpty(this.GatewayLoadBalancerId))
            {
                // Gateway
                if (vFrontendIpConfigurations.GatewayLoadBalancer == null)
                {
                    vFrontendIpConfigurations.GatewayLoadBalancer = new PSFrontendIPConfiguration();
                }
                vFrontendIpConfigurations.GatewayLoadBalancer.Id = this.GatewayLoadBalancerId;
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                // PublicIpAddress
                if (vFrontendIpConfigurations.PublicIpAddress == null)
                {
                    vFrontendIpConfigurations.PublicIpAddress = new PSPublicIpAddress();
                }
                vFrontendIpConfigurations.PublicIpAddress.Id = this.PublicIpAddressId;
            }
            if (!string.IsNullOrEmpty(this.PublicIpAddressPrefixId))
            {
                // PublicIpAddressPrefix
                if (vFrontendIpConfigurations.PublicIPPrefix == null)
                {
                    vFrontendIpConfigurations.PublicIPPrefix = new PSPublicIpPrefix();
                }
                vFrontendIpConfigurations.PublicIPPrefix.Id = this.PublicIpAddressPrefixId;
            }
            this.LoadBalancer.FrontendIpConfigurations[vFrontendIPConfigurationsIndex] = vFrontendIpConfigurations;
            WriteObject(this.LoadBalancer, true);
        }
        public override void Execute()
        {
            if (string.Equals(ParameterSetName, "SetByResourceSubnet"))
            {
                if (this.Subnet != null)
                {
                    this.SubnetId = this.Subnet.Id;
                }
            }

            if (string.Equals(ParameterSetName, "SetByResourcePublicIpAddress"))
            {
                if (this.PublicIpAddress != null)
                {
                    this.PublicIpAddressId = this.PublicIpAddress.Id;
                }
            }
            var vFrontendIpConfigurations = new PSFrontendIPConfiguration();

            vFrontendIpConfigurations.PrivateIpAddress        = this.PrivateIpAddress;
            vFrontendIpConfigurations.PrivateIpAddressVersion = this.PrivateIpAddressVersion;
            if (!string.IsNullOrEmpty(vFrontendIpConfigurations.PrivateIpAddress))
            {
                vFrontendIpConfigurations.PrivateIpAllocationMethod = "Static";
            }
            else
            {
                vFrontendIpConfigurations.PrivateIpAllocationMethod = "Dynamic";
            }

            vFrontendIpConfigurations.Name  = this.Name;
            vFrontendIpConfigurations.Zones = this.Zone?.ToList();
            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                // Subnet
                if (vFrontendIpConfigurations.Subnet == null)
                {
                    vFrontendIpConfigurations.Subnet = new PSSubnet();
                }
                vFrontendIpConfigurations.Subnet.Id = this.SubnetId;
            }
            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                // PublicIpAddress
                if (vFrontendIpConfigurations.PublicIpAddress == null)
                {
                    vFrontendIpConfigurations.PublicIpAddress = new PSPublicIpAddress();
                }
                vFrontendIpConfigurations.PublicIpAddress.Id = this.PublicIpAddressId;
            }
            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,
                "FrontendIpConfigurations",
                this.Name);

            vFrontendIpConfigurations.Id = generatedId;

            WriteObject(vFrontendIpConfigurations, true);
        }
Esempio n. 7
0
        public override void Execute()
        {
            base.Execute();

            // DestinationNetworkInterfaceIPConfiguration
            PSNetworkInterfaceIPConfiguration vDestinationNetworkInterfaceIPConfiguration = null;

            // DestinationLoadBalancerFrontEndIPConfiguration
            PSFrontendIPConfiguration vDestinationLoadBalancerFrontEndIPConfiguration = null;


            if (string.Equals(ParameterSetName, Microsoft.Azure.Commands.Network.Properties.Resources.SetByResource))
            {
                if (this.DestinationNetworkInterfaceIPConfiguration != null)
                {
                    this.DestinationNetworkInterfaceIPConfigurationId = this.DestinationNetworkInterfaceIPConfiguration.Id;
                }
                if (this.DestinationLoadBalancerFrontEndIPConfiguration != null)
                {
                    this.DestinationLoadBalancerFrontEndIPConfigurationId = this.DestinationLoadBalancerFrontEndIPConfiguration.Id;
                }
            }

            if (this.DestinationNetworkInterfaceIPConfigurationId != null)
            {
                if (vDestinationNetworkInterfaceIPConfiguration == null)
                {
                    vDestinationNetworkInterfaceIPConfiguration = new PSNetworkInterfaceIPConfiguration();
                }
                vDestinationNetworkInterfaceIPConfiguration.Id = this.DestinationNetworkInterfaceIPConfigurationId;
            }

            if (this.DestinationLoadBalancerFrontEndIPConfigurationId != null)
            {
                if (vDestinationLoadBalancerFrontEndIPConfiguration == null)
                {
                    vDestinationLoadBalancerFrontEndIPConfiguration = new PSFrontendIPConfiguration();
                }
                vDestinationLoadBalancerFrontEndIPConfiguration.Id = this.DestinationLoadBalancerFrontEndIPConfigurationId;
            }


            var vVirtualNetworkTap = new PSVirtualNetworkTap
            {
                DestinationPort = this.DestinationPort,
                Location        = this.Location,
                DestinationNetworkInterfaceIPConfiguration     = vDestinationNetworkInterfaceIPConfiguration,
                DestinationLoadBalancerFrontEndIPConfiguration = vDestinationLoadBalancerFrontEndIPConfiguration,
            };

            var vVirtualNetworkTapModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualNetworkTap>(vVirtualNetworkTap);

            vVirtualNetworkTapModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);
            var present = true;

            try
            {
                this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.Get(this.ResourceGroupName, this.Name);
            }
            catch (Microsoft.Rest.Azure.CloudException exception)
            {
                if (exception.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    // Resource is not present
                    present = false;
                }
                else
                {
                    throw;
                }
            }

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () =>
            {
                this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.CreateOrUpdate(this.ResourceGroupName, this.Name, vVirtualNetworkTapModel);
                var getVirtualNetworkTap = this.NetworkClient.NetworkManagementClient.VirtualNetworkTaps.Get(this.ResourceGroupName, this.Name);
                var psVirtualNetworkTap  = NetworkResourceManagerProfile.Mapper.Map <PSVirtualNetworkTap>(getVirtualNetworkTap);
                psVirtualNetworkTap.ResourceGroupName = this.ResourceGroupName;
                psVirtualNetworkTap.Tag = TagsConversionHelper.CreateTagHashtable(getVirtualNetworkTap.Tags);
                WriteObject(psVirtualNetworkTap, true);
            },
                () => present);
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

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

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


            // Get the subnetId and publicIpAddressId from the object if specified
            if (string.Equals(ParameterSetName, "id"))
            {
                this.SubnetId = this.Subnet.Id;

                if (PublicIpAddress != null)
                {
                    this.PublicIpAddressId = this.PublicIpAddress.Id;
                }
            }

            var frontendIpConfig = new PSFrontendIPConfiguration();

            frontendIpConfig.Name = this.Name;

            if (!string.IsNullOrEmpty(this.SubnetId))
            {
                frontendIpConfig.Subnet    = new PSResourceId();
                frontendIpConfig.Subnet.Id = this.SubnetId;

                if (!string.IsNullOrEmpty(this.PrivateIpAddress))
                {
                    frontendIpConfig.PrivateIpAddress          = this.PrivateIpAddress;
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IpAllocationMethod.Static;
                }
                else
                {
                    frontendIpConfig.PrivateIpAllocationMethod = Management.Network.Models.IpAllocationMethod.Dynamic;
                }
            }

            if (!string.IsNullOrEmpty(this.PublicIpAddressId))
            {
                frontendIpConfig.PublicIpAddress    = new PSResourceId();
                frontendIpConfig.PublicIpAddress.Id = this.PublicIpAddressId;
            }

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

            this.LoadBalancer.FrontendIpConfigurations.Add(frontendIpConfig);

            WriteObject(this.LoadBalancer);
        }