Наследование: PSChildResource
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

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

                if (this.RouteTable != null)
                {
                    this.RouteTableId = this.RouteTable.Id;
                }
            }

            var subnet = new PSSubnet();
            subnet.Name = this.Name;
            subnet.AddressPrefix = this.AddressPrefix;

            if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId))
            {
                subnet.NetworkSecurityGroup = new PSResourceId();
                subnet.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId;
            }

            if (!string.IsNullOrEmpty(this.RouteTableId))
            {
                subnet.RouteTable = new PSResourceId();
                subnet.RouteTable.Id = this.RouteTableId;
            }

            WriteObject(subnet);
        }
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            // Verify if the subnet exists in the VirtualNetwork
            var subnet = this.VirtualNetwork.Subnets.SingleOrDefault(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

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

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

            subnet = new PSSubnet();

            subnet.Name = this.Name;
            subnet.AddressPrefix = this.AddressPrefix;
            
            if (!string.IsNullOrEmpty(this.NetworkSecurityGroupId))
            {
                subnet.NetworkSecurityGroup = new PSResourceId();
                subnet.NetworkSecurityGroup.Id = this.NetworkSecurityGroupId;
            }

            this.VirtualNetwork.Subnets.Add(subnet);

            WriteObject(this.VirtualNetwork);
        }
Пример #3
0
        public void Allocate(PSVirtualNetwork virtualNetwork, PSPublicIpAddress[] publicIpAddresses)
        {
            if (virtualNetwork == null)
            {
                throw new ArgumentNullException(nameof(virtualNetwork), "Virtual Network cannot be null!");
            }

            if (publicIpAddresses == null || publicIpAddresses.Count() == 0)
            {
                throw new ArgumentNullException(nameof(publicIpAddresses), "Public IP Addresses cannot be null or empty!");
            }

            PSSubnet firewallSubnet = null;

            try
            {
                firewallSubnet = virtualNetwork.Subnets.Single(subnet => AzureFirewallSubnetName.Equals(subnet.Name));
            }
            catch (InvalidOperationException)
            {
                throw new ArgumentException($"Virtual Network {virtualNetwork.Name} should contain a Subnet named {AzureFirewallSubnetName}");
            }

            this.IpConfigurations = new List <PSAzureFirewallIpConfiguration>();

            for (var i = 0; i < publicIpAddresses.Count(); i++)
            {
                this.IpConfigurations.Add(
                    new PSAzureFirewallIpConfiguration
                {
                    Name            = $"{AzureFirewallIpConfigurationName}{i}",
                    PublicIpAddress = new PSResourceId {
                        Id = publicIpAddresses[i].Id
                    }
                });
            }

            this.IpConfigurations[0].Subnet = new PSResourceId {
                Id = firewallSubnet.Id
            };
        }
Пример #4
0
        public void Allocate(PSVirtualNetwork virtualNetwork, PSPublicIpAddress publicIpAddress)
        {
            if (virtualNetwork == null)
            {
                throw new ArgumentNullException(nameof(virtualNetwork), "Virtual Network cannot be null!");
            }

            if (publicIpAddress == null)
            {
                throw new ArgumentNullException(nameof(publicIpAddress), "Public IP Addresses cannot be null or empty!");
            }

            //proper error message
            PSSubnet BastionSubnet = null;

            try
            {
                BastionSubnet = virtualNetwork.Subnets.Single(subnet => BastionSubnetName.Equals(subnet.Name, StringComparison.OrdinalIgnoreCase));
            }

            catch (InvalidOperationException)
            {
                throw new ArgumentException($"Virtual Network {virtualNetwork.Name} should contain a Subnet named {BastionSubnetName}");
            }

            this.IpConfigurations = new List <PSBastionIPConfiguration>();

            this.IpConfigurations.Add(
                new PSBastionIPConfiguration
            {
                Name            = BastionIpConfigurationName,
                PublicIpAddress = new PSResourceId {
                    Id = publicIpAddress.Id
                },
            });

            this.IpConfigurations[0].Subnet = new PSResourceId {
                Id = BastionSubnet.Id
            };
        }
Пример #5
0
        public void Allocate(PSVirtualNetwork virtualNetwork, PSPublicIpAddress publicIpAddress)
        {
            if (virtualNetwork == null)
            {
                throw new ArgumentNullException(nameof(virtualNetwork), "Virtual Network cannot be null!");
            }

            if (publicIpAddress == null)
            {
                throw new ArgumentNullException(nameof(publicIpAddress), "Public IP Address cannot be null!");
            }

            PSSubnet firewallSubnet = null;

            try
            {
                firewallSubnet = virtualNetwork.Subnets.Single(subnet => AzureFirewallSubnetName.Equals(subnet.Name));
            }
            catch (InvalidOperationException)
            {
                throw new ArgumentException($"Virtual Network {virtualNetwork.Name} should contain a Subnet named {AzureFirewallSubnetName}");
            }

            this.IpConfigurations = new List <PSAzureFirewallIpConfiguration>
            {
                new PSAzureFirewallIpConfiguration
                {
                    Name   = AzureFirewallIpConfigurationName,
                    Subnet = new PSResourceId {
                        Id = firewallSubnet.Id
                    },
                    PublicIpAddress = new PSResourceId {
                        Id = publicIpAddress.Id
                    }
                }
            };
        }