|
| 1 | +using Microsoft.Azure.Management.Compute; |
| 2 | +using Microsoft.Azure.Management.Compute.Models; |
| 3 | +using System.Threading.Tasks; |
| 4 | + |
| 5 | +namespace Azure.Experiments |
| 6 | +{ |
| 7 | + public sealed class VmObject |
| 8 | + : ResourceObject<VirtualMachine, IVirtualMachinesOperations> |
| 9 | + { |
| 10 | + public VmObject( |
| 11 | + string name, |
| 12 | + ResourceGroupObject rg, |
| 13 | + NetworkInterfaceObject ni, |
| 14 | + string adminUsername, |
| 15 | + string adminPassword) |
| 16 | + : base(name, rg, new[] { ni }) |
| 17 | + { |
| 18 | + AdminUsername = adminUsername; |
| 19 | + AdminPassword = adminPassword; |
| 20 | + Ni = ni; |
| 21 | + } |
| 22 | + |
| 23 | + protected override Task<VirtualMachine> CreateAsync( |
| 24 | + IVirtualMachinesOperations c) |
| 25 | + => c.CreateOrUpdateAsync( |
| 26 | + ResourceGroupName, |
| 27 | + Name, |
| 28 | + new VirtualMachine |
| 29 | + { |
| 30 | + Location = "eastus", |
| 31 | + OsProfile = new OSProfile |
| 32 | + { |
| 33 | + ComputerName = Name, |
| 34 | + WindowsConfiguration = new WindowsConfiguration |
| 35 | + { |
| 36 | + }, |
| 37 | + AdminUsername = AdminUsername, |
| 38 | + AdminPassword = AdminPassword, |
| 39 | + }, |
| 40 | + NetworkProfile = new NetworkProfile |
| 41 | + { |
| 42 | + NetworkInterfaces = new NetworkInterfaceReference[] |
| 43 | + { |
| 44 | + new NetworkInterfaceReference(Ni.Info.Id) |
| 45 | + } |
| 46 | + }, |
| 47 | + HardwareProfile = new HardwareProfile |
| 48 | + { |
| 49 | + VmSize = "Standard_DS1_v2" |
| 50 | + }, |
| 51 | + StorageProfile = new StorageProfile |
| 52 | + { |
| 53 | + ImageReference = new ImageReference |
| 54 | + { |
| 55 | + Publisher = "MicrosoftWindowsServer", |
| 56 | + Offer = "WindowsServer", |
| 57 | + Sku = "2016-Datacenter", |
| 58 | + Version = "latest" |
| 59 | + } |
| 60 | + }, |
| 61 | + }); |
| 62 | + |
| 63 | + protected override IVirtualMachinesOperations CreateClient(Context c) |
| 64 | + => new ComputeManagementClient(c.Credentials) |
| 65 | + { |
| 66 | + SubscriptionId = c.SubscriptionId |
| 67 | + } |
| 68 | + .VirtualMachines; |
| 69 | + |
| 70 | + protected override Task DeleteAsync(IVirtualMachinesOperations c) |
| 71 | + { |
| 72 | + throw new System.NotImplementedException(); |
| 73 | + } |
| 74 | + |
| 75 | + protected override Task<VirtualMachine> GetOrThrowAsync(IVirtualMachinesOperations c) |
| 76 | + => c.GetAsync(ResourceGroupName, Name); |
| 77 | + |
| 78 | + private string AdminUsername { get; } |
| 79 | + |
| 80 | + private string AdminPassword { get; } |
| 81 | + |
| 82 | + private NetworkInterfaceObject Ni { get; } |
| 83 | + } |
| 84 | +} |
0 commit comments