Inheritance: PSTopLevelResource
コード例 #1
0
        public void SetManagementIpConfiguration(PSVirtualNetwork virtualNetwork, PSPublicIpAddress publicIpAddress)
        {
            if (publicIpAddress == null)
            {
                throw new ArgumentNullException(nameof(publicIpAddress), "Public IP Address cannot be null!");
            }

            if (virtualNetwork == null)
            {
                throw new ArgumentNullException(nameof(virtualNetwork), "Virtual Network cannot be null!");
            }

            PSSubnet subnet = null;

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

            this.ManagementIpConfiguration = new PSAzureFirewallIpConfiguration
            {
                Name            = AzureFirewallMgmtIpConfigurationName,
                PublicIpAddress = new PSResourceId {
                    Id = publicIpAddress.Id
                },
                Subnet = new PSResourceId {
                    Id = subnet.Id
                }
            };
        }
コード例 #2
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
            };
        }
コード例 #3
0
ファイル: PSBastion.cs プロジェクト: pixia/azure-powershell
        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
            };
        }
コード例 #4
0
        private PSVirtualNetwork CreateVirtualNetwork()
        {
            var vnet = new PSVirtualNetwork();
            vnet.Name = this.Name;
            vnet.ResourceGroupName = this.ResourceGroupName;
            vnet.Location = this.Location;
            vnet.AddressSpace = new PSAddressSpace();
            vnet.AddressSpace.AddressPrefixes = this.AddressPrefix;

            if (this.DnsServer != null)
            {
                vnet.DhcpOptions = new PSDhcpOptions();
                vnet.DhcpOptions.DnsServers = this.DnsServer;
            }

            vnet.Subnets = new List<PSSubnet>();
            vnet.Subnets = this.Subnet;

            // Map to the sdk object
            var vnetModel = Mapper.Map<MNM.VirtualNetwork>(vnet);
            vnetModel.Type = Microsoft.Azure.Commands.Network.Properties.Resources.VirtualNetworkType;
            vnetModel.Tags = TagsConversionHelper.CreateTagDictionary(this.Tag, validate: true);

            // Execute the Create VirtualNetwork call
            this.VirtualNetworkClient.CreateOrUpdate(this.ResourceGroupName, this.Name, vnetModel);

            var getVirtualNetwork = this.GetVirtualNetwork(this.ResourceGroupName, this.Name);

            return getVirtualNetwork;
        }