Beispiel #1
0
 /// <summary>
 /// Initiate troubleshooting on a specified resource
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='networkWatcherName'>
 /// The name of the network watcher resource.
 /// </param>
 /// <param name='parameters'>
 /// Parameters that define the resource to troubleshoot.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <TroubleshootingResult> BeginGetTroubleshootingAsync(this INetworkWatchersOperations operations, string resourceGroupName, string networkWatcherName, TroubleshootingParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginGetTroubleshootingWithHttpMessagesAsync(resourceGroupName, networkWatcherName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
        public void TroubleshootApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler4 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };

            using (MockContext context = MockContext.Start(this.GetType().FullName))
            {
                var resourcesClient         = ResourcesManagementTestUtilities.GetResourceManagementClientWithHandler(context, handler1);
                var networkManagementClient = NetworkManagementTestUtilities.GetNetworkManagementClientWithHandler(context, handler2);
                var computeManagementClient = NetworkManagementTestUtilities.GetComputeManagementClientWithHandler(context, handler3);
                var storageManagementClient = NetworkManagementTestUtilities.GetStorageManagementClientWithHandler(context, handler4);

                string location = "westcentralus";

                string resourceGroupName = TestUtilities.GenerateName();
                resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName,
                                                              new ResourceGroup
                {
                    Location = location
                });

                // CreateVirtualNetworkGateway API
                // Prerequisite:- Create PublicIPAddress(Gateway Ip) using Put PublicIPAddress API
                string publicIpName    = TestUtilities.GenerateName();
                string domainNameLabel = TestUtilities.GenerateName();

                var nic1publicIp = TestHelper.CreateDefaultPublicIpAddress(publicIpName, resourceGroupName, domainNameLabel, location, networkManagementClient);

                //Prerequisite:-Create Virtual Network using Put VirtualNetwork API
                string vnetName   = TestUtilities.GenerateName();
                string subnetName = "GatewaySubnet";

                var virtualNetwork = TestHelper.CreateVirtualNetwork(vnetName, subnetName, resourceGroupName, location, networkManagementClient);

                var getSubnetResponse = networkManagementClient.Subnets.Get(resourceGroupName, vnetName, subnetName);

                // CreateVirtualNetworkGateway API
                string virtualNetworkGatewayName = TestUtilities.GenerateName();
                string ipConfigName = TestUtilities.GenerateName();

                var virtualNetworkGateway = new VirtualNetworkGateway()
                {
                    Location = location,
                    Tags     = new Dictionary <string, string>()
                    {
                        { "key", "value" }
                    },
                    EnableBgp          = false,
                    GatewayDefaultSite = null,
                    GatewayType        = VirtualNetworkGatewayType.Vpn,
                    VpnType            = VpnType.RouteBased,
                    IpConfigurations   = new List <VirtualNetworkGatewayIPConfiguration>()
                    {
                        new VirtualNetworkGatewayIPConfiguration()
                        {
                            Name = ipConfigName,
                            PrivateIPAllocationMethod = IPAllocationMethod.Dynamic,
                            PublicIPAddress           = new SubResource()
                            {
                                Id = nic1publicIp.Id
                            },
                            Subnet = new SubResource()
                            {
                                Id = getSubnetResponse.Id
                            }
                        }
                    },
                    Sku = new VirtualNetworkGatewaySku()
                    {
                        Name = VirtualNetworkGatewaySkuName.Basic,
                        Tier = VirtualNetworkGatewaySkuTier.Basic
                    }
                };

                var putVirtualNetworkGatewayResponse = networkManagementClient.VirtualNetworkGateways.CreateOrUpdate(resourceGroupName, virtualNetworkGatewayName, virtualNetworkGateway);

                // GetVirtualNetworkGateway API
                var getVirtualNetworkGatewayResponse = networkManagementClient.VirtualNetworkGateways.Get(resourceGroupName, virtualNetworkGatewayName);

                string         networkWatcherName = TestUtilities.GenerateName();
                NetworkWatcher properties         = new NetworkWatcher();
                properties.Location = location;

                //Create network Watcher
                var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties);


                //Create storage
                string storageName = TestUtilities.GenerateName();

                var storageParameters = new StorageAccountCreateParameters()
                {
                    Location = location,
                    Kind     = Kind.Storage,
                    Sku      = new Sku
                    {
                        Name = SkuName.StandardLRS
                    }
                };

                var account = storageManagementClient.StorageAccounts.Create(resourceGroupName, storageName, storageParameters);

                TroubleshootingParameters parameters = new TroubleshootingParameters()
                {
                    TargetResourceId = getVirtualNetworkGatewayResponse.Id,
                    StorageId        = account.Id,
                    StoragePath      = "https://nwtestdbdzq4xsvskrei6.blob.core.windows.net/vhds",
                };

                //Get troubleshooting
                var troubleshoot = networkManagementClient.NetworkWatchers.GetTroubleshooting(resourceGroupName, networkWatcherName, parameters);

                QueryTroubleshootingParameters qParameters = new QueryTroubleshootingParameters()
                {
                    TargetResourceId = getVirtualNetworkGatewayResponse.Id
                };

                //Query last troubleshoot
                var queryTroubleshoot = networkManagementClient.NetworkWatchers.GetTroubleshootingResult(resourceGroupName, networkWatcherName, qParameters);

                //TO DO: make verification once fixed for troubleshoot API deployed
            }
        }
Beispiel #3
0
 /// <summary>
 /// Initiate troubleshooting on a specified resource
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='networkWatcherName'>
 /// The name of the network watcher resource.
 /// </param>
 /// <param name='parameters'>
 /// Parameters that define the resource to troubleshoot.
 /// </param>
 public static TroubleshootingResult BeginGetTroubleshooting(this INetworkWatchersOperations operations, string resourceGroupName, string networkWatcherName, TroubleshootingParameters parameters)
 {
     return(operations.BeginGetTroubleshootingAsync(resourceGroupName, networkWatcherName, parameters).GetAwaiter().GetResult());
 }
Beispiel #4
0
        public async Task TroubleshootApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location = "westus2";
            await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName, new ResourceGroup(location));

            // CreateVirtualNetworkGateway API
            // Prerequisite:- Create PublicIPAddress(Gateway Ip) using Put PublicIPAddress API
            string publicIpName    = Recording.GenerateAssetName("azsmnet");
            string domainNameLabel = Recording.GenerateAssetName("azsmnet");

            PublicIPAddress nic1publicIp = await CreateDefaultPublicIpAddress(publicIpName, resourceGroupName, domainNameLabel, location, NetworkManagementClient);

            //Prerequisite:-Create Virtual Network using Put VirtualNetwork API
            string vnetName   = Recording.GenerateAssetName("azsmnet");
            string subnetName = "GatewaySubnet";

            await CreateVirtualNetwork(vnetName, subnetName, resourceGroupName, location, NetworkManagementClient);

            Response <Subnet> getSubnetResponse = await NetworkManagementClient.Subnets.GetAsync(resourceGroupName, vnetName, subnetName);

            // CreateVirtualNetworkGateway API
            string virtualNetworkGatewayName = Recording.GenerateAssetName("azsmnet");
            string ipConfigName = Recording.GenerateAssetName("azsmnet");

            VirtualNetworkGateway virtualNetworkGateway = new VirtualNetworkGateway()
            {
                Location           = location,
                Tags               = { { "key", "value" } },
                EnableBgp          = false,
                GatewayDefaultSite = null,
                GatewayType        = VirtualNetworkGatewayType.Vpn,
                VpnType            = VpnType.RouteBased,
                IpConfigurations   =
                {
                    new VirtualNetworkGatewayIPConfiguration()
                    {
                        Name = ipConfigName,
                        PrivateIPAllocationMethod = IPAllocationMethod.Dynamic,
                        PublicIPAddress           = new SubResource()
                        {
                            Id = nic1publicIp.Id
                        }, Subnet = new SubResource()
                        {
                            Id = getSubnetResponse.Value.Id
                        }
                    }
                },
                Sku = new VirtualNetworkGatewaySku()
                {
                    Name = VirtualNetworkGatewaySkuName.Basic, Tier = VirtualNetworkGatewaySkuTier.Basic
                }
            };

            VirtualNetworkGatewaysCreateOrUpdateOperation putVirtualNetworkGatewayResponseOperation =
                await NetworkManagementClient.VirtualNetworkGateways.StartCreateOrUpdateAsync(resourceGroupName, virtualNetworkGatewayName, virtualNetworkGateway);

            await WaitForCompletionAsync(putVirtualNetworkGatewayResponseOperation);

            // GetVirtualNetworkGateway API
            Response <VirtualNetworkGateway> getVirtualNetworkGatewayResponse =
                await NetworkManagementClient.VirtualNetworkGateways.GetAsync(resourceGroupName, virtualNetworkGatewayName);

            //TODO:There is no need to perform a separate create NetworkWatchers operation
            //Create network Watcher
            //string networkWatcherName = Recording.GenerateAssetName("azsmnet");
            //NetworkWatcher properties = new NetworkWatcher { Location = location };
            //await NetworkManagementClient.NetworkWatchers.CreateOrUpdateAsync(resourceGroupName, networkWatcherName, properties);

            //Create storage
            string storageName       = Recording.GenerateAssetName("azsmnet");
            var    storageParameters = new StorageAccountCreateParameters(new Sku(SkuName.StandardLRS), Kind.Storage, location);

            Operation <StorageAccount> accountOperation = await StorageManagementClient.StorageAccounts.StartCreateAsync(resourceGroupName, storageName, storageParameters);

            Response <StorageAccount> account = await WaitForCompletionAsync(accountOperation);

            TroubleshootingParameters parameters = new TroubleshootingParameters(getVirtualNetworkGatewayResponse.Value.Id, account.Value.Id, "https://nwtestdbdzq4xsvskrei6.blob.core.windows.net/vhds");

            //Get troubleshooting
            NetworkWatchersGetTroubleshootingOperation troubleshootOperation = await NetworkManagementClient.NetworkWatchers.StartGetTroubleshootingAsync("NetworkWatcherRG", "NetworkWatcher_westus2", parameters);

            await WaitForCompletionAsync(troubleshootOperation);

            QueryTroubleshootingParameters qParameters = new QueryTroubleshootingParameters(getVirtualNetworkGatewayResponse.Value.Id);

            //Query last troubleshoot
            NetworkWatchersGetTroubleshootingResultOperation queryTroubleshootOperation = await NetworkManagementClient.NetworkWatchers.StartGetTroubleshootingResultAsync("NetworkWatcherRG", "NetworkWatcher_westus2", qParameters);

            await WaitForCompletionAsync(queryTroubleshootOperation);

            //TODO: make verification once fixed for troubleshoot API deployed
        }