Skip to content

Commit

Permalink
NetworkInterfacePolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-shandar committed Nov 9, 2017
1 parent 157f96b commit 8b2b24b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.Azure.Experiments.ResourceManager;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Azure.Management.ResourceManager.Models;

namespace Microsoft.Azure.Experiments.Network
{
public static class NetworkInterfacePolicy
{
public static ResourcePolicy<ResourceName, NetworkInterface> Policy { get; }
= NetworkPolicy.Create(
client => client.NetworkInterfaces,
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name),
(operations, name, info)
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info));

public static ResourceConfig<ResourceName, NetworkInterface> CreateNetworkInterfaceConfig(
this ResourceConfig<string, ResourceGroup> resourceGroup,
string name,
ResourceConfig<ResourceName, VirtualNetwork> virtualNetwork,
ResourceConfig<ResourceName, NetworkSecurityGroup> networkSecurityGroup,
ResourceConfig<ResourceName, PublicIPAddress> publicIPAddress)
=> resourceGroup.CreateResourceConfig(
Policy,
name,
new NetworkInterface(),
new IResourceConfig[] { virtualNetwork, networkSecurityGroup, publicIPAddress });
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Microsoft.Azure.Experiments.ResourceManager;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Azure.Management.Network;
using System;
using System.Threading.Tasks;

Expand All @@ -18,24 +15,5 @@ public static ResourcePolicy<ResourceName, Info> Create<Operations, Info>(
.Create(getAsync, createOrUpdateAsync)
.Transform(getOperations)
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location);

public static ResourcePolicy<ResourceName, NetworkInterface> NetworkInterface { get; }
= Create(
client => client.NetworkInterfaces,
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name),
(operations, name, info)
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info));

public static ResourceConfig<ResourceName, NetworkInterface> CreateNetworkInterfaceConfig(
this ResourceConfig<string, ResourceGroup> resourceGroup,
string name,
ResourceConfig<ResourceName, VirtualNetwork> virtualNetwork,
ResourceConfig<ResourceName, NetworkSecurityGroup> networkSecurityGroup,
ResourceConfig<ResourceName, PublicIPAddress> publicIPAddress)
=> resourceGroup.CreateResourceConfig(
NetworkInterface,
name,
new NetworkInterface(),
new IResourceConfig[] { virtualNetwork, networkSecurityGroup, publicIPAddress });
}
}

0 comments on commit 8b2b24b

Please sign in to comment.