Beispiel #1
0
        public async Task DeleteVirtualNetwork()
        {
            #region Snippet:Managing_Networks_DeleteAVirtualNetwork
            VirtualNetworkCollection virtualNetworkCollection = resourceGroup.GetVirtualNetworks();

            VirtualNetworkResource virtualNetwork = await virtualNetworkCollection.GetAsync("myVnet");

            await virtualNetwork.DeleteAsync(WaitUntil.Completed);

            #endregion
        }
 private async Task CleanUpVirtualNetwork()
 {
     if (virtualNetwork != null)
     {
         await virtualNetwork.DeleteAsync(WaitUntil.Completed);
     }
     if (privateDnsZone != null)
     {
         await privateDnsZone.DeleteAsync(WaitUntil.Completed);
     }
     if (storageAccount != null)
     {
         //await StorageManagementClient.StorageAccounts.DeleteAsync(resourceGroup.Data.Name, storageAccount.Name);
         await storageAccount.DeleteAsync(WaitUntil.Completed);
     }
 }
        public async Task SetGetNetworkRuleSets()
        {
            IgnoreTestInLiveMode();
            //create namespace with premium
            _resourceGroup = await CreateResourceGroupAsync();

            ServiceBusNamespaceCollection namespaceCollection = _resourceGroup.GetServiceBusNamespaces();
            string namespaceName = await CreateValidNamespaceName(namespacePrefix);

            ServiceBusNamespaceData createParameters = new ServiceBusNamespaceData(DefaultLocation);

            createParameters.Sku = new ServiceBusSku(ServiceBusSkuName.Premium)
            {
                Tier = ServiceBusSkuTier.Premium
            };
            ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, createParameters)).Value;

            //prepare vnet
            string vnetName   = Recording.GenerateAssetName("sdktestvnet");
            var    parameters = new VirtualNetworkData
            {
                Subnets =
                {
                    new SubnetData
                    {
                        Name             = "default1",
                        AddressPrefix    = "10.0.0.0/24",
                        ServiceEndpoints ={ new ServiceEndpointPropertiesFormat                        {
                          Service = "Microsoft.ServiceBus"
                      } }
                    },
                    new SubnetData
                    {
                        Name             = "default2",
                        AddressPrefix    = "10.0.1.0/24",
                        ServiceEndpoints ={ new ServiceEndpointPropertiesFormat                        {
                          Service = "Microsoft.ServiceBus"
                      } }
                    },
                    new SubnetData
                    {
                        Name             = "default3",
                        AddressPrefix    = "10.0.2.0/24",
                        ServiceEndpoints ={ new ServiceEndpointPropertiesFormat                        {
                          Service = "Microsoft.ServiceBus"
                      } }
                    }
                },
                Location = "eastus2"
            };

            parameters.AddressPrefixes.Add("10.0.0.0/16");
            VirtualNetworkResource virtualNetwork = (await _resourceGroup.GetVirtualNetworks().CreateOrUpdateAsync(WaitUntil.Completed, vnetName, parameters)).Value;

            //set network rule set
            string             subscriptionId = DefaultSubscription.Id.ToString();
            ResourceIdentifier subnetId1      = new ResourceIdentifier(subscriptionId + "/resourceGroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default1");
            ResourceIdentifier subnetId2      = new ResourceIdentifier(subscriptionId + "/resourceGroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default2");
            ResourceIdentifier subnetId3      = new ResourceIdentifier(subscriptionId + "/resourceGroups/" + _resourceGroup.Id.Name + "/providers/Microsoft.Network/virtualNetworks/" + vnetName + "/subnets/default3");
            NetworkRuleSetData parameter      = new NetworkRuleSetData()
            {
                DefaultAction       = DefaultAction.Deny,
                VirtualNetworkRules =
                {
                    new NetworkRuleSetVirtualNetworkRules()
                    {
                        Subnet = new WritableSubResource()
                        {
                            Id = subnetId1
                        }, IgnoreMissingVnetServiceEndpoint = true
                    },
                    new NetworkRuleSetVirtualNetworkRules()
                    {
                        Subnet = new WritableSubResource()
                        {
                            Id = subnetId2
                        }, IgnoreMissingVnetServiceEndpoint = false
                    },
                    new NetworkRuleSetVirtualNetworkRules()
                    {
                        Subnet = new WritableSubResource()
                        {
                            Id = subnetId3
                        }, IgnoreMissingVnetServiceEndpoint = false
                    }
                },
                IPRules =
                {
                    new NetworkRuleSetIPRules()
                    {
                        IPMask = "1.1.1.1", Action = "Allow"
                    },
                    new NetworkRuleSetIPRules()
                    {
                        IPMask = "1.1.1.2", Action = "Allow"
                    },
                    new NetworkRuleSetIPRules()
                    {
                        IPMask = "1.1.1.3", Action = "Allow"
                    },
                    new NetworkRuleSetIPRules()
                    {
                        IPMask = "1.1.1.4", Action = "Allow"
                    },
                    new NetworkRuleSetIPRules()
                    {
                        IPMask = "1.1.1.5", Action = "Allow"
                    }
                }
            };
            await serviceBusNamespace.GetNetworkRuleSet().CreateOrUpdateAsync(WaitUntil.Completed, parameter);

            //get the network rule set
            NetworkRuleSetResource networkRuleSet = await serviceBusNamespace.GetNetworkRuleSet().GetAsync();

            Assert.NotNull(networkRuleSet);
            Assert.NotNull(networkRuleSet.Data.IPRules);
            Assert.NotNull(networkRuleSet.Data.VirtualNetworkRules);
            Assert.AreEqual(networkRuleSet.Data.VirtualNetworkRules.Count, 3);
            Assert.AreEqual(networkRuleSet.Data.IPRules.Count, 5);

            //delete virtual network
            await virtualNetwork.DeleteAsync(WaitUntil.Completed);
        }