public static void ComparePeeringPolicy(ManagedNetworkPeeringPolicy p1, ManagedNetworkPeeringPolicy p2) { if (p1.Properties.Hub == null) { Assert.Null(p2.Properties.Hub); } else { Assert.Equal(p1.Properties.Hub.Id, p2.Properties.Hub.Id); } if (p1.Properties.Spokes == null) { if (p2.Properties.Spokes != null) { Assert.Equal(0, p2.Properties.Spokes.Count); } } else { Assert.Equal(p1.Properties.Spokes.Count, p2.Properties.Spokes.Count); for (int i = 0; i < p1.Properties.Spokes.Count; i++) { Assert.Equal(p1.Properties.Spokes[i].Id, p2.Properties.Spokes[i].Id); } } if (p1.Properties.Mesh == null) { if (p2.Properties.Mesh != null) { Assert.Equal(0, p2.Properties.Mesh.Count); } } else { Assert.Equal(p1.Properties.Mesh.Count, p2.Properties.Mesh.Count); for (int i = 0; i < p1.Properties.Mesh.Count; i++) { Assert.Equal(p1.Properties.Mesh[i].Id, p2.Properties.Mesh[i].Id); } } }
public void ManagedNetworkGroupTest() { using (var context = MockContext.Start(this.GetType().FullName)) { #region Initialization this.client = context.GetServiceClient <ManagedNetworkManagementClient>(); this.resourcesClient = context.GetServiceClient <ResourceManagementClient>(); string resourceGroupName = TestUtilities.GenerateName("MNCRP_RSG"); string location = "Central US"; ResourceGroup rsg; try { rsg = this.resourcesClient.ResourceGroups.Get(resourceGroupName); } catch { rsg = this.resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); } Assert.Equal(rsg.Name, resourceGroupName); #endregion #region Create managedNetwork string managedNetworkName = TestUtilities.GenerateName("myManagedNetwork"); ManagedNetworkModel managedNetwork = new ManagedNetworkModel() { Location = location, Scope = new Scope() { VirtualNetworks = new List <ResourceId>() { new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNCRG/providers/Microsoft.Network/virtualnetworks/testvnet" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNCRG/providers/Microsoft.Network/virtualnetworks/testvnet2" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNCRG/providers/Microsoft.Network/virtualnetworks/Spoke9" } }, } }; // Put ManagedNetwork this.client.ManagedNetworks.CreateOrUpdate(managedNetwork, resourceGroupName, managedNetworkName); // Create Connectivity Group string managedNetworkGroupName = TestUtilities.GenerateName("myGroup"); ManagedNetworkGroup managedNetworkGroup = new ManagedNetworkGroup() { Location = location, VirtualNetworks = new List <ResourceId>() { new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNCRG/providers/Microsoft.Network/virtualnetworks/testvnet2" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNCRG/providers/Microsoft.Network/virtualnetworks/Spoke9" } } }; // Put Connectivity Group ManagedNetworkGroup putConnectivityGroupResponse = this.client.ManagedNetworkGroups.CreateOrUpdate(managedNetworkGroup, resourceGroupName, managedNetworkName, managedNetworkGroupName); #endregion #region Create peeringPolicy string peeringPolicyName = TestUtilities.GenerateName("hubAndSpoke"); ResourceId hub = new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNCRG/providers/Microsoft.Network/virtualnetworks/testvnet" }; var spokes = new List <ResourceId> { new ResourceId() { Id = putConnectivityGroupResponse.Id }, }; ManagedNetworkPeeringPolicyProperties managedNetworkPeeringPolicyProperties = new ManagedNetworkPeeringPolicyProperties { Type = "HubAndSpokeTopology", Hub = hub, Spokes = spokes }; ManagedNetworkPeeringPolicy peeringPolicy = new ManagedNetworkPeeringPolicy { Location = location, Properties = managedNetworkPeeringPolicyProperties }; #endregion // Put PeeringPolicy ManagedNetworkPeeringPolicy putPeeringPolicyResult = this.client.ManagedNetworkPeeringPolicies.CreateOrUpdate(peeringPolicy, resourceGroupName, managedNetworkName, peeringPolicyName); Assert.NotNull(putPeeringPolicyResult); Comparator.ComparePeeringPolicy(peeringPolicy, putPeeringPolicyResult); // Get PeeringPolicy ManagedNetworkPeeringPolicy getPeeringPolicyResult = this.client.ManagedNetworkPeeringPolicies.Get(resourceGroupName, managedNetworkName, peeringPolicyName); Comparator.ComparePeeringPolicy(peeringPolicy, getPeeringPolicyResult); //Get PeeringPolicy from ManagedNetwork ManagedNetworkModel getManagedNetworkResponse = this.client.ManagedNetworks.Get(resourceGroupName, managedNetworkName); Comparator.ComparePeeringPolicy(peeringPolicy, getManagedNetworkResponse.Connectivity.Peerings[0]); //List PeeringPolicy from ManagedNetworkm var listPeeringPolicyResponse = this.client.ManagedNetworkPeeringPolicies.ListByManagedNetwork(resourceGroupName, managedNetworkName); Assert.Single(listPeeringPolicyResponse); //Delete PeeringPolicy this.client.ManagedNetworkPeeringPolicies.Delete(resourceGroupName, managedNetworkName, peeringPolicyName); } }
public void Mesh() { using (var context = MockContext.Start(this.GetType().FullName)) { #region Initialization this.client = context.GetServiceClient <ManagedNetworkManagementClient>(); this.resourcesClient = context.GetServiceClient <ResourceManagementClient>(); string resourceGroupName = "MNC-Portal"; string location = "Central US"; ResourceGroup rsg; try { rsg = this.resourcesClient.ResourceGroups.Get(resourceGroupName); } catch { rsg = this.resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); } Assert.Equal(rsg.Name, resourceGroupName); #endregion #region Create managedNetwork string managedNetworkName = "SDK_ManagedNetwork_Mesh2"; Scope mNScope = new Scope() { VirtualNetworks = new List <ResourceId>() { new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh1" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh2" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh3" } } }; ManagedNetworkModel managedNetwork = new ManagedNetworkModel() { Location = location, Scope = mNScope }; ManagedNetworkModel putManagedNetworkResponse = this.client.ManagedNetworks.CreateOrUpdate(managedNetwork, resourceGroupName, managedNetworkName); #endregion string managedNetworkGroupName = "SDK_MeshGroup"; ManagedNetworkGroup managedNetworkGroup = new ManagedNetworkGroup() { Location = location, VirtualNetworks = new List <ResourceId>() { new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh1" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh2" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-PowerShell/providers/Microsoft.Network/virtualnetworks/Mesh3" } } }; // Put Connectivity Group ManagedNetworkGroup putManagedNetworkGroupResponse = this.client.ManagedNetworkGroups.CreateOrUpdate(managedNetworkGroup, resourceGroupName, managedNetworkName, managedNetworkGroupName); #region Create peeringPolicy string peeringPolicyName = "SDK_MeshPolicy"; string managedNetworkPeeringPolicyType = "MeshTopology"; var mesh = new List <ResourceId> { new ResourceId() { Id = putManagedNetworkGroupResponse.Id }, }; ManagedNetworkPeeringPolicyProperties managedNetworkPeeringPolicyProperties = new ManagedNetworkPeeringPolicyProperties { Type = managedNetworkPeeringPolicyType, Mesh = mesh }; ManagedNetworkPeeringPolicy peeringPolicy = new ManagedNetworkPeeringPolicy { Location = location, Properties = managedNetworkPeeringPolicyProperties }; #endregion // Put PeeringPolicy ManagedNetworkPeeringPolicy putPeeringPolicyResult = this.client.ManagedNetworkPeeringPolicies.CreateOrUpdate(peeringPolicy, resourceGroupName, managedNetworkName, peeringPolicyName); } }
public void HubSpoke() { var mode = System.Environment.GetEnvironmentVariable("AZURE_TEST_MODE"); var connectionstring = System.Environment.GetEnvironmentVariable("TEST_CSM_ORGID_AUTHENTICATION"); using (var context = MockContext.Start(this.GetType().FullName)) { #region Initialization this.client = context.GetServiceClient <ManagedNetworkManagementClient>(); this.resourcesClient = context.GetServiceClient <ResourceManagementClient>(); string resourceGroupName = "MNC-Portal"; string location = "Central US"; ResourceGroup rsg; try { rsg = this.resourcesClient.ResourceGroups.Get(resourceGroupName); } catch { rsg = this.resourcesClient.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup { Location = location }); } Assert.Equal(rsg.Name, resourceGroupName); #endregion #region Create managedNetwork string managedNetworkName = "Portal_ManagedNetwork118"; Scope scope = new Scope() { VirtualNetworks = new List <ResourceId>() { new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke11" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke12" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke13" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke14" } } }; IDictionary <string, string> tags = new Dictionary <string, string>(); tags["SampleKey"] = "SampleValue"; ManagedNetworkModel managedNetwork = new ManagedNetworkModel() { Location = location, Scope = scope, Tags = tags }; ManagedNetworkModel putManagedNetworkResponse = this.client.ManagedNetworks.CreateOrUpdate(managedNetwork, resourceGroupName, managedNetworkName); #endregion string managedNetworkGroupName = "Portal_SpokeGroup3"; ManagedNetworkGroup managedNetworkGroup = new ManagedNetworkGroup() { Location = location, VirtualNetworks = new List <ResourceId>() { new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke12" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke11" }, new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke13" } } }; // Put Connectivity Group ManagedNetworkGroup putManagedNetworkGroupResponse = this.client.ManagedNetworkGroups.CreateOrUpdate(managedNetworkGroup, resourceGroupName, managedNetworkName, managedNetworkGroupName); #region Create peeringPolicy string peeringPolicyName = "SDK_MeshPolicy3"; ResourceId hub = new ResourceId() { Id = "/subscriptions/18ba8369-92e4-4d70-8b1e-937660bde798/resourceGroups/MNC-Portal/providers/Microsoft.Network/virtualNetworks/Spoke14" }; var spokes = new List <ResourceId> { new ResourceId() { Id = putManagedNetworkGroupResponse.Id }, }; ManagedNetworkPeeringPolicyProperties managedNetworkPeeringPolicyProperties = new ManagedNetworkPeeringPolicyProperties { Type = "HubAndSpokeTopology", Hub = hub, Spokes = spokes }; ManagedNetworkPeeringPolicy peeringPolicy = new ManagedNetworkPeeringPolicy { Location = location, Properties = managedNetworkPeeringPolicyProperties }; #endregion // Put PeeringPolicy ManagedNetworkPeeringPolicy putPeeringPolicyResult = this.client.ManagedNetworkPeeringPolicies.CreateOrUpdate(peeringPolicy, resourceGroupName, managedNetworkName, peeringPolicyName); } }
/// <summary> /// The Put ManagedNetworkPeeringPolicies operation creates/updates a new /// Managed Network Peering Policy /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='managedNetworkPolicy'> /// Parameters supplied to create/update a Managed Network Peering Policy /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='managedNetworkName'> /// The name of the Managed Network. /// </param> /// <param name='managedNetworkPeeringPolicyName'> /// The name of the Managed Network Peering Policy. /// </param> public static ManagedNetworkPeeringPolicy CreateOrUpdate(this IManagedNetworkPeeringPoliciesOperations operations, ManagedNetworkPeeringPolicy managedNetworkPolicy, string resourceGroupName, string managedNetworkName, string managedNetworkPeeringPolicyName) { return(operations.CreateOrUpdateAsync(managedNetworkPolicy, resourceGroupName, managedNetworkName, managedNetworkPeeringPolicyName).GetAwaiter().GetResult()); }
/// <summary> /// The Put ManagedNetworkPeeringPolicies operation creates/updates a new /// Managed Network Peering Policy /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='managedNetworkPolicy'> /// Parameters supplied to create/update a Managed Network Peering Policy /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='managedNetworkName'> /// The name of the Managed Network. /// </param> /// <param name='managedNetworkPeeringPolicyName'> /// The name of the Managed Network Peering Policy. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <ManagedNetworkPeeringPolicy> BeginCreateOrUpdateAsync(this IManagedNetworkPeeringPoliciesOperations operations, ManagedNetworkPeeringPolicy managedNetworkPolicy, string resourceGroupName, string managedNetworkName, string managedNetworkPeeringPolicyName, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(managedNetworkPolicy, resourceGroupName, managedNetworkName, managedNetworkPeeringPolicyName, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }