Skip to content

Commit

Permalink
NetworkInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Oct 17, 2017
1 parent a522a35 commit 5782a9b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public async Task SubnetTest()
var info = await subnet.GetOrCreateAsync(c);
}

[Fact]
public async Task NetworkInterfaceObject()
{
var c = Credentials.Get();
var rg = new ResourceGroupObject("MyNI");
var vn = new VirtualNetworkObject("MyNI", rg, "192.168.0.0/16");
var subnet = new SubnetObject("MyNI", vn, "192.168.1.0/24");
var pia = new PublicIpAddressObject("MyNI", rg);
var nsg = new NetworkSecurityGroupObject("MyNI", rg);
var ni = new NetworkInterfaceObject("MyNI", rg, subnet, pia, nsg);
var info = await ni.GetOrCreateAsync(c);
}

[Fact]
public async Task Test1()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected AzureObject(string name, IEnumerable<AzureObject> dependencies)
public abstract class AzureObject<T, C> : AzureObject
where T: class
{
public T Info { get; private set; }

public async Task<T> GetOrNullAsync(C c)
{
if (!IsGetCalled)
Expand Down Expand Up @@ -84,8 +86,6 @@ protected AzureObject(string name, IEnumerable<AzureObject> dependencies)

protected abstract Task DeleteAsync(C c);

private bool IsGetCalled;

private T Info;
private bool IsGetCalled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,39 @@

namespace Azure.Experiments
{
class NetworkInterfaceObject
public sealed class NetworkInterfaceObject
: ResourceObject<NetworkInterface, INetworkInterfacesOperations>
{
protected NetworkInterfaceObject(
public NetworkInterfaceObject(
string name,
ResourceGroupObject rg,
VirtualNetworkObject vn,
SubnetObject subnet,
PublicIpAddressObject pia,
NetworkSecurityGroupObject nsg)
: base(name, rg, new AzureObject[] { vn, pia, nsg })
: base(name, rg, new AzureObject[] { subnet, pia, nsg })
{
Pia = pia;
Subnet = subnet;
}

protected override Task<NetworkInterface> CreateAsync(
protected override async Task<NetworkInterface> CreateAsync(
INetworkInterfacesOperations c)
=> c.CreateOrUpdateAsync(
ResourceGroupName, Name, new NetworkInterface());
=> await c.CreateOrUpdateAsync(
ResourceGroupName,
Name,
new NetworkInterface
{
Location = "eastus",
IpConfigurations = new[]
{
new NetworkInterfaceIPConfiguration
{
Name = Name,
Subnet = Subnet.Info,
PublicIPAddress = Pia.Info,
}
}
});

protected override INetworkInterfacesOperations CreateClient(Context c)
=> c.CreateNetwork().NetworkInterfaces;
Expand All @@ -31,5 +47,8 @@ protected override Task DeleteAsync(INetworkInterfacesOperations c)
protected override Task<NetworkInterface> GetOrThrowAsync(
INetworkInterfacesOperations c)
=> c.GetAsync(ResourceGroupName, Name);

private PublicIpAddressObject Pia { get; }
private SubnetObject Subnet { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ class NetworkInterface: Resource1 {
$subnetInfo = $this.Subnet.Info
$securityGroupInfo = $this.SecurityGroup.Info
return New-AzureRmNetworkInterface `
-ResourceGroupName $this.GetResourceGroupName() `
-ResourceGroupName $this.ResourceGroup.Name `
-Location $p.Location `
-Name $this.Name `
-PublicIpAddressId $publicIpAddressInfo.Id `
Expand Down

0 comments on commit 5782a9b

Please sign in to comment.