public async Task TopologyApiTest() { string resourceGroupName1 = Recording.GenerateAssetName("azsmnet"); string resourceGroupName2 = Recording.GenerateAssetName("azsmnet"); string location = "westus2"; await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName1, new ResourceGroup(location)); string virtualMachineName = Recording.GenerateAssetName("azsmnet"); string networkSecurityGroupName = virtualMachineName + "-nsg"; string networkInterfaceName = Recording.GenerateAssetName("azsmnet"); //Deploy Vm from template await CreateVm( resourcesClient : ResourceManagementClient, resourceGroupName : resourceGroupName1, location : location, virtualMachineName : virtualMachineName, storageAccountName : Recording.GenerateAssetName("azsmnet"), networkInterfaceName : networkInterfaceName, networkSecurityGroupName : networkSecurityGroupName, diagnosticsStorageAccountName : Recording.GenerateAssetName("azsmnet"), deploymentName : Recording.GenerateAssetName("azsmnet"), adminPassword : Recording.GenerateAlphaNumericId("AzureSDKNetworkTest#") ); await ResourceGroupsOperations.CreateOrUpdateAsync(resourceGroupName2, new ResourceGroup(location)); //TODO:There is no need to perform a separate create NetworkWatchers operation //Create NetworkWatcher //string networkWatcherName = Recording.GenerateAssetName("azsmnet"); //NetworkWatcher properties = new NetworkWatcher { Location = location }; //await NetworkManagementClient.NetworkWatchers.CreateOrUpdateAsync(resourceGroupName2, networkWatcherName, properties); TopologyParameters tpProperties = new TopologyParameters() { TargetResourceGroupName = resourceGroupName1 }; Response <VirtualMachine> getVm = await ComputeManagementClient.VirtualMachines.GetAsync(resourceGroupName1, virtualMachineName); //Get the current network topology of the resourceGroupName1 Response <Topology> getTopology = await NetworkManagementClient.NetworkWatchers.GetTopologyAsync("NetworkWatcherRG", "NetworkWatcher_westus2", tpProperties); //Getting infromation about VM from topology TopologyResource vmResource = getTopology.Value.Resources[0]; //Verify that topology contain right number of resources (9 resources from template) Assert.AreEqual(9, getTopology.Value.Resources.Count); //Verify that topology contain information about acreated VM Assert.AreEqual(virtualMachineName, vmResource.Name); Assert.AreEqual(getVm.Value.Id, vmResource.Id); Assert.AreEqual(networkInterfaceName, vmResource.Associations.FirstOrDefault().Name); Assert.AreEqual(getVm.Value.NetworkProfile.NetworkInterfaces.FirstOrDefault().Id, vmResource.Associations.FirstOrDefault().ResourceId); Assert.AreEqual("Contains", vmResource.Associations.FirstOrDefault().AssociationType.ToString()); }
public async Task TopologyApiTest() { string resourceGroupName1 = Recording.GenerateAssetName("azsmnet"); string resourceGroupName2 = Recording.GenerateAssetName("azsmnet"); string location = TestEnvironment.Location; var resourceGroup1 = await CreateResourceGroup(resourceGroupName1, location); string virtualMachineName = Recording.GenerateAssetName("azsmnet"); string networkSecurityGroupName = virtualMachineName + "-nsg"; string networkInterfaceName = Recording.GenerateAssetName("azsmnet"); //Deploy Vm from template var vm = await CreateWindowsVM(virtualMachineName, networkInterfaceName, location, resourceGroup1); // TODO: where is this used? var resourceGropu2 = await CreateResourceGroup(resourceGroupName2, location); //TODO:There is no need to perform a separate create NetworkWatchers operation //Create NetworkWatcher //string networkWatcherName = Recording.GenerateAssetName("azsmnet"); //NetworkWatcher properties = new NetworkWatcher { Location = location }; //await networkWatcherCollection.CreateOrUpdateAsync(resourceGroupName2, networkWatcherName, properties); TopologyParameters tpProperties = new TopologyParameters() { TargetResourceGroupName = resourceGroupName1 }; //Get the current network topology of the resourceGroupName1 var networkWatcherCollection = GetNetworkWatcherCollection("NetworkWatcherRG"); Response <Topology> getTopology = await networkWatcherCollection.Get("NetworkWatcher_westus2").Value.GetTopologyAsync(tpProperties); //Getting infromation about VM from topology TopologyResource vmResource = getTopology.Value.Resources[0]; //Verify that topology contain right number of resources (9 resources from template) Assert.AreEqual(9, getTopology.Value.Resources.Count); //Verify that topology contain information about acreated VM Assert.AreEqual(virtualMachineName, vmResource.Name); Assert.AreEqual(vm.Id, vmResource.Id); Assert.AreEqual(networkInterfaceName, vmResource.Associations.FirstOrDefault().Name); //Assert.AreEqual(vm.Data.NetworkProfile.NetworkInterfaces.FirstOrDefault().Id, vmResource.Associations.FirstOrDefault().ResourceId); Assert.AreEqual("Contains", vmResource.Associations.FirstOrDefault().AssociationType.ToString()); }
/// <summary> /// Gets the current network topology by resource group. /// </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 representation of topology. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <Topology> GetTopologyAsync(this INetworkWatchersOperations operations, string resourceGroupName, string networkWatcherName, TopologyParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.GetTopologyWithHttpMessagesAsync(resourceGroupName, networkWatcherName, parameters, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Gets the current network topology by resource group. /// </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 representation of topology. /// </param> public static Topology GetTopology(this INetworkWatchersOperations operations, string resourceGroupName, string networkWatcherName, TopologyParameters parameters) { return(operations.GetTopologyAsync(resourceGroupName, networkWatcherName, parameters).GetAwaiter().GetResult()); }
public void TopologyApiTest() { 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 = "eastus"; string resourceGroupName1 = TestUtilities.GenerateName(); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName1, new ResourceGroup { Location = location }); string virtualMachineName = TestUtilities.GenerateName(); string networkSecurityGroupName = virtualMachineName + "-nsg"; string networkInterfaceName = TestUtilities.GenerateName(); //Deploy Vm from template Deployments.CreateVm( resourcesClient: resourcesClient, resourceGroupName: resourceGroupName1, location: location, virtualMachineName: virtualMachineName, storageAccountName: TestUtilities.GenerateName(), networkInterfaceName: networkInterfaceName, networkSecurityGroupName: networkSecurityGroupName, diagnosticsStorageAccountName: TestUtilities.GenerateName(), deploymentName: TestUtilities.GenerateName() ); string resourceGroupName2 = TestUtilities.GenerateName(); resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName2, new ResourceGroup { Location = location }); string networkWatcherName = TestUtilities.GenerateName(); NetworkWatcher properties = new NetworkWatcher(); properties.Location = location; //Create NetworkWatcher var createNetworkWatcher = networkManagementClient.NetworkWatchers.CreateOrUpdate(resourceGroupName2, networkWatcherName, properties); TopologyParameters tpProperties = new TopologyParameters() { TargetResourceGroupName = resourceGroupName1 }; var getVm = computeManagementClient.VirtualMachines.Get(resourceGroupName1, virtualMachineName); //Get the current network topology of the resourceGroupName1 var getTopology = networkManagementClient.NetworkWatchers.GetTopology(resourceGroupName2, networkWatcherName, tpProperties); //Getting infromation about VM from topology TopologyResource vmResource = getTopology.Resources[2]; //Verify that topology contain right number of resources (9 resources from template) Assert.Equal(9, getTopology.Resources.Count); //Verify that topology contain information about acreated VM Assert.Equal(virtualMachineName, vmResource.Name); Assert.Equal(getVm.Id, vmResource.Id); Assert.Equal(networkInterfaceName, vmResource.Associations.FirstOrDefault().Name); Assert.Equal(getVm.NetworkProfile.NetworkInterfaces.FirstOrDefault().Id, vmResource.Associations.FirstOrDefault().ResourceId); Assert.Equal("Contains", vmResource.Associations.FirstOrDefault().AssociationType); } }