Example #1
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.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);
        }
Example #2
0
        public override void Execute()
        {
            // Old params provided - Get the virtual network, get the public IP address
            if (!string.IsNullOrEmpty(VirtualNetworkName))
            {
                var vnet = this.VirtualNetworkClient.Get(this.ResourceGroupName, VirtualNetworkName);
                this.virtualNetwork = NetworkResourceManagerProfile.Mapper.Map <PSVirtualNetwork>(vnet);

                var publicIp = this.PublicIPAddressesClient.Get(this.ResourceGroupName, PublicIpName);
                this.publicIpAddresses = new PSPublicIpAddress[]
                {
                    NetworkResourceManagerProfile.Mapper.Map <PSPublicIpAddress>(publicIp)
                };
            }
            // New params
            else if (VirtualNetwork != null)
            {
                this.virtualNetwork    = VirtualNetwork;
                this.publicIpAddresses = PublicIpAddress;
            }

            base.Execute();

            var present = this.IsAzureFirewallPresent(this.ResourceGroupName, this.Name);

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () => WriteObject(this.CreateAzureFirewall()),
                () => present);
        }
        public override void Execute()
        {
            var isVnetPresent = VirtualNetworkName != null;

            // Get the virtual network, get the public IP address
            if (isVnetPresent)
            {
                var vnet = this.VirtualNetworkClient.Get(this.ResourceGroupName, VirtualNetworkName);
                this.virtualNetwork = NetworkResourceManagerProfile.Mapper.Map <PSVirtualNetwork>(vnet);

                var publicIp = this.PublicIPAddressesClient.Get(this.ResourceGroupName, PublicIpName);
                this.publicIpAddress = NetworkResourceManagerProfile.Mapper.Map <PSPublicIpAddress>(publicIp);
            }

            base.Execute();

            var present = this.IsAzureFirewallPresent(this.ResourceGroupName, this.Name);

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.OverwritingResource, Name),
                Properties.Resources.CreatingResourceMessage,
                Name,
                () => WriteObject(this.CreateAzureFirewall()),
                () => present);
        }
Example #4
0
        private PSVirtualNetwork CreateVirtualNetwork()
        {
            var vnet = new PSVirtualNetwork
            {
                Name = Name,
                ResourceGroupName = ResourceGroupName,
                Location          = Location,
                AddressSpace      = new PSAddressSpace {
                    AddressPrefixes = AddressPrefix?.ToList()
                }
            };

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

            vnet.Subnets = this.Subnet?.ToList();
            vnet.EnableDdosProtection = EnableDdosProtection;

            if (!string.IsNullOrEmpty(DdosProtectionPlanId))
            {
                vnet.DdosProtectionPlan = new PSResourceId {
                    Id = DdosProtectionPlanId
                };
            }

            if (!string.IsNullOrWhiteSpace(BgpCommunity))
            {
                vnet.BgpCommunities = new PSVirtualNetworkBgpCommunities {
                    VirtualNetworkCommunity = this.BgpCommunity
                };
            }

            // Map to the sdk object
            var vnetModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualNetwork>(vnet);

            vnetModel.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);

            if (this.IpAllocation != null)
            {
                foreach (var ipAllocation in this.IpAllocation)
                {
                    var ipAllocationReference = new MNM.SubResource(ipAllocation.Id);
                    vnetModel.IpAllocations.Add(ipAllocationReference);
                }
            }

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

            var getVirtualNetwork = GetVirtualNetwork(ResourceGroupName, Name);

            return(getVirtualNetwork);
        }
        private PSVirtualNetwork CreateVirtualNetwork()
        {
            var vnet = new PSVirtualNetwork
            {
                Name = Name,
                ResourceGroupName = ResourceGroupName,
                Location          = Location,
                AddressSpace      = new PSAddressSpace {
                    AddressPrefixes = AddressPrefix
                }
            };

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

            vnet.Subnets = Subnet;
            vnet.EnableDdosProtection = EnableDdosProtection;

            if (!string.IsNullOrEmpty(DdosProtectionPlanId))
            {
                vnet.DdosProtectionPlan = new PSResourceId {
                    Id = DdosProtectionPlanId
                };
            }

            // Map to the sdk object
            var vnetModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualNetwork>(vnet);

            vnetModel.Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true);

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

            var getVirtualNetwork = GetVirtualNetwork(ResourceGroupName, Name);

            return(getVirtualNetwork);
        }
        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 = this.Subnet;
            vnet.EnableDdosProtection = this.EnableDdosProtection;
            vnet.EnableVmProtection   = this.EnableVmProtection;

            if (!string.IsNullOrEmpty(this.DdosProtectionPlanId))
            {
                vnet.DdosProtectionPlan    = new PSResourceId();
                vnet.DdosProtectionPlan.Id = this.DdosProtectionPlanId;
            }

            // Map to the sdk object
            var vnetModel = NetworkResourceManagerProfile.Mapper.Map <MNM.VirtualNetwork>(vnet);

            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);
        }