forked from AzureRT/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 5
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
5782a9b
commit fb1539a
Showing
2 changed files
with
98 additions
and
0 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
84 changes: 84 additions & 0 deletions
84
experiments/Azure.Experiments/Azure.Experiments/VmObject.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,84 @@ | ||
using Microsoft.Azure.Management.Compute; | ||
using Microsoft.Azure.Management.Compute.Models; | ||
using System.Threading.Tasks; | ||
|
||
namespace Azure.Experiments | ||
{ | ||
public sealed class VmObject | ||
: ResourceObject<VirtualMachine, IVirtualMachinesOperations> | ||
{ | ||
public VmObject( | ||
string name, | ||
ResourceGroupObject rg, | ||
NetworkInterfaceObject ni, | ||
string adminUsername, | ||
string adminPassword) | ||
: base(name, rg, new[] { ni }) | ||
{ | ||
AdminUsername = adminUsername; | ||
AdminPassword = adminPassword; | ||
Ni = ni; | ||
} | ||
|
||
protected override Task<VirtualMachine> CreateAsync( | ||
IVirtualMachinesOperations c) | ||
=> c.CreateOrUpdateAsync( | ||
ResourceGroupName, | ||
Name, | ||
new VirtualMachine | ||
{ | ||
Location = "eastus", | ||
OsProfile = new OSProfile | ||
{ | ||
ComputerName = Name, | ||
WindowsConfiguration = new WindowsConfiguration | ||
{ | ||
}, | ||
AdminUsername = AdminUsername, | ||
AdminPassword = AdminPassword, | ||
}, | ||
NetworkProfile = new NetworkProfile | ||
{ | ||
NetworkInterfaces = new NetworkInterfaceReference[] | ||
{ | ||
new NetworkInterfaceReference(Ni.Info.Id) | ||
} | ||
}, | ||
HardwareProfile = new HardwareProfile | ||
{ | ||
VmSize = "Standard_DS1_v2" | ||
}, | ||
StorageProfile = new StorageProfile | ||
{ | ||
ImageReference = new ImageReference | ||
{ | ||
Publisher = "MicrosoftWindowsServer", | ||
Offer = "WindowsServer", | ||
Sku = "2016-Datacenter", | ||
Version = "latest" | ||
} | ||
}, | ||
}); | ||
|
||
protected override IVirtualMachinesOperations CreateClient(Context c) | ||
=> new ComputeManagementClient(c.Credentials) | ||
{ | ||
SubscriptionId = c.SubscriptionId | ||
} | ||
.VirtualMachines; | ||
|
||
protected override Task DeleteAsync(IVirtualMachinesOperations c) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
protected override Task<VirtualMachine> GetOrThrowAsync(IVirtualMachinesOperations c) | ||
=> c.GetAsync(ResourceGroupName, Name); | ||
|
||
private string AdminUsername { get; } | ||
|
||
private string AdminPassword { get; } | ||
|
||
private NetworkInterfaceObject Ni { get; } | ||
} | ||
} |