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
e37b2a4
commit cad25fb
Showing
19 changed files
with
398 additions
and
13 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
24 changes: 24 additions & 0 deletions
24
src/ResourceManager/Common/Commands.Common.Strategies/Compute/ComputeStrategy.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,24 @@ | ||
using Microsoft.Azure.Management.Compute; | ||
using Microsoft.Azure.Management.Compute.Models; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies.Compute | ||
{ | ||
public static class ComputePolicy | ||
{ | ||
public static ResourceStrategy<Model> Create<Model, Operations>( | ||
string header, | ||
Func<IComputeManagementClient, Operations> getOperations, | ||
Func<GetAsyncParams<Operations>, Task<Model>> getAsync, | ||
Func<CreateOrUpdateAsyncParams<Operations, Model>, Task<Model>> createOrUpdateAsync) | ||
where Model : Resource | ||
=> ResourceStrategy.Create( | ||
new[] { "Microsoft.Compute", header }, | ||
getOperations, | ||
getAsync, | ||
createOrUpdateAsync, | ||
config => config.Location, | ||
(config, location) => config.Location = location); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
src/ResourceManager/Common/Commands.Common.Strategies/Compute/VirtualMachineStrategy.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,66 @@ | ||
using Microsoft.Azure.Management.Compute; | ||
using Microsoft.Azure.Management.Compute.Models; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using Microsoft.Azure.Management.ResourceManager.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies.Compute | ||
{ | ||
public static class VirtualMachineStrategy | ||
{ | ||
public static ResourceStrategy<VirtualMachine> Strategy { get; } | ||
= ComputePolicy.Create( | ||
"virtualMachines", | ||
client => client.VirtualMachines, | ||
p => p.Operations.GetAsync( | ||
p.ResourceGroupName, p.Name, null, p.CancellationToken), | ||
p => p.Operations.CreateOrUpdateAsync( | ||
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken)); | ||
|
||
public static ResourceConfig<VirtualMachine> CreateVirtualMachineConfig( | ||
this ResourceConfig<ResourceGroup> resourceGroup, | ||
string name, | ||
ResourceConfig<NetworkInterface> networkInterface, | ||
string adminUsername, | ||
string adminPassword) | ||
=> Strategy.CreateConfig( | ||
resourceGroup, | ||
name, | ||
subscription => new VirtualMachine | ||
{ | ||
OsProfile = new OSProfile | ||
{ | ||
ComputerName = name, | ||
WindowsConfiguration = new WindowsConfiguration | ||
{ | ||
}, | ||
AdminUsername = adminUsername, | ||
AdminPassword = adminPassword, | ||
}, | ||
NetworkProfile = new NetworkProfile | ||
{ | ||
NetworkInterfaces = new[] | ||
{ | ||
new NetworkInterfaceReference | ||
{ | ||
Id = networkInterface.GetId(subscription).IdToString() | ||
} | ||
} | ||
}, | ||
HardwareProfile = new HardwareProfile | ||
{ | ||
VmSize = "Standard_DS1_v2" | ||
}, | ||
StorageProfile = new StorageProfile | ||
{ | ||
ImageReference = new ImageReference | ||
{ | ||
Publisher = "MicrosoftWindowsServer", | ||
Offer = "WindowsServer", | ||
Sku = "2016-Datacenter", | ||
Version = "latest" | ||
} | ||
}, | ||
}, | ||
new[] { networkInterface }); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/ResourceManager/Common/Commands.Common.Strategies/Network/NetworkInterfaceStrategy.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,48 @@ | ||
using Microsoft.Azure.Management.Network; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using Microsoft.Azure.Management.ResourceManager.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies.Network | ||
{ | ||
public static class NetworkInterfaceStrategy | ||
{ | ||
public static ResourceStrategy<NetworkInterface> Strategy { get; } | ||
= NetworkStrategy.Create( | ||
"networkInterfaces", | ||
client => client.NetworkInterfaces, | ||
p => p.Operations.GetAsync( | ||
p.ResourceGroupName, p.Name, null, p.CancellationToken), | ||
p => p.Operations.CreateOrUpdateAsync( | ||
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken)); | ||
|
||
public static ResourceConfig<NetworkInterface> CreateNetworkInterfaceConfig( | ||
this ResourceConfig<ResourceGroup> resourceGroup, | ||
string name, | ||
NestedResourceConfig<Subnet, VirtualNetwork> subnet, | ||
ResourceConfig<PublicIPAddress> publicIPAddress, | ||
ResourceConfig<NetworkSecurityGroup> networkSecurityGroup) | ||
=> Strategy.CreateConfig( | ||
resourceGroup, | ||
name, | ||
subscription => new NetworkInterface | ||
{ | ||
IpConfigurations = new [] | ||
{ | ||
new NetworkInterfaceIPConfiguration | ||
{ | ||
Name = name, | ||
Subnet = new Subnet { Id = subnet.GetId(subscription).IdToString() }, | ||
PublicIPAddress = new PublicIPAddress | ||
{ | ||
Id = publicIPAddress.GetId(subscription).IdToString() | ||
} | ||
} | ||
}, | ||
NetworkSecurityGroup = new NetworkSecurityGroup | ||
{ | ||
Id = networkSecurityGroup.GetId(subscription).IdToString() | ||
} | ||
}, | ||
new IResourceConfig[] { subnet, publicIPAddress, networkSecurityGroup }); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/ResourceManager/Common/Commands.Common.Strategies/Network/NetworkSecurityGroupPolicy.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,22 @@ | ||
using Microsoft.Azure.Management.Network; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using Microsoft.Azure.Management.ResourceManager.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies.Network | ||
{ | ||
public static class NetworkSecurityGroupStrategy | ||
{ | ||
public static ResourceStrategy<NetworkSecurityGroup> Strategy { get; } | ||
= NetworkStrategy.Create( | ||
"networkSecurityGroups", | ||
client => client.NetworkSecurityGroups, | ||
p => p.Operations.GetAsync( | ||
p.ResourceGroupName, p.Name, null, p.CancellationToken), | ||
p => p.Operations.CreateOrUpdateAsync( | ||
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken)); | ||
|
||
public static ResourceConfig<NetworkSecurityGroup> CreateNetworkSecurityGroupConfig( | ||
this ResourceConfig<ResourceGroup> resourceGroup, string name) | ||
=> Strategy.CreateConfig(resourceGroup, name); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/ResourceManager/Common/Commands.Common.Strategies/Network/NetworkStrategy.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,24 @@ | ||
using Microsoft.Azure.Management.Network; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies.Network | ||
{ | ||
public static class NetworkStrategy | ||
{ | ||
public static ResourceStrategy<Model> Create<Model, Operations>( | ||
string header, | ||
Func<INetworkManagementClient, Operations> getOperations, | ||
Func<GetAsyncParams<Operations>, Task<Model>> getAsync, | ||
Func<CreateOrUpdateAsyncParams<Operations, Model>, Task<Model>> createOrUpdateAsync) | ||
where Model : Resource | ||
=> ResourceStrategy.Create( | ||
new [] { "Microsoft.Network", header }, | ||
getOperations, | ||
getAsync, | ||
createOrUpdateAsync, | ||
model => model.Location, | ||
(model, location) => model.Location = location); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/ResourceManager/Common/Commands.Common.Strategies/Network/PublicIPAddressStrategy.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,22 @@ | ||
using Microsoft.Azure.Management.Network; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using Microsoft.Azure.Management.ResourceManager.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies.Network | ||
{ | ||
public static class PublicIPAddressStrategy | ||
{ | ||
public static ResourceStrategy<PublicIPAddress> Strategy { get; } | ||
= NetworkStrategy.Create( | ||
"publicIPAddresses", | ||
client => client.PublicIPAddresses, | ||
p => p.Operations.GetAsync( | ||
p.ResourceGroupName, p.Name, null, p.CancellationToken), | ||
p => p.Operations.CreateOrUpdateAsync( | ||
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken)); | ||
|
||
public static ResourceConfig<PublicIPAddress> CreatePublicIPAddressConfig( | ||
this ResourceConfig<ResourceGroup> resourceGroup, string name) | ||
=> Strategy.CreateConfig(resourceGroup, name); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/ResourceManager/Common/Commands.Common.Strategies/Network/SubnetStrategy.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.Commands.Common.Strategies.Network | ||
{ | ||
public static class SubnetPolicy | ||
{ | ||
public static NestedResourceStrategy<Subnet, VirtualNetwork> Strategy { get; } | ||
= NestedResourceStrategy.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) | ||
=> Strategy.CreateConfig( | ||
virtualNetwork, | ||
name, | ||
() => new Subnet { Name = name, AddressPrefix = addressPrefix }); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/ResourceManager/Common/Commands.Common.Strategies/Network/VirtualNetworkStrategy.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 Microsoft.Azure.Management.Network; | ||
using Microsoft.Azure.Management.Network.Models; | ||
using Microsoft.Azure.Management.ResourceManager.Models; | ||
|
||
namespace Microsoft.Azure.Commands.Common.Strategies.Network | ||
{ | ||
public static class VirtualNetworkStrategy | ||
{ | ||
public static ResourceStrategy<VirtualNetwork> Strategy { get; } | ||
= NetworkStrategy.Create( | ||
"virtualNetworks", | ||
client => client.VirtualNetworks, | ||
p => p.Operations.GetAsync( | ||
p.ResourceGroupName, p.Name, null, p.CancellationToken), | ||
p => p.Operations.CreateOrUpdateAsync( | ||
p.ResourceGroupName, p.Name, p.Model, p.CancellationToken)); | ||
|
||
public static ResourceConfig<VirtualNetwork> CreateVirtualNetworkConfig( | ||
this ResourceConfig<ResourceGroup> resourceGroup, | ||
string name, | ||
string addressPrefix) | ||
=> Strategy.CreateConfig( | ||
resourceGroup, | ||
name, | ||
_ => new VirtualNetwork | ||
{ | ||
AddressSpace = new AddressSpace | ||
{ | ||
AddressPrefixes = new[] { addressPrefix } | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.