Пример #1
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);
        }