forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
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
e582289
commit b643730
Showing
9 changed files
with
230 additions
and
22 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
experiments/Azure.Experiments/Azure.Experiments/Compute/ComputePolicy.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,28 @@ | ||
using Microsoft.Azure.Management.Compute; | ||
using Microsoft.Azure.Management.Compute.Models; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Experiments.Compute | ||
{ | ||
public static class ComputePolicy | ||
{ | ||
public static ResourcePolicy<IComputeManagementClient, ResourceName, Info> Create<Operations, Info>( | ||
Func<IComputeManagementClient, Operations> getOperations, | ||
Func<Operations, ResourceName, Task<Info>> getAsync, | ||
Func<Operations, ResourceName, Info, Task<Info>> createOrUpdateAsync) | ||
where Info : Resource | ||
=> OperationsPolicy | ||
.Create(getAsync, createOrUpdateAsync) | ||
.Transform(getOperations) | ||
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location); | ||
|
||
public static ResourcePolicy<IComputeManagementClient, ResourceName, VirtualMachine> VirtualMachine | ||
{ get; } | ||
= Create( | ||
client => client.VirtualMachines, | ||
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name), | ||
(operations, name, info) | ||
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info)); | ||
} | ||
} |
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,9 @@ | ||
namespace Microsoft.Azure.Experiments | ||
{ | ||
public interface IClient | ||
{ | ||
Context Context { get; } | ||
|
||
T GetClient<T>(); | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
experiments/Azure.Experiments/Azure.Experiments/IResourcePolicy.cs
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
experiments/Azure.Experiments/Azure.Experiments/Network/NetworkPolicy.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,52 @@ | ||
using Microsoft.Azure.Management.Network; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Experiments.Network | ||
{ | ||
public static class NetworkPolicy | ||
{ | ||
public static ResourcePolicy<INetworkManagementClient, ResourceName, Info> Create<Operations, Info>( | ||
Func<INetworkManagementClient, Operations> getOperations, | ||
Func<Operations, ResourceName, Task<Info>> getAsync, | ||
Func<Operations, ResourceName, Info, Task<Info>> createOrUpdateAsync) | ||
where Info : Resource | ||
=> OperationsPolicy | ||
.Create(getAsync, createOrUpdateAsync) | ||
.Transform(getOperations) | ||
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location); | ||
|
||
public static ResourcePolicy<INetworkManagementClient, 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 ResourcePolicy<INetworkManagementClient, ResourceName, NetworkSecurityGroup> NetworkSecurityGroup | ||
{ get; } | ||
= Create( | ||
client => client.NetworkSecurityGroups, | ||
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name), | ||
(operations, name, info) | ||
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info)); | ||
|
||
public static ResourcePolicy<INetworkManagementClient, ResourceName, PublicIPAddress> PublicIPAddresss | ||
{ get; } | ||
= Create( | ||
client => client.PublicIPAddresses, | ||
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name), | ||
(operations, name, info) | ||
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info)); | ||
|
||
public static ResourcePolicy<INetworkManagementClient, ResourceName, VirtualNetwork> VirtualNetwork | ||
{ get; } | ||
= Create( | ||
client => client.VirtualNetworks, | ||
(operations, name) => operations.GetAsync(name.ResourceGroupName, name.Name), | ||
(operations, name, info) | ||
=> operations.CreateOrUpdateAsync(name.ResourceGroupName, name.Name, info)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
experiments/Azure.Experiments/Azure.Experiments/OperationsPolicy.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,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Experiments | ||
{ | ||
public static class OperationsPolicy | ||
{ | ||
public static OperationsPolicy<Client, Name, Info> Create<Client, Name, Info>( | ||
Func<Client, Name, Task<Info>> getAsync, | ||
Func<Client, Name, Info, Task<Info>> createOrUpdateAsync) | ||
=> new OperationsPolicy<Client, Name, Info>(getAsync, createOrUpdateAsync); | ||
} | ||
|
||
public sealed class OperationsPolicy<Client, Name, Info> | ||
{ | ||
public Func<Client, Name, Task<Info>> GetAsync { get; } | ||
|
||
public Func<Client, Name, Info, Task<Info>> CreateOrUpdateAsync { get; } | ||
|
||
public OperationsPolicy( | ||
Func<Client, Name, Task<Info>> getAsync, | ||
Func<Client, Name, Info, Task<Info>> createOrUpdateAsync) | ||
{ | ||
GetAsync = getAsync; | ||
CreateOrUpdateAsync = createOrUpdateAsync; | ||
} | ||
|
||
public OperationsPolicy<NewClient, Name, Info> Transform<NewClient>(Func<NewClient, Client> get) | ||
=> OperationsPolicy.Create<NewClient, Name, Info>( | ||
(client, name) => GetAsync(get(client), name), | ||
(client, name, info) => CreateOrUpdateAsync(get(client), name, info)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
experiments/Azure.Experiments/Azure.Experiments/ResourceConfig.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,43 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.Azure.Experiments | ||
{ | ||
public interface IResourceConfig | ||
{ | ||
} | ||
|
||
public static class ResourceConfig | ||
{ | ||
public static ResourceConfig<Client, Name, Info> CreateResourceConfig<Client, Name, Info>( | ||
this ResourcePolicy<Client, Name, Info> policy, | ||
Name name, | ||
Info info, | ||
IEnumerable<IResourceConfig> dependencies) | ||
where Info : class | ||
=> new ResourceConfig<Client, Name, Info>(policy, name, info, dependencies); | ||
} | ||
|
||
public sealed class ResourceConfig<Client, TName, TInfo> | ||
where TInfo : class | ||
{ | ||
public ResourcePolicy<Client, TName, TInfo> Policy { get; } | ||
|
||
public TName Name { get; } | ||
|
||
public TInfo Info { get; } | ||
|
||
public IEnumerable<IResourceConfig> Dependencies { get; } | ||
|
||
public ResourceConfig( | ||
ResourcePolicy<Client, TName, TInfo> policy, | ||
TName name, | ||
TInfo info, | ||
IEnumerable<IResourceConfig> dependencies) | ||
{ | ||
Policy = policy; | ||
Name = name; | ||
Info = info; | ||
Dependencies = dependencies; | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
experiments/Azure.Experiments/Azure.Experiments/ResourceManager/ResourceManagerPolicy.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,17 @@ | ||
using Microsoft.Azure.Management.ResourceManager; | ||
using Microsoft.Azure.Management.ResourceManager.Models; | ||
|
||
namespace Microsoft.Azure.Experiments.ResourceManager | ||
{ | ||
public static class ResourceManagerPolicy | ||
{ | ||
public static ResourcePolicy<IResourceManagementClient, string, ResourceGroup> ResourceGroup | ||
{ get; } | ||
= OperationsPolicy | ||
.Create<IResourceGroupsOperations, string, ResourceGroup>( | ||
(operations, name) => operations.GetAsync(name), | ||
(operations, name, info) => operations.CreateOrUpdateAsync(name, info)) | ||
.Transform<IResourceManagementClient>(r => r.ResourceGroups) | ||
.CreateResourcePolicy(i => i.Location, (i, location) => i.Location = location); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
experiments/Azure.Experiments/Azure.Experiments/ResourceName.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,14 @@ | ||
namespace Microsoft.Azure.Experiments | ||
{ | ||
public sealed class ResourceName | ||
{ | ||
public string ResourceGroupName { get; } | ||
public string Name { get; } | ||
|
||
public ResourceName(string resourceGroupName, string name) | ||
{ | ||
ResourceGroupName = resourceGroupName; | ||
Name = name; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
experiments/Azure.Experiments/Azure.Experiments/ResourcePolicy.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 System; | ||
|
||
namespace Microsoft.Azure.Experiments | ||
{ | ||
public static class ResourcePolicy | ||
{ | ||
public static ResourcePolicy<Client, Name, Info> CreateResourcePolicy<Client, Name, Info>( | ||
this OperationsPolicy<Client, Name, Info> operationsPolicy, | ||
Func<Info, string> getLocation, | ||
Action<Info, string> setLocation) | ||
where Info : class | ||
=> new ResourcePolicy<Client, Name, Info>(operationsPolicy, getLocation, setLocation); | ||
} | ||
|
||
public sealed class ResourcePolicy<Client, Name, Info> | ||
where Info : class | ||
{ | ||
public OperationsPolicy<Client, Name, Info> OperationsPolicy { get; } | ||
|
||
public Func<Info, string> GetLocation { get; } | ||
|
||
public Action<Info, string> SetLocation { get; } | ||
|
||
public ResourcePolicy( | ||
OperationsPolicy<Client, Name, Info> operationsPolicy, | ||
Func<Info, string> getLocation, | ||
Action<Info, string> setLocation) | ||
{ | ||
OperationsPolicy = operationsPolicy; | ||
GetLocation = getLocation; | ||
SetLocation = setLocation; | ||
} | ||
} | ||
} |