forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
381a986
commit 27525ee
Showing
12 changed files
with
200 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
experiments/Azure.Experiments/Azure.Experiments/Network/SubnetPolicy.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.Azure.Management.Network.Models; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Microsoft.Azure.Experiments.Network | ||
{ | ||
public static class SubnetPolicy | ||
{ | ||
public static NestedResourcePolicy<Subnet, VirtualNetwork> Policy { get; } | ||
= NestedResourcePolicy.Create<Subnet, VirtualNetwork>( | ||
"subnets", | ||
(vn, name) => vn.Subnets?.FirstOrDefault(s => s.Name == name), | ||
(vn, name, subnet) => | ||
{ | ||
subnet.Name = name; | ||
if (vn.Subnets == null) | ||
{ | ||
vn.Subnets = new List<Subnet> { subnet }; | ||
return; | ||
} | ||
var s = vn | ||
.Subnets | ||
.Select((sn, i) => new { sn, i }) | ||
.FirstOrDefault(p => p.sn.Name == name); | ||
if (s != null) | ||
{ | ||
vn.Subnets[s.i] = subnet; | ||
return; | ||
} | ||
vn.Subnets.Add(subnet); | ||
}); | ||
|
||
public static NestedResourceConfig<Subnet, VirtualNetwork> CreateSubnet( | ||
this ResourceConfig<VirtualNetwork> virtualNetwork, string name, string addressPrefix) | ||
=> Policy.CreateConfig( | ||
virtualNetwork, | ||
name, | ||
() => new Subnet { Name = name, AddressPrefix = addressPrefix }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
experiments/Azure.Experiments/Tests/NetworkInterfaceTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.Azure.Experiments.Network; | ||
using Microsoft.Azure.Experiments.ResourceManager; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Experiments.Tests | ||
{ | ||
public class NetworkInterfaceTest | ||
{ | ||
[Fact] | ||
public async Task CreateAsyncTest() | ||
{ | ||
var rg = ResourceGroupPolicy.CreateResourceGroupConfig("nirg"); | ||
var vn = rg.CreateVirtualNetworkConfig("Vnni", "192.168.0.0/16"); | ||
var sn = vn.CreateSubnet("mysubnet", "192.168.1.0/24"); | ||
var pipa = rg.CreatePublicIPAddressConfig("pipani"); | ||
var nsg = rg.CreateNetworkSecurityGroupConfig("nsgni"); | ||
var ni = rg.CreateNetworkInterfaceConfig("ni", sn, pipa, nsg); | ||
|
||
var client = new Client(Credentials.Get()); | ||
var state = await ni.GetAsync(client, new CancellationToken()); | ||
var location = state.GetLocation(rg); | ||
var parameters = ni.GetParameters(client.Context.SubscriptionId, "eastus"); | ||
var nic = parameters.GetOrNull(ni); | ||
var createState = await ni.CreateOrUpdateAsync( | ||
client, state, parameters, new CancellationToken()); | ||
var nicc = createState.GetOrNull(ni); | ||
Assert.Equal("eastus", nicc.Location); | ||
Assert.Equal("ni", nicc.Name); | ||
Assert.Equal(ni.GetId(client.Context.SubscriptionId).IdToString(), nicc.Id); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
experiments/Azure.Experiments/Tests/NetworkSecurityGroupTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.Azure.Experiments.Network; | ||
using Microsoft.Azure.Experiments.ResourceManager; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Experiments.Tests | ||
{ | ||
public class NetworkSecurityGroupTest | ||
{ | ||
[Fact] | ||
public async Task CreateAsyncTest() | ||
{ | ||
var rg = ResourceGroupPolicy.CreateResourceGroupConfig("nsgrg"); | ||
var vn = rg.CreateNetworkSecurityGroupConfig("nsg"); | ||
var client = new Client(Credentials.Get()); | ||
var state = await vn.GetAsync(client, new CancellationToken()); | ||
var location = state.GetLocation(rg); | ||
var parameters = vn.GetParameters(client.Context.SubscriptionId, "eastus"); | ||
var vnc = parameters.GetOrNull(vn); | ||
var createState = await vn.CreateOrUpdateAsync( | ||
client, state, parameters, new CancellationToken()); | ||
var vncc = createState.GetOrNull(vn); | ||
Assert.Equal("eastus", vncc.Location); | ||
Assert.Equal("nsg", vncc.Name); | ||
Assert.Equal(vn.GetId(client.Context.SubscriptionId).IdToString(), vncc.Id); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
experiments/Azure.Experiments/Tests/PublicIPAddressTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.Azure.Experiments.Network; | ||
using Microsoft.Azure.Experiments.ResourceManager; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Experiments.Tests | ||
{ | ||
public class PublicIPAddressTest | ||
{ | ||
[Fact] | ||
public async Task CreateAsyncTest() | ||
{ | ||
var rg = ResourceGroupPolicy.CreateResourceGroupConfig("piparg"); | ||
var vn = rg.CreatePublicIPAddressConfig("pipa"); | ||
var client = new Client(Credentials.Get()); | ||
var state = await vn.GetAsync(client, new CancellationToken()); | ||
var location = state.GetLocation(rg); | ||
var parameters = vn.GetParameters(client.Context.SubscriptionId, "eastus"); | ||
var vnc = parameters.GetOrNull(vn); | ||
var createState = await vn.CreateOrUpdateAsync( | ||
client, state, parameters, new CancellationToken()); | ||
var vncc = createState.GetOrNull(vn); | ||
Assert.Equal("eastus", vncc.Location); | ||
Assert.Equal("pipa", vncc.Name); | ||
Assert.Equal(vn.GetId(client.Context.SubscriptionId).IdToString(), vncc.Id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Microsoft.Azure.Experiments.Network; | ||
using Microsoft.Azure.Experiments.ResourceManager; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Experiments.Tests | ||
{ | ||
public class SubnetTest | ||
{ | ||
[Fact] | ||
public async Task CreateAsyncTest() | ||
{ | ||
var rg = ResourceGroupPolicy.CreateResourceGroupConfig("Snrg"); | ||
var vn = rg.CreateVirtualNetworkConfig("Vn", "192.168.0.0/16"); | ||
var sn = vn.CreateSubnet("mysubnet", "192.168.1.0/24"); | ||
|
||
var client = new Client(Credentials.Get()); | ||
var state = await sn.GetAsync(client, new CancellationToken()); | ||
var location = state.GetLocation(rg); | ||
var parameters = sn.GetParameters(client.Context.SubscriptionId, "eastus"); | ||
var snc = parameters.GetOrNull(sn); | ||
var createState = await sn.CreateOrUpdateAsync( | ||
client, state, parameters, new CancellationToken()); | ||
var sncc = createState.GetOrNull(sn); | ||
Assert.Equal("mysubnet", sncc.Name); | ||
Assert.Equal(sn.GetId(client.Context.SubscriptionId).IdToString(), sncc.Id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters