コード例 #1
0
        public async Task NextHopApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

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

            string virtualMachineName       = Recording.GenerateAssetName("azsmnet");
            string networkSecurityGroupName = virtualMachineName + "-nsg";
            string networkInterfaceName     = Recording.GenerateAssetName("azsmnet");

            //Deploy VM wih VNet,Subnet and Route Table from template
            await CreateVm(
                resourcesClient : ResourceManagementClient,
                resourceGroupName : resourceGroupName,
                location : location,
                virtualMachineName : virtualMachineName,
                storageAccountName : Recording.GenerateAssetName("azsmnet"),
                networkInterfaceName : networkInterfaceName,
                networkSecurityGroupName : networkSecurityGroupName,
                diagnosticsStorageAccountName : Recording.GenerateAssetName("azsmnet"),
                deploymentName : Recording.GenerateAssetName("azsmnet"),
                adminPassword : Recording.GenerateAlphaNumericId("AzureSDKNetworkTest#")
                );

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

            string sourceIPAddress = NetworkManagementClient.NetworkInterfaces
                                     .GetAsync(resourceGroupName, networkInterfaceName).Result.Value.IpConfigurations
                                     .FirstOrDefault().PrivateIPAddress;

            Response <VirtualMachine> getVm = await ComputeManagementClient.VirtualMachines.GetAsync(resourceGroupName, virtualMachineName);

            //Use DestinationIPAddress from Route Table
            NextHopParameters nhProperties1 = new NextHopParameters(getVm.Value.Id, sourceIPAddress, "10.1.3.6");

            NextHopParameters nhProperties2 = new NextHopParameters(getVm.Value.Id, sourceIPAddress, "12.11.12.14");

            NetworkWatchersGetNextHopOperation getNextHop1Operation = await NetworkManagementClient.NetworkWatchers.StartGetNextHopAsync("NetworkWatcherRG", "NetworkWatcher_westus2", nhProperties1);

            Response <NextHopResult> getNextHop1 = await WaitForCompletionAsync(getNextHop1Operation);

            NetworkWatchersGetNextHopOperation getNextHop2Operation = await NetworkManagementClient.NetworkWatchers.StartGetNextHopAsync("NetworkWatcherRG", "NetworkWatcher_westus2", nhProperties2);

            Response <NextHopResult> getNextHop2 = await WaitForCompletionAsync(getNextHop2Operation);

            Response <RouteTable> routeTable = await NetworkManagementClient.RouteTables.GetAsync(resourceGroupName, resourceGroupName + "RT");

            //Validation
            Assert.AreEqual("10.0.1.2", getNextHop1.Value.NextHopIpAddress);
            Assert.AreEqual(routeTable.Value.Id, getNextHop1.Value.RouteTableId);
            Assert.AreEqual("Internet", getNextHop2.Value.NextHopType.ToString());
            Assert.AreEqual("System Route", getNextHop2.Value.RouteTableId);
        }
コード例 #2
0
        public async Task NextHopApiTest()
        {
            string resourceGroupName = Recording.GenerateAssetName("azsmnet");

            string location      = "westus2";
            var    resourceGroup = await CreateResourceGroup(resourceGroupName, location);

            string virtualMachineName       = Recording.GenerateAssetName("azsmnet");
            string networkSecurityGroupName = virtualMachineName + "-nsg";
            string networkInterfaceName     = Recording.GenerateAssetName("azsmnet");

            //Deploy VM wih VNet,SubnetResource and RouteResource Table from template
            var vm = await CreateLinuxVM(virtualMachineName, networkInterfaceName, location, resourceGroup);

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

            var    networkInterfaceCollection = resourceGroup.GetNetworkInterfaces();
            string sourceIPAddress            = networkInterfaceCollection
                                                .GetAsync(networkInterfaceName).Result.Value.Data.IPConfigurations
                                                .FirstOrDefault().PrivateIPAddress;

            //Use DestinationIPAddress from RouteResource Table
            NextHopParameters nhProperties1 = new NextHopParameters(vm.Id, sourceIPAddress, "10.1.3.6");

            NextHopParameters nhProperties2 = new NextHopParameters(vm.Id, sourceIPAddress, "12.11.12.14");

            var networkWatcherCollection = resourceGroup.GetNetworkWatchers();
            var networkWatcherResponse   = await networkWatcherCollection.GetAsync("NetworkWatcher_westus2");

            var getNextHop1Operation = await networkWatcherResponse.Value.GetNextHopAsync(WaitUntil.Completed, nhProperties1);

            Response <NextHopResult> getNextHop1 = await getNextHop1Operation.WaitForCompletionAsync();;

            var getNextHop2Operation = await networkWatcherResponse.Value.GetNextHopAsync(WaitUntil.Completed, nhProperties2);

            Response <NextHopResult> getNextHop2 = await getNextHop2Operation.WaitForCompletionAsync();;

            Response <RouteTableResource> routeTable = await resourceGroup.GetRouteTables().GetAsync(resourceGroupName + "RT");

            //Validation
            Assert.AreEqual("10.0.1.2", getNextHop1.Value.NextHopIPAddress);
            Assert.AreEqual(routeTable.Value.Id, getNextHop1.Value.RouteTableId);
            Assert.AreEqual("Internet", getNextHop2.Value.NextHopType.ToString());
            Assert.AreEqual("System Route", getNextHop2.Value.RouteTableId);
        }
コード例 #3
0
 /// <summary>
 /// Gets the next hop from the specified VM.
 /// </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.
 /// </param>
 /// <param name='parameters'>
 /// Parameters that define the source and destination endpoint.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <NextHopResult> BeginGetNextHopAsync(this INetworkWatchersOperations operations, string resourceGroupName, string networkWatcherName, NextHopParameters parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginGetNextHopWithHttpMessagesAsync(resourceGroupName, networkWatcherName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #4
0
 /// <summary>
 /// Gets the next hop from the specified VM.
 /// </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.
 /// </param>
 /// <param name='parameters'>
 /// Parameters that define the source and destination endpoint.
 /// </param>
 public static NextHopResult BeginGetNextHop(this INetworkWatchersOperations operations, string resourceGroupName, string networkWatcherName, NextHopParameters parameters)
 {
     return(operations.BeginGetNextHopAsync(resourceGroupName, networkWatcherName, parameters).GetAwaiter().GetResult());
 }
コード例 #5
0
ファイル: NextHopTests.cs プロジェクト: shahabhijeet/aznetsdk
        public void NextHopApiTest()
        {
            var handler1 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler2 = new RecordedDelegatingHandler {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var handler3 = 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);

                string location = "westcentralus";

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

                string virtualMachineName       = TestUtilities.GenerateName();
                string networkSecurityGroupName = virtualMachineName + "-nsg";
                string networkInterfaceName     = TestUtilities.GenerateName();

                //Deploy VM wih VNet,Subnet and Route Table from template
                Deployments.CreateVm(
                    resourcesClient: resourcesClient,
                    resourceGroupName: resourceGroupName,
                    location: location,
                    virtualMachineName: virtualMachineName,
                    storageAccountName: TestUtilities.GenerateName(),
                    networkInterfaceName: networkInterfaceName,
                    networkSecurityGroupName: networkSecurityGroupName,
                    diagnosticsStorageAccountName: TestUtilities.GenerateName(),
                    deploymentName: TestUtilities.GenerateName()
                    );

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

                //Create Network Watcher
                var    createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName, networkWatcherName, properties);
                string sourceIPAddress      = networkManagementClient.NetworkInterfaces.Get(resourceGroupName, networkInterfaceName).IpConfigurations.FirstOrDefault().PrivateIPAddress;

                var getVm = computeManagementClient.VirtualMachines.Get(resourceGroupName, virtualMachineName);

                //Use DestinationIPAddress from Route Table
                NextHopParameters nhProperties1 = new NextHopParameters()
                {
                    TargetResourceId     = getVm.Id,
                    SourceIPAddress      = sourceIPAddress,
                    DestinationIPAddress = "10.1.3.6"
                };

                NextHopParameters nhProperties2 = new NextHopParameters()
                {
                    TargetResourceId     = getVm.Id,
                    SourceIPAddress      = sourceIPAddress,
                    DestinationIPAddress = "12.11.12.14"
                };

                var getNextHop1 = networkManagementClient.NetworkWatchers.GetNextHop(resourceGroupName, networkWatcherName, nhProperties1);
                var getNextHop2 = networkManagementClient.NetworkWatchers.GetNextHop(resourceGroupName, networkWatcherName, nhProperties2);

                var routeTable = networkManagementClient.RouteTables.Get(resourceGroupName, resourceGroupName + "RT");

                //Validation
                Assert.Equal("10.0.1.2", getNextHop1.NextHopIpAddress);
                Assert.Equal(routeTable.Id, getNextHop1.RouteTableId);

                Assert.Equal("Internet", getNextHop2.NextHopType);
                Assert.Equal("System Route", getNextHop2.RouteTableId);
            }
        }